mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
commit
b30acaac78
10 changed files with 97 additions and 104 deletions
|
@ -76,7 +76,7 @@
|
|||
"message": "Paused"
|
||||
},
|
||||
"confirmMSG": {
|
||||
"message": "\n\nTo edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
|
||||
"message": "To edit or delete individual values, click the info button or open the extension popup by clicking the extension icon in the top right corner."
|
||||
},
|
||||
"clearThis": {
|
||||
"message": "Are you sure you want to clear this?\n\n"
|
||||
|
@ -314,5 +314,11 @@
|
|||
},
|
||||
"youHaveSavedTimeEnd": {
|
||||
"message": " of their lives."
|
||||
},
|
||||
"guildlinesSummary": {
|
||||
"message": "- Make sure your segment only contains paid promotion segment, nothing else.\n- Make sure skipping this segment will not skip valuable content\n- If the whole video is a sponsor, please do not report it. A full video reporting system will come out soon.\n- Please do not report disclaimers that could show bias (if a review video is sponsored, don't skip when they mention that)."
|
||||
},
|
||||
"statusReminder": {
|
||||
"message": "Check status.sponsor.ajay.app for server status."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||
case "alertPrevious":
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + request.previousVideoID + "?",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
|
@ -216,21 +216,3 @@ function sendRequestToServer(type, address, callback) {
|
|||
//submit this request
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function generateUserID(length = 36) {
|
||||
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let result = "";
|
||||
if (window.crypto && window.crypto.getRandomValues) {
|
||||
values = new Uint32Array(length);
|
||||
window.crypto.getRandomValues(values);
|
||||
for (i = 0; i < length; i++) {
|
||||
result += charset[values[i] % charset.length];
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += charset[Math.floor(Math.random() * charset.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
66
content.js
66
content.js
|
@ -479,7 +479,12 @@ function updatePreviewBar() {
|
|||
//create an array of the sponsor types
|
||||
let types = [];
|
||||
for (let i = 0; i < localSponsorTimes.length; i++) {
|
||||
if (!hiddenSponsorTimes.includes(i)) {
|
||||
types.push("sponsor");
|
||||
} else {
|
||||
// Don't show this sponsor
|
||||
types.push(null);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
||||
types.push("previewSponsor");
|
||||
|
@ -493,25 +498,20 @@ function updatePreviewBar() {
|
|||
|
||||
function getChannelID() {
|
||||
//get channel id
|
||||
let channelContainers = document.querySelectorAll(".ytd-channel-name#text");
|
||||
let channelURLContainer = null;
|
||||
let channelNameContainer = document.getElementById("channel-name");
|
||||
let channelURLContainer = channelNameContainer.querySelector("#container").querySelector("#text-container").querySelector("#text").firstElementChild;
|
||||
|
||||
for (let i = 0; i < channelContainers.length; i++) {
|
||||
let child = channelContainers[i].firstElementChild;
|
||||
if (child != null && child.getAttribute("href") != "") {
|
||||
channelURLContainer = child;
|
||||
}
|
||||
}
|
||||
|
||||
if (channelContainers.length == 0) {
|
||||
|
||||
if (channelURLContainer === null) {
|
||||
//old YouTube theme
|
||||
channelContainers = document.getElementsByClassName("yt-user-info");
|
||||
let channelContainers = document.getElementsByClassName("yt-user-info");
|
||||
if (channelContainers.length != 0) {
|
||||
channelURLContainer = channelContainers[0].firstElementChild;
|
||||
}
|
||||
}
|
||||
|
||||
if (channelURLContainer == null) {
|
||||
if (channelURLContainer === null) {
|
||||
//try later
|
||||
return false;
|
||||
}
|
||||
|
@ -545,11 +545,9 @@ function whitelistCheck() {
|
|||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
//reset sponsor times to nothing
|
||||
sponsorTimes = [];
|
||||
UUIDs = [];
|
||||
console.log(channelURL)
|
||||
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
channelWhitelisted = true;
|
||||
}
|
||||
});
|
||||
|
@ -561,6 +559,8 @@ function sponsorCheck() {
|
|||
// Make sure this isn't called again
|
||||
v.ontimeupdate = null;
|
||||
return;
|
||||
} else if (channelWhitelisted) {
|
||||
return;
|
||||
}
|
||||
|
||||
let skipHappened = false;
|
||||
|
@ -980,14 +980,8 @@ function vote(type, UUID, skipNotice) {
|
|||
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
|
||||
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
|
||||
} else if (response.successType == -1) {
|
||||
if (response.statusCode == 502) {
|
||||
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown"))
|
||||
skipNotice.addNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode))
|
||||
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
|
||||
} else {
|
||||
//failure: unknown error
|
||||
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
|
||||
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1047,8 +1041,11 @@ function submitSponsorTimes() {
|
|||
//update sponsorTimes
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
|
||||
|
||||
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
|
||||
confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG");
|
||||
//update sponsorTimesSubmitting
|
||||
sponsorTimesSubmitting = sponsorTimes;
|
||||
|
||||
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
|
||||
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
|
||||
if(!confirm(confirmMessage)) return;
|
||||
|
||||
sendSubmitMessage();
|
||||
|
@ -1066,8 +1063,6 @@ function sendSubmitMessage(){
|
|||
|
||||
let currentVideoID = sponsorVideoID;
|
||||
|
||||
let currentSponsorTimes = submitSponsorTimes;
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
message: "submitTimes",
|
||||
videoID: currentVideoID
|
||||
|
@ -1091,24 +1086,25 @@ function sendSubmitMessage(){
|
|||
|
||||
//clear the sponsor times
|
||||
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar());
|
||||
chrome.storage.sync.set({[sponsorTimeKey]: []});
|
||||
|
||||
//add submissions to current sponsors list
|
||||
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
||||
// Add some random IDs
|
||||
UUIDs.push(generateUserID());
|
||||
}
|
||||
|
||||
// Empty the submitting times
|
||||
sponsorTimesSubmitting = [];
|
||||
|
||||
updatePreviewBar();
|
||||
} else {
|
||||
//show that the upload failed
|
||||
document.getElementById("submitButton").style.animation = "unset";
|
||||
document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
|
||||
|
||||
if([400, 429, 409, 502, 0].includes(response.statusCode)) {
|
||||
//treat them the same
|
||||
if (response.statusCode == 503) response.statusCode = 502;
|
||||
|
||||
alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode);
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
|
||||
}
|
||||
alert(getErrorMessage(response.statusCode));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<br/>
|
||||
<br/>
|
||||
|
||||
Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary.
|
||||
Whenever you skip a video, you will get a notice report that submission. If the timing seems wrong, report it! You can also vote in the popup. The extension auto upvotes it if you don't report it, so make sure to report when necessary (this can be disabled in the options).
|
||||
</p>
|
||||
|
||||
<center><img height="120px" src="https://user-images.githubusercontent.com/12688112/63067735-5a638700-bede-11e9-8147-f321b57527ec.gif"></center>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "__MSG_fullName__",
|
||||
"short_name": "__MSG_Name__",
|
||||
"version": "1.1.9.8",
|
||||
"version": "1.1.9.9",
|
||||
"default_locale": "en",
|
||||
"description": "__MSG_Description__",
|
||||
"content_scripts": [
|
||||
|
|
14
popup.html
14
popup.html
|
@ -140,24 +140,24 @@
|
|||
<span class="popupElement">__MSG_youHaveSavedTimeEnd__</span>
|
||||
</span>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<span id="sponsorTimesSkipsDoneContainer" class="popupElement" style="display: none">
|
||||
<div id="sponsorTimesSkipsDoneContainer" class="popupElement" style="display: none">
|
||||
__MSG_youHaveSkipped__
|
||||
<span id="sponsorTimesSkipsDoneDisplay" class="popupElement">
|
||||
0
|
||||
</span>
|
||||
<span id="sponsorTimesSkipsDoneEndWord" class="popupElement">__MSG_Segments__</span> since December 5th.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span id="sponsorTimeSavedContainer" class="popupElement" style="display: none">
|
||||
<div id="sponsorTimeSavedContainer" class="popupElement" style="display: none">
|
||||
__MSG_youHaveSaved__
|
||||
<span id="sponsorTimeSavedDisplay" class="popupElement">
|
||||
0
|
||||
</span>
|
||||
<span id="sponsorTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span> since December 5th.
|
||||
</span>
|
||||
|
||||
</br/>
|
||||
</br/>
|
||||
</div>
|
||||
|
||||
<div class="popupElement">
|
||||
__MSG_viewLeaderboard__ <a class="popupElement discreteLink" href="https://sponsor.ajay.app/stats" target="_blank">__MSG_here__</a>.
|
||||
|
|
32
popup.js
32
popup.js
|
@ -895,18 +895,7 @@ function runThePopup() {
|
|||
|
||||
clearTimes();
|
||||
} else {
|
||||
let errorMessage = "";
|
||||
|
||||
if([400, 429, 409, 502, 0].includes(response.statusCode)) {
|
||||
//treat them the same
|
||||
if (response.statusCode == 503) response.statusCode = 502;
|
||||
|
||||
errorMessage = chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode;
|
||||
} else {
|
||||
errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode;
|
||||
}
|
||||
|
||||
document.getElementById("submitTimesInfoMessage").innerText = errorMessage;
|
||||
document.getElementById("submitTimesInfoMessage").innerText = getErrorMessage(response.statusCode);
|
||||
document.getElementById("submitTimesInfoMessageContainer").style.display = "unset";
|
||||
|
||||
SB.submitTimesInfoMessageContainer.style.display = "unset";
|
||||
|
@ -1138,7 +1127,7 @@ function runThePopup() {
|
|||
SB.usernameInput.style.display = "none";
|
||||
|
||||
SB.setUsernameStatusContainer.style.display = "unset";
|
||||
SB.setUsernameStatus.innerText = "Couldn't connect to server. Error code: " + xmlhttp.status;
|
||||
SB.setUsernameStatus.innerText = getErrorMessage(xmlhttp.status);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1160,15 +1149,7 @@ function runThePopup() {
|
|||
|
||||
SB.setUsernameStatus.innerText = chrome.i18n.getMessage("success");
|
||||
} else if (xmlhttp.readyState == 4) {
|
||||
let errorMessage = "";
|
||||
|
||||
if([400, 429, 409, 502].includes(xmlhttp.status)) {
|
||||
errorMessage = chrome.i18n.getMessage(xmlhttp.status);
|
||||
} else {
|
||||
errorMessage = chrome.i18n.getMessage("connectionError") + xmlhttp.status;
|
||||
}
|
||||
|
||||
SB.setUsernameStatus.innerText = errorMessage;
|
||||
SB.setUsernameStatus.innerText = getErrorMessageI(xmlhttp.status);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1224,12 +1205,7 @@ function runThePopup() {
|
|||
//failure: duplicate vote
|
||||
addVoteMessage(chrome.i18n.getMessage("voteFail"), UUID)
|
||||
} else if (response.successType == -1) {
|
||||
if (response.statusCode == 502) {
|
||||
addVoteMessage(chrome.i18n.getMessage("serverDown"), UUID)
|
||||
} else {
|
||||
//failure: unknown error
|
||||
addVoteMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID)
|
||||
}
|
||||
addVoteMessage(getErrorMessage(response.statusCode), UUID)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
39
utils.js
39
utils.js
|
@ -66,3 +66,42 @@ function localizeHtmlPage() {
|
|||
}
|
||||
}
|
||||
|
||||
function generateUserID(length = 36) {
|
||||
let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let result = "";
|
||||
if (window.crypto && window.crypto.getRandomValues) {
|
||||
values = new Uint32Array(length);
|
||||
window.crypto.getRandomValues(values);
|
||||
for (i = 0; i < length; i++) {
|
||||
result += charset[values[i] % charset.length];
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += charset[Math.floor(Math.random() * charset.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the error message in a nice string
|
||||
*
|
||||
* @param {int} statusCode
|
||||
* @returns {string} errorMessage
|
||||
*/
|
||||
function getErrorMessage(statusCode) {
|
||||
let errorMessage = "";
|
||||
|
||||
if([400, 429, 409, 502, 0].includes(statusCode)) {
|
||||
//treat them the same
|
||||
if (statusCode == 503) statusCode = 502;
|
||||
|
||||
errorMessage = chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
|
||||
+ "\n\n" + chrome.i18n.getMessage("statusReminder");
|
||||
} else {
|
||||
errorMessage = chrome.i18n.getMessage("connectionError") + statusCode;
|
||||
}
|
||||
|
||||
return errorMessage;
|
||||
}
|
|
@ -59,6 +59,8 @@ class PreviewBar {
|
|||
duration = Math.floor(duration * 100) / 100;
|
||||
let width;
|
||||
for (let i = 0; i < timestamps.length; i++) {
|
||||
if (types[i] == null) continue;
|
||||
|
||||
width = (timestamps[i][1] - timestamps[i][0]) / duration * 100;
|
||||
width = Math.floor(width * 100) / 100;
|
||||
|
||||
|
|
|
@ -324,15 +324,7 @@ class SkipNotice {
|
|||
//add this as a hidden sponsorTime
|
||||
hiddenSponsorTimes.push(i);
|
||||
|
||||
let sponsorTimesLeft = sponsorTimes.slice();
|
||||
for (let j = 0; j < hiddenSponsorTimes.length; j++) {
|
||||
//remove this sponsor time
|
||||
sponsorTimesLeft.splice(hiddenSponsorTimes[j], 1);
|
||||
}
|
||||
|
||||
//update the preview
|
||||
previewBar.set(sponsorTimesLeft, [], v.duration);
|
||||
|
||||
updatePreviewBar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue