From 381c11ed999f2e64b5f80bc875d6ddba2cee1377 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 28 Nov 2019 18:03:33 -0500 Subject: [PATCH 1/2] Updated error messages. --- _locales/en/messages.json | 9 ++++++--- _locales/fr/messages.json | 3 --- _locales/it/messages.json | 3 --- _locales/pt_BR/messages.json | 3 --- _locales/pt_pt/messages.json | 3 --- _locales/ru/messages.json | 3 --- content.js | 2 +- popup.js | 2 +- 8 files changed, 8 insertions(+), 20 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 85381acbd6..6a52de6bc1 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -24,9 +24,6 @@ "409": { "message": "This has already been submitted before" }, - "502": { - "message": "It seems the server is down. Contact the dev to inform them." - }, "channelWhitelisted": { "message": "Channel Whitelisted!" }, @@ -272,5 +269,11 @@ "yourWork": { "message": "Your Work", "description": "Used to describe the section that will show you the statistics from your submissions." + }, + "502": { + "message": "The server seems to be overloaded. Try again in a few seconds." + }, + "errorCode": { + "message": "Error Code: " } } diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index b9749c06e5..24f973a969 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -24,9 +24,6 @@ "409": { "message": "Déja soumis" }, - "502": { - "message": "Le serveur ne fonctionne pas. Contactez le développeur." - }, "channelWhitelisted": { "message": "Cette chaîne est sur la liste blanche !" }, diff --git a/_locales/it/messages.json b/_locales/it/messages.json index 053da4ee58..2d63101f6b 100644 --- a/_locales/it/messages.json +++ b/_locales/it/messages.json @@ -24,9 +24,6 @@ "409": { "message": "Questo spezzone è già stato inviato" }, - "502": { - "message": "Sembra che il server non funzioni. Contatta lo sviluppatore." - }, "channelWhitelisted": { "message": "Canale aggiunto alla whitelist!" }, diff --git a/_locales/pt_BR/messages.json b/_locales/pt_BR/messages.json index 0cbcfd8bda..d400e1f4c3 100644 --- a/_locales/pt_BR/messages.json +++ b/_locales/pt_BR/messages.json @@ -24,9 +24,6 @@ "409": { "message": "Isso já foi enviado antes" }, - "502": { - "message": "Parece que o servidor caiu. Contate o desenvolvedor para informá-los." - }, "channelWhitelisted": { "message": "Canal adicionado à lista branca!" }, diff --git a/_locales/pt_pt/messages.json b/_locales/pt_pt/messages.json index 26e8ea384b..5665b9075b 100644 --- a/_locales/pt_pt/messages.json +++ b/_locales/pt_pt/messages.json @@ -24,9 +24,6 @@ "409": { "message": "Isso já foi enviado antes" }, - "502": { - "message": "Parece que o servidor caiu. Contacte o desenvolvedor para o informar." - }, "channelWhitelisted": { "message": "Canal adicionado à whitelist!" }, diff --git a/_locales/ru/messages.json b/_locales/ru/messages.json index 4ef09dd8bb..e6c0c9c389 100644 --- a/_locales/ru/messages.json +++ b/_locales/ru/messages.json @@ -24,9 +24,6 @@ "409": { "message": "Этот запрос был отправлен ранее." }, - "502": { - "message": "Сервер недоступен. Свяжитесь с разработчиком и сообщите ему об этом." - }, "channelWhitelisted": { "message": "Канал добавлен в белый список!" }, diff --git a/content.js b/content.js index 920f0cd69a..dca6047467 100644 --- a/content.js +++ b/content.js @@ -1048,7 +1048,7 @@ function sendSubmitMessage(){ //treat them the same if (response.statusCode == 503) response.statusCode = 502; - alert(chrome.i18n.getMessage(response.statusCode + "")); + alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode); } else { alert(chrome.i18n.getMessage("connectionError") + response.statusCode); } diff --git a/popup.js b/popup.js index 30c928af36..2b6b687808 100644 --- a/popup.js +++ b/popup.js @@ -830,7 +830,7 @@ function runThePopup() { //treat them the same if (response.statusCode == 503) response.statusCode = 502; - errorMessage = chrome.i18n.getMessage(response.statusCode + ""); + errorMessage = chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode; } else { errorMessage = chrome.i18n.getMessage("connectionError") + response.statusCode; } From cd5207f816ab2b5cee6dd58a70c26ec190637e2c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 2 Dec 2019 23:58:29 -0500 Subject: [PATCH 2/2] Added ability to disable auto skip. Resolves https://github.com/ajayyy/SponsorBlock/issues/131 and https://github.com/ajayyy/SponsorBlock/issues/162 --- _locales/en/messages.json | 15 +++++++++ content.js | 15 +++++++-- popup.html | 10 ++++++ popup.js | 29 ++++++++++++++++ utils/skipNotice.js | 70 +++++++++++++++++++++++++++++++++------ 5 files changed, 126 insertions(+), 13 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6a52de6bc1..72cf1bec4f 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -275,5 +275,20 @@ }, "errorCode": { "message": "Error Code: " + }, + "noticeTitleNotSkipped": { + "message": "Skip Sponsor?" + }, + "skip": { + "message": "Skip" + }, + "disableAutoSkip": { + "message": "Disable Auto Skip" + }, + "enableAutoSkip": { + "message": "Enable Auto Skip" + }, + "autoSkipDescription": { + "message": "Auto skip will skip sponsors for you. If disabled, a notice will appear asking if you'd like to skip." } } diff --git a/content.js b/content.js index dca6047467..5c90a96467 100644 --- a/content.js +++ b/content.js @@ -76,6 +76,15 @@ chrome.storage.sync.get(["disableSkipping"], function(result) { } }); +//should skips be manual +var disableAutoSkip = false; +chrome.storage.sync.get(["disableAutoSkip"], function(result) { + let disableAutoSkipStorage = result.disableAutoSkip; + if (disableAutoSkipStorage != undefined) { + disableAutoSkip = disableAutoSkipStorage; + } +}); + //should view counts be tracked var trackViewCount = false; chrome.storage.sync.get(["trackViewCount"], function(result) { @@ -606,7 +615,9 @@ function checkIfTimeToSkip(currentVideoTime, startTime, endTime) { //skip fromt he start time to the end time for a certain index sponsor time function skipToTime(v, index, sponsorTimes, openNotice) { - v.currentTime = sponsorTimes[index][1]; + if (!disableAutoSkip) { + v.currentTime = sponsorTimes[index][1]; + } lastSponsorTimeSkipped = sponsorTimes[index][0]; @@ -616,7 +627,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) { if (openNotice) { //send out the message saying that a sponsor message was skipped if (!dontShowNotice) { - let skipNotice = new SkipNotice(this, currentUUID); + let skipNotice = new SkipNotice(this, currentUUID, disableAutoSkip); if (dontShowNoticeOld) { //show why this notice is showing diff --git a/popup.html b/popup.html index 88cb5756ac..c09000f0c1 100644 --- a/popup.html +++ b/popup.html @@ -176,6 +176,16 @@

__MSG_Options__

+ + +
+ + __MSG_autoSkipDescription__ + + +
+
+
diff --git a/popup.js b/popup.js index 2b6b687808..eea0c7c071 100644 --- a/popup.js +++ b/popup.js @@ -34,7 +34,10 @@ function runThePopup() { // More controls "clearTimes", "submitTimes", + // options "showNoticeAgain", + "disableAutoSkip", + "enableAutoSkip", "hideVideoPlayerControls", "showVideoPlayerControls", "hideInfoButtonPlayerControls", @@ -89,6 +92,8 @@ function runThePopup() { SB.clearTimes.addEventListener("click", clearTimes); SB.submitTimes.addEventListener("click", submitTimes); SB.showNoticeAgain.addEventListener("click", showNoticeAgain); + SB.disableAutoSkip.addEventListener("click", () => setAutoSkip(true)); + SB.enableAutoSkip.addEventListener("click", () => setAutoSkip(false)); SB.setStartSponsorKeybind.addEventListener("click", () => setKeybind(true)); SB.setSubmitKeybind.addEventListener("click", () => setKeybind(false)); SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls); @@ -157,6 +162,15 @@ function runThePopup() { SB.showNoticeAgain.style.display = "unset"; } }); + + //show proper auto skip option + chrome.storage.sync.get(["disableAutoSkip"], function(result) { + let disableAutoSkip = result.disableAutoSkip; + if (disableAutoSkip != undefined && disableAutoSkip) { + SB.disableAutoSkip.style.display = "none"; + SB.enableAutoSkip.style.display = "unset"; + } + }); //show proper video player controls options chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { @@ -859,6 +873,21 @@ function runThePopup() { SB.showNoticeAgain.style.display = "none"; } + + function setAutoSkip(value) { + chrome.storage.sync.set({"disableAutoSkip": value}); + + if (value) { + // If it isn't shown, they can't manually skip + showNoticeAgain(); + + SB.disableAutoSkip.style.display = "none"; + SB.enableAutoSkip.style.display = "unset"; + } else { + SB.enableAutoSkip.style.display = "none"; + SB.disableAutoSkip.style.display = "unset"; + } + } function hideVideoPlayerControls() { chrome.storage.sync.set({"hideVideoPlayerControls": true}); diff --git a/utils/skipNotice.js b/utils/skipNotice.js index 4e35cc7b72..1819aea837 100644 --- a/utils/skipNotice.js +++ b/utils/skipNotice.js @@ -1,10 +1,25 @@ 'use strict'; -//The notice that tells the user that a sponsor was just skipped +/** + * The notice that tells the user that a sponsor was just skipped + */ class SkipNotice { - constructor(parent, UUID) { + /** + * @param {HTMLElement} parent + * @param {String} UUID + * @param {String} noticeTitle + * @param {boolean} manualSkip + */ + constructor(parent, UUID, manualSkip = false) { this.parent = parent; this.UUID = UUID; + this.manualSkip = manualSkip; + + let noticeTitle = chrome.i18n.getMessage("noticeTitle"); + + if (manualSkip) { + noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped"); + } this.maxCountdownTime = () => 4; //the countdown until this notice closes @@ -54,7 +69,7 @@ class SkipNotice { noticeMessage.id = "sponsorSkipMessage" + this.idSuffix; noticeMessage.classList.add("sponsorSkipMessage"); noticeMessage.classList.add("sponsorSkipObject"); - noticeMessage.innerText = chrome.i18n.getMessage("noticeTitle"); + noticeMessage.innerText = noticeTitle; //create the first column logoColumn.appendChild(logoElement); @@ -136,7 +151,10 @@ class SkipNotice { dontShowAgainButton.className = "sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"; dontShowAgainButton.addEventListener("click", dontShowNoticeAgain); - dontshowContainer.appendChild(dontShowAgainButton); + // Don't let them hide it if manually skipping + if (!this.manualSkip) { + dontshowContainer.appendChild(dontShowAgainButton); + } //add to row secondRow.appendChild(voteButtonsContainer); @@ -165,6 +183,10 @@ class SkipNotice { referenceNode.prepend(noticeElement); + if (manualSkip) { + this.unskippedMode(chrome.i18n.getMessage("skip")); + } + this.startCountdown(); } @@ -228,10 +250,13 @@ class SkipNotice { unskip() { unskipSponsorTime(this.UUID); + this.unskippedMode(chrome.i18n.getMessage("reskip")); + } + + /** Sets up notice to be not skipped yet */ + unskippedMode(buttonText) { //change unskip button to a reskip button - let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix); - unskipButton.innerText = chrome.i18n.getMessage("reskip"); - unskipButton.removeEventListener("click", this.unskipCallback); + let unskipButton = this.changeUnskipButton(buttonText); //setup new callback this.unskipCallback = this.reskip.bind(this); @@ -252,10 +277,8 @@ class SkipNotice { reskip() { reskipSponsorTime(this.UUID); - //change unskip button to a reskip button - let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix); - unskipButton.innerText = chrome.i18n.getMessage("unskip"); - unskipButton.removeEventListener("click", this.unskipCallback); + //change reskip button to a unskip button + let unskipButton = this.changeUnskipButton(chrome.i18n.getMessage("unskip")); //setup new callback this.unskipCallback = this.unskip.bind(this); @@ -265,6 +288,25 @@ class SkipNotice { this.maxCountdownTime = () => 4; this.countdownTime = this.maxCountdownTime(); this.updateTimerDisplay(); + + // See if the title should be changed + if (this.manualSkip) { + this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle")); + } + } + + /** + * Changes the text on the reskip button + * + * @param {string} text + * @returns {HTMLElement} unskipButton + */ + changeUnskipButton(text) { + let unskipButton = document.getElementById("sponsorSkipUnskipButton" + this.idSuffix); + unskipButton.innerText = text; + unskipButton.removeEventListener("click", this.unskipCallback); + + return unskipButton; } afterDownvote() { @@ -293,6 +335,12 @@ class SkipNotice { } } } + + changeNoticeTitle(title) { + let noticeElement = document.getElementById("sponsorSkipMessage" + this.idSuffix); + + noticeElement.innerText = title; + } addNoticeInfoMessage(message, message2) { let previousInfoMessage = document.getElementById("sponsorTimesInfoMessage" + this.idSuffix);