From 84e4adbc1204859178a60bc7611530a3f5899916 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 14:55:03 +0000 Subject: [PATCH 01/70] Config proxy [POC] Having a global SB.config that can be used to store get and set variables easily Example: SB.config.userID = "blah" --- popup.js | 135 +++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/popup.js b/popup.js index 113e44cc..1a242a79 100644 --- a/popup.js +++ b/popup.js @@ -1,8 +1,41 @@ +SB = {}; + +function configProxy() { + chrome.storage.onChanged.addListener((changes, namespace) => { + for (key in changes) { + localconfig[key] = changes[key].newValue; + } + }); + var handler = { + set: function(obj, prop, value) { + chrome.storage.sync.set({ + [prop]: value + }) + }, + get: function(obj, prop) { + return localconfig[prop] + } + }; + return new Proxy({}, handler); +} + +fetchConfig = _ => new Promise(function(resolve, reject) { + chrome.storage.sync.get(null, function(items) { + localconfig = items; // Data is ready + resolve(); + }); +}); + +async function config() { + localconfig = {}; + await fetchConfig(); + SB.config = configProxy(); +} //make this a function to allow this to run on the content page -function runThePopup() { +async function runThePopup() { localizeHtmlPage(); - + await config(); //is it in the popup or content script var inPopup = true; if (chrome.tabs == undefined) { @@ -22,8 +55,6 @@ function runThePopup() { inPopup = false; } - - var SB = {}; ["sponsorStart", // Top toggles @@ -95,7 +126,7 @@ function runThePopup() { SB.optionsButton.addEventListener("click", openOptions); SB.reportAnIssue.addEventListener("click", reportAnIssue); SB.hideDiscordButton.addEventListener("click", hideDiscordButton); - + //if true, the button now selects the end time let startTimeChosen = false; @@ -106,11 +137,9 @@ function runThePopup() { let currentVideoID = null; //see if discord link can be shown - chrome.storage.sync.get(["hideDiscordLink"], function(result) { - let hideDiscordLink = result.hideDiscordLink; + let hideDiscordLink = SB.config.hideDiscordLink; if (hideDiscordLink == undefined || !hideDiscordLink) { - chrome.storage.sync.get(["hideDiscordLaunches"], function(result) { - let hideDiscordLaunches = result.hideDiscordLaunches; + let hideDiscordLaunches = SB.config.hideDiscordLaunches; //only if less than 10 launches if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) { SB.discordButtonContainer.style.display = null; @@ -118,45 +147,36 @@ function runThePopup() { if (hideDiscordLaunches == undefined) { hideDiscordLaunches = 1; } - - chrome.storage.sync.set({"hideDiscordLaunches": hideDiscordLaunches + 1}); + SB.config.hideDiscordLaunches = hideDiscordLaunches + 1; } - }); } - }); //show proper disable skipping button - chrome.storage.sync.get(["disableSkipping"], function(result) { - let disableSkipping = result.disableSkipping; + let disableSkipping = SB.config.disableSkipping; if (disableSkipping != undefined && disableSkipping) { SB.disableSkipping.style.display = "none"; SB.enableSkipping.style.display = "unset"; } - }); //if the don't show notice again variable is true, an option to // disable should be available - chrome.storage.sync.get(["dontShowNotice"], function(result) { - let dontShowNotice = result.dontShowNotice; + let dontShowNotice = SB.config.dontShowNotice; if (dontShowNotice != undefined && dontShowNotice) { SB.showNoticeAgain.style.display = "unset"; } - }); //get the amount of times this user has contributed and display it to thank them - chrome.storage.sync.get(["sponsorTimesContributed"], function(result) { - if (result.sponsorTimesContributed != undefined) { - if (result.sponsorTimesContributed > 1) { + if (SB.config.sponsorTimesContributed != undefined) { + if (SB.config.sponsorTimesContributed > 1) { SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors"); } else { SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor"); } - SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed; + SB.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed; SB.sponsorTimesContributionsContainer.style.display = "unset"; //get the userID - chrome.storage.sync.get(["userID"], function(result) { - let userID = result.userID; + let userID = SB.config.userID; if (userID != undefined) { //there are probably some views on these submissions then //get the amount of views from the sponsors submitted @@ -193,43 +213,37 @@ function runThePopup() { } }); } - }); } - }); //get the amount of times this user has skipped a sponsor - chrome.storage.sync.get(["skipCount"], function(result) { - if (result.skipCount != undefined) { - if (result.skipCount != 1) { + if (SB.config.skipCount != undefined) { + if (SB.config.skipCount != 1) { SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors"); } else { SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor"); } - SB.sponsorTimesSkipsDoneDisplay.innerText = result.skipCount; + SB.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount; SB.sponsorTimesSkipsDoneContainer.style.display = "unset"; } - }); //get the amount of time this user has saved. - chrome.storage.sync.get(["minutesSaved"], function(result) { - if (result.minutesSaved != undefined) { - if (result.minutesSaved != 1) { + if (SB.config.minutesSaved != undefined) { + if (SB.config.minutesSaved != 1) { SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); } else { SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); } - SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(result.minutesSaved); + SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(SB.config.minutesSaved); SB.sponsorTimeSavedContainer.style.display = "unset"; } - }); chrome.tabs.query({ active: true, currentWindow: true }, onTabs); - + function onTabs(tabs) { chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) { if (result != undefined && result.videoID) { @@ -251,8 +265,7 @@ function runThePopup() { //load video times for this video let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimesStorage = result[sponsorTimeKey]; + let sponsorTimesStorage = SB.config.sponsorTimeKey[sponsorTimeKey]; if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) { startTimeChosen = true; @@ -268,7 +281,6 @@ function runThePopup() { showSubmitTimesIfNecessary(); } - }); //check if this video's sponsors are known chrome.tabs.sendMessage( @@ -350,7 +362,7 @@ function runThePopup() { let sponsorTimeKey = "sponsorTimes" + currentVideoID; let localStartTimeChosen = startTimeChosen; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() { + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; //send a message to the client script if (localStartTimeChosen) { chrome.tabs.query({ @@ -363,7 +375,6 @@ function runThePopup() { ); }); } - }); updateStartTimeChosen(); @@ -684,7 +695,7 @@ function runThePopup() { //save this let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() { + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; chrome.tabs.query({ active: true, currentWindow: true @@ -694,7 +705,6 @@ function runThePopup() { {message: "sponsorDataChanged"} ); }); - }); if (closeEditMode) { displaySponsorTimes(); @@ -725,7 +735,7 @@ function runThePopup() { //save this let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() { + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; chrome.tabs.query({ active: true, currentWindow: true @@ -735,7 +745,6 @@ function runThePopup() { {message: "sponsorDataChanged"} ); }); - }); //update display displaySponsorTimes(); @@ -778,7 +787,7 @@ function runThePopup() { sponsorTimes = []; let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, function() { + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; chrome.tabs.query({ active: true, currentWindow: true @@ -788,7 +797,6 @@ function runThePopup() { {message: "sponsorDataChanged"} ); }); - }); displaySponsorTimes(); @@ -826,7 +834,7 @@ function runThePopup() { } function showNoticeAgain() { - chrome.storage.sync.set({"dontShowNotice": false}); + SB.config.dontShowNotice = false; chrome.tabs.query({ active: true, @@ -875,10 +883,8 @@ function runThePopup() { //make the options username setting option visible function setUsernameButton() { - //get the userID - chrome.storage.sync.get(["userID"], function(result) { //get username from the server - sendRequestToServer("GET", "/api/getUsername?userID=" + result.userID, function (xmlhttp, error) { + sendRequestToServer("GET", "/api/getUsername?userID=" + SB.config.userID, function (xmlhttp, error) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { SB.usernameInput.value = JSON.parse(xmlhttp.responseText).userName; @@ -898,7 +904,6 @@ function runThePopup() { SB.setUsernameStatus.innerText = getErrorMessage(xmlhttp.status); } }); - }); } //submit the new username @@ -908,8 +913,7 @@ function runThePopup() { SB.setUsernameStatus.innerText = "Loading..."; //get the userID - chrome.storage.sync.get(["userID"], function(result) { - sendRequestToServer("POST", "/api/setUsername?userID=" + result.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) { + sendRequestToServer("POST", "/api/setUsername?userID=" + SB.config.userID + "&username=" + SB.usernameInput.value, function (xmlhttp, error) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { //submitted SB.submitUsername.style.display = "none"; @@ -920,7 +924,6 @@ function runThePopup() { SB.setUsernameStatus.innerText = getErrorMessageI(xmlhttp.status); } }); - }); SB.setUsernameContainer.style.display = "none"; @@ -980,8 +983,7 @@ function runThePopup() { } function hideDiscordButton() { - chrome.storage.sync.set({"hideDiscordLink": true}); - + SB.config.hideDiscordLink = true; SB.discordButtonContainer.style.display = "none"; } @@ -1010,8 +1012,7 @@ function runThePopup() { {message: 'getChannelURL'}, function(response) { //get whitelisted channels - chrome.storage.sync.get(["whitelistedChannels"], function(result) { - let whitelistedChannels = result.whitelistedChannels; + let whitelistedChannels = SB.config.whitelistedChannels; if (whitelistedChannels == undefined) { whitelistedChannels = []; } @@ -1027,7 +1028,7 @@ function runThePopup() { SB.downloadedSponsorMessageTimes.style.fontWeight = "bold"; //save this - chrome.storage.sync.set({whitelistedChannels: whitelistedChannels}); + SB.config.whitelistedChannels = whitelistedChannels; //send a message to the client chrome.tabs.query({ @@ -1041,7 +1042,6 @@ function runThePopup() { }); } ); - }); } ); }); @@ -1058,8 +1058,7 @@ function runThePopup() { {message: 'getChannelURL'}, function(response) { //get whitelisted channels - chrome.storage.sync.get(["whitelistedChannels"], function(result) { - let whitelistedChannels = result.whitelistedChannels; + let whitelistedChannels = SB.config.whitelistedChannels; if (whitelistedChannels == undefined) { whitelistedChannels = []; } @@ -1076,7 +1075,7 @@ function runThePopup() { SB.downloadedSponsorMessageTimes.style.fontWeight = "unset"; //save this - chrome.storage.sync.set({whitelistedChannels: whitelistedChannels}); + SB.config.whitelistedChannels = whitelistedChannels; //send a message to the client chrome.tabs.query({ @@ -1090,7 +1089,6 @@ function runThePopup() { }); } ); - }); } ); }); @@ -1100,7 +1098,7 @@ function runThePopup() { * Should skipping be disabled (visuals stay) */ function toggleSkipping(disabled) { - chrome.storage.sync.set({"disableSkipping": disabled}); + SB.config.disableSkipping = disabled; let hiddenButton = SB.disableSkipping; let shownButton = SB.enableSkipping; @@ -1169,7 +1167,6 @@ function runThePopup() { if (chrome.tabs != undefined) { //add the width restriction (because Firefox) document.getElementById("sponorBlockStyleSheet").sheet.insertRule('.popupBody { width: 325 }', 0); - //this means it is actually opened in the popup runThePopup(); } From 3fbb689e0a49d70950a447d0a1ce2e30c771a36f Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:01:17 +0000 Subject: [PATCH 02/70] Moving utils --- popup.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/popup.js b/popup.js index 1a242a79..87ba0d30 100644 --- a/popup.js +++ b/popup.js @@ -1,37 +1,3 @@ -SB = {}; - -function configProxy() { - chrome.storage.onChanged.addListener((changes, namespace) => { - for (key in changes) { - localconfig[key] = changes[key].newValue; - } - }); - var handler = { - set: function(obj, prop, value) { - chrome.storage.sync.set({ - [prop]: value - }) - }, - get: function(obj, prop) { - return localconfig[prop] - } - }; - return new Proxy({}, handler); -} - -fetchConfig = _ => new Promise(function(resolve, reject) { - chrome.storage.sync.get(null, function(items) { - localconfig = items; // Data is ready - resolve(); - }); -}); - -async function config() { - localconfig = {}; - await fetchConfig(); - SB.config = configProxy(); -} - //make this a function to allow this to run on the content page async function runThePopup() { localizeHtmlPage(); From 272698f97bb9915a72171c15df0de46c7f27890d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:03:43 +0000 Subject: [PATCH 03/70] Update utils.js --- utils.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/utils.js b/utils.js index 44486ab9..df283367 100644 --- a/utils.js +++ b/utils.js @@ -1,3 +1,37 @@ +SB = {}; + +function configProxy() { + chrome.storage.onChanged.addListener((changes, namespace) => { + for (key in changes) { + localconfig[key] = changes[key].newValue; + } + }); + var handler = { + set: function(obj, prop, value) { + chrome.storage.sync.set({ + [prop]: value + }) + }, + get: function(obj, prop) { + return localconfig[prop] + } + }; + return new Proxy({}, handler); +} + +fetchConfig = _ => new Promise(function(resolve, reject) { + chrome.storage.sync.get(null, function(items) { + localconfig = items; // Data is ready + resolve(); + }); +}); + +async function config() { + localconfig = {}; + await fetchConfig(); + SB.config = configProxy(); +} + // Function that can be used to wait for a condition before returning async function wait(condition, timeout = 5000, check = 100) { return await new Promise((resolve, reject) => { From 2917de6776175dfa870968ab0618463d76e0e60f Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:06:33 +0000 Subject: [PATCH 04/70] Moved localconfig to SB object --- utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils.js b/utils.js index df283367..edea86dc 100644 --- a/utils.js +++ b/utils.js @@ -13,7 +13,7 @@ function configProxy() { }) }, get: function(obj, prop) { - return localconfig[prop] + return SB.localconfig[prop] } }; return new Proxy({}, handler); @@ -21,13 +21,13 @@ function configProxy() { fetchConfig = _ => new Promise(function(resolve, reject) { chrome.storage.sync.get(null, function(items) { - localconfig = items; // Data is ready + SB.localconfig = items; // Data is ready resolve(); }); }); async function config() { - localconfig = {}; + SB.localconfig = {}; await fetchConfig(); SB.config = configProxy(); } From a94d941125e17288f83a186844b6e4b01089fc87 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:16:46 +0000 Subject: [PATCH 05/70] Added sync config --- utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils.js b/utils.js index edea86dc..986c4ee1 100644 --- a/utils.js +++ b/utils.js @@ -32,6 +32,9 @@ async function config() { SB.config = configProxy(); } +// Sync config +config(); + // Function that can be used to wait for a condition before returning async function wait(condition, timeout = 5000, check = 100) { return await new Promise((resolve, reject) => { From 67f9697f3ff2066429290647cb728dfa8e944dc5 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:17:10 +0000 Subject: [PATCH 06/70] test --- popup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/popup.js b/popup.js index 87ba0d30..0e01caa6 100644 --- a/popup.js +++ b/popup.js @@ -1,7 +1,6 @@ //make this a function to allow this to run on the content page async function runThePopup() { localizeHtmlPage(); - await config(); //is it in the popup or content script var inPopup = true; if (chrome.tabs == undefined) { From 8baf11a053fba21e625f59916ff6789031382332 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 19:20:20 +0000 Subject: [PATCH 07/70] Forgot SB. --- utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.js b/utils.js index 986c4ee1..6b211901 100644 --- a/utils.js +++ b/utils.js @@ -3,7 +3,7 @@ SB = {}; function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - localconfig[key] = changes[key].newValue; + SB.localconfig[key] = changes[key].newValue; } }); var handler = { From 4450aaa3b382f93e5d8a30d0a2ec24691e3452cd Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:07:03 +0000 Subject: [PATCH 08/70] Moving to separate due to load order --- utils.js | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/utils.js b/utils.js index 6b211901..44486ab9 100644 --- a/utils.js +++ b/utils.js @@ -1,40 +1,3 @@ -SB = {}; - -function configProxy() { - chrome.storage.onChanged.addListener((changes, namespace) => { - for (key in changes) { - SB.localconfig[key] = changes[key].newValue; - } - }); - var handler = { - set: function(obj, prop, value) { - chrome.storage.sync.set({ - [prop]: value - }) - }, - get: function(obj, prop) { - return SB.localconfig[prop] - } - }; - return new Proxy({}, handler); -} - -fetchConfig = _ => new Promise(function(resolve, reject) { - chrome.storage.sync.get(null, function(items) { - SB.localconfig = items; // Data is ready - resolve(); - }); -}); - -async function config() { - SB.localconfig = {}; - await fetchConfig(); - SB.config = configProxy(); -} - -// Sync config -config(); - // Function that can be used to wait for a condition before returning async function wait(condition, timeout = 5000, check = 100) { return await new Promise((resolve, reject) => { From 61b8427270a07fbf8e46b08a46d87692703d5b8b Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:07:43 +0000 Subject: [PATCH 09/70] File used to control the SB object --- SB.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 SB.js diff --git a/SB.js b/SB.js new file mode 100644 index 00000000..75b98294 --- /dev/null +++ b/SB.js @@ -0,0 +1,36 @@ +SB = {}; + +function configProxy() { + chrome.storage.onChanged.addListener((changes, namespace) => { + for (key in changes) { + SB.localconfig[key] = changes[key].newValue; + } + }); + var handler = { + set: function(obj, prop, value) { + chrome.storage.sync.set({ + [prop]: value + }) + }, + get: function(obj, prop) { + return SB.localconfig[prop] + } + }; + return new Proxy({}, handler); +} + +fetchConfig = _ => new Promise(function(resolve, reject) { + chrome.storage.sync.get(null, function(items) { + SB.localconfig = items; // Data is ready + resolve(); + }); +}); + +async function config() { + SB.localconfig = {}; + await fetchConfig(); + SB.config = configProxy(); +} + +// Sync config +config(); From 6ceeaebd9dd53cd4e535aafbce3802a8c5144fc2 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:08:11 +0000 Subject: [PATCH 10/70] Added SB --- popup.html | 1 + 1 file changed, 1 insertion(+) diff --git a/popup.html b/popup.html index 6d453871..624b8b55 100644 --- a/popup.html +++ b/popup.html @@ -1,6 +1,7 @@ __MSG_openPopup__ + From 796bf6ef453eceaad86bcfc61af67168267150f2 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:10:16 +0000 Subject: [PATCH 11/70] Added SB.js --- manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.json b/manifest.json index aea51e65..f9b5a044 100644 --- a/manifest.json +++ b/manifest.json @@ -52,6 +52,7 @@ }, "background": { "scripts":[ + "SB.js", "utils.js", "config.js", "background.js" From 25672a64961f7dd37fce2e214497897dfaa9208d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:17:27 +0000 Subject: [PATCH 12/70] SB.js content script --- manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.json b/manifest.json index f9b5a044..b128617a 100644 --- a/manifest.json +++ b/manifest.json @@ -13,6 +13,7 @@ "all_frames": true, "js": [ "config.js", + "SB.js", "utils/previewBar.js", "utils/skipNotice.js", "utils.js", From 7bbbe0dcf3ba41210ae90d5a138b9d5e066d0ed6 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:56:30 +0000 Subject: [PATCH 13/70] Use SB.config --- content.js | 166 +++++++++++++++++++++-------------------------------- 1 file changed, 66 insertions(+), 100 deletions(-) diff --git a/content.js b/content.js index 0a829e51..3a6b244f 100644 --- a/content.js +++ b/content.js @@ -72,51 +72,42 @@ var popupInitialised = false; //should skips happen at all var disableSkipping = false; -chrome.storage.sync.get(["disableSkipping"], function(result) { - let disableSkippingStorage = result.disableSkipping; - if (disableSkippingStorage != undefined) { - disableSkipping = disableSkippingStorage; - } -}); +let disableSkippingStorage = SB.config.disableSkipping; +if (disableSkippingStorage != undefined) { + disableSkipping = disableSkippingStorage; +} //should skips be manual var disableAutoSkip = false; -chrome.storage.sync.get(["disableAutoSkip"], function(result) { - let disableAutoSkipStorage = result.disableAutoSkip; - if (disableAutoSkipStorage != undefined) { - disableAutoSkip = disableAutoSkipStorage; - } -}); +let disableAutoSkipStorage = SB.config.disableAutoSkip; +if (disableAutoSkipStorage != undefined) { + disableAutoSkip = disableAutoSkipStorage; +} //should view counts be tracked var trackViewCount = false; -chrome.storage.sync.get(["trackViewCount"], function(result) { - let trackViewCountStorage = result.trackViewCount; - if (trackViewCountStorage != undefined) { - trackViewCount = trackViewCountStorage; - } else { - trackViewCount = true; - } -}); +let trackViewCountStorage = SB.config.trackViewCount; +if (trackViewCountStorage != undefined) { + trackViewCount = trackViewCountStorage; +} else { + trackViewCount = true; +} //if the notice should not be shown //happens when the user click's the "Don't show notice again" button //option renamed when new notice was made var dontShowNotice = false; -chrome.storage.sync.get(["dontShowNotice"], function(result) { - let dontShowNoticeAgain = result.dontShowNotice; - if (dontShowNoticeAgain != undefined) { - dontShowNotice = dontShowNoticeAgain; - } -}); +let dontShowNoticeAgain = SB.config.dontShowNotice; +if (dontShowNoticeAgain != undefined) { + dontShowNotice = dontShowNoticeAgain; +} + //load the legacy option to hide the notice var dontShowNoticeOld = false; -chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) { - let dontShowNoticeAgain = result.dontShowNoticeAgain; - if (dontShowNoticeAgain != undefined) { - dontShowNoticeOld = dontShowNoticeAgain; - } -}); +let dontShowNoticeAgain = SB.config.dontShowNoticeAgain; +if (dontShowNoticeAgain != undefined) { + dontShowNoticeOld = dontShowNoticeAgain; +} //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); @@ -231,12 +222,9 @@ document.onkeydown = async function(e){ let video = document.getElementById("movie_player"); - let startSponsorKey = await new Promise((resolve, reject) => { - chrome.storage.sync.get(["startSponsorKeybind"], (result) => resolve(result)); - }); - let submitKey = await new Promise((resolve, reject) => { - chrome.storage.sync.get(["submitKeybind"], (result) => resolve(result)); - }); + let startSponsorKey = SB.config.startSponsorKeybind; + + let submitKey = SB.config.submitKeybind; if (startSponsorKey.startSponsorKeybind === undefined) { startSponsorKey.startSponsorKeybind = ";" @@ -303,9 +291,7 @@ function videoIDChange(id) { if (previousVideoID != null) { //get the sponsor times from storage let sponsorTimeKey = 'sponsorTimes' + previousVideoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimes = result[sponsorTimeKey]; - + let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; if (sponsorTimes != undefined && sponsorTimes.length > 0) { //warn them that they have unsubmitted sponsor times chrome.runtime.sendMessage({ @@ -316,7 +302,6 @@ function videoIDChange(id) { //set the previous video id to the currentID previousVideoID = id; - }); } else { //set the previous id now, don't wait for chrome.storage.get previousVideoID = id; @@ -359,29 +344,24 @@ function videoIDChange(id) { }); }); - //see if video controls buttons should be added - chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) { - if (result.hideVideoPlayerControls != undefined) { - hideVideoPlayerControls = result.hideVideoPlayerControls; + //see if video controls buttons should be added + if (SB.config.hideVideoPlayerControls != undefined) { + hideVideoPlayerControls = SB.config.hideVideoPlayerControls; } updateVisibilityOfPlayerControlsButton(); - }); - chrome.storage.sync.get(["hideInfoButtonPlayerControls"], function(result) { - if (result.hideInfoButtonPlayerControls != undefined) { - hideInfoButtonPlayerControls = result.hideInfoButtonPlayerControls; + + if (SB.config.hideInfoButtonPlayerControls != undefined) { + hideInfoButtonPlayerControls = SB.config.hideInfoButtonPlayerControls; } updateVisibilityOfPlayerControlsButton(); - }); - chrome.storage.sync.get(["hideDeleteButtonPlayerControls"], function(result) { - if (result.hideDeleteButtonPlayerControls != undefined) { - hideDeleteButtonPlayerControls = result.hideDeleteButtonPlayerControls; + + if (SB.config.hideDeleteButtonPlayerControls != undefined) { + hideDeleteButtonPlayerControls = SB.config.hideDeleteButtonPlayerControls; } updateVisibilityOfPlayerControlsButton(false); - }); - } function sponsorsLookup(id, channelIDPromise) { @@ -542,15 +522,13 @@ function getChannelID() { //checks if this channel is whitelisted, should be done only after the channelID has been loaded function whitelistCheck() { //see if this is a whitelisted channel - chrome.storage.sync.get(["whitelistedChannels"], function(result) { - let whitelistedChannels = result.whitelistedChannels; + let whitelistedChannels = SB.config.whitelistedChannels; console.log(channelURL) if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) { channelWhitelisted = true; } - }); } //video skipping @@ -640,7 +618,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) { skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2")); //remove this setting - chrome.storage.sync.remove(["dontShowNoticeAgain"]); + delete SB.config["dontShowNoticeAgain"]; dontShowNoticeOld = false; } @@ -657,17 +635,12 @@ function skipToTime(v, index, sponsorTimes, openNotice) { if (!disableAutoSkip) { // Count this as a skip - chrome.storage.sync.get(["minutesSaved"], function(result) { - if (result.minutesSaved === undefined) result.minutesSaved = 0; + if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0; - chrome.storage.sync.set({"minutesSaved": result.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60 }); - }); - chrome.storage.sync.get(["skipCount"], function(result) { - if (result.skipCount === undefined) result.skipCount = 0; - - chrome.storage.sync.set({"skipCount": result.skipCount + 1 }); - }); + SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60; + if (SB.config.skipCount === undefined) SB.config.skipCount = 0; + SB.config.skipCount = SB.config.skipCount + 1; sponsorSkipped[index] = true; } } @@ -907,27 +880,25 @@ function clearSponsorTimes() { let currentVideoID = sponsorVideoID; let sponsorTimeKey = 'sponsorTimes' + currentVideoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimes = result[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; - if (sponsorTimes != undefined && sponsorTimes.length > 0) { - let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes); - confirmMessage += chrome.i18n.getMessage("confirmMSG") - if(!confirm(confirmMessage)) return; + if (sponsorTimes != undefined && sponsorTimes.length > 0) { + let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes); + confirmMessage += chrome.i18n.getMessage("confirmMSG") + if(!confirm(confirmMessage)) return; - //clear the sponsor times - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: []}); + //clear the sponsor times + let sponsorTimeKey = "sponsorTimes" + currentVideoID; + SB.config.sponsorTimeKey = []; - //clear sponsor times submitting - sponsorTimesSubmitting = []; + //clear sponsor times submitting + sponsorTimesSubmitting = []; - updatePreviewBar(); + updatePreviewBar(); - //set buttons to be correct - changeStartSponsorButton(true, false); - } - }); + //set buttons to be correct + changeStartSponsorButton(true, false); + } } //if skipNotice is null, it will not affect the UI @@ -949,17 +920,14 @@ function vote(type, UUID, skipNotice) { sponsorSkipped[sponsorIndex] = false; } - // Count this as a skip - chrome.storage.sync.get(["minutesSaved"], function(result) { - if (result.minutesSaved === undefined) result.minutesSaved = 0; + // Count this as a skip + if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0; - chrome.storage.sync.set({"minutesSaved": result.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60 }); - }); - chrome.storage.sync.get(["skipCount"], function(result) { - if (result.skipCount === undefined) result.skipCount = 0; + SB.config.minutesSaved = SB.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60; + + if (SB.config.skipCount === undefined) SB.config.skipCount = 0; - chrome.storage.sync.set({"skipCount": result.skipCount + factor * 1 }); - }); + SB.config.skipCount = SB.config.skipCount + factor * 1; } chrome.runtime.sendMessage({ @@ -997,7 +965,7 @@ function closeAllSkipNotices(){ } function dontShowNoticeAgain() { - chrome.storage.sync.set({"dontShowNotice": true}); + SB.config.dontShowNotice = true; dontShowNotice = true; @@ -1028,8 +996,7 @@ function submitSponsorTimes() { let currentVideoID = sponsorVideoID; let sponsorTimeKey = 'sponsorTimes' + currentVideoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimes = result[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; if (sponsorTimes != undefined && sponsorTimes.length > 0) { //check if a sponsor exceeds the duration of the video @@ -1039,7 +1006,7 @@ function submitSponsorTimes() { } } //update sponsorTimes - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; //update sponsorTimesSubmitting sponsorTimesSubmitting = sponsorTimes; @@ -1050,7 +1017,6 @@ function submitSponsorTimes() { sendSubmitMessage(); } - }); } @@ -1086,7 +1052,7 @@ function sendSubmitMessage(){ //clear the sponsor times let sponsorTimeKey = "sponsorTimes" + currentVideoID; - chrome.storage.sync.set({[sponsorTimeKey]: []}); + SB.config.sponsorTimeKey[sponsorTimeKey] = []; //add submissions to current sponsors list sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); From 2a1b60596b1687473f58f1ccb4ec498dabb9b8d0 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 21:30:54 +0000 Subject: [PATCH 14/70] debug --- content.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/content.js b/content.js index 3a6b244f..f02c72d0 100644 --- a/content.js +++ b/content.js @@ -71,18 +71,8 @@ var sponsorTimesSubmitting = []; var popupInitialised = false; //should skips happen at all -var disableSkipping = false; -let disableSkippingStorage = SB.config.disableSkipping; -if (disableSkippingStorage != undefined) { - disableSkipping = disableSkippingStorage; -} - -//should skips be manual -var disableAutoSkip = false; -let disableAutoSkipStorage = SB.config.disableAutoSkip; -if (disableAutoSkipStorage != undefined) { - disableAutoSkip = disableAutoSkipStorage; -} +var disableSkipping = (SB.config.disableSkipping !== undefined); +var disableAutoSkip = (SB.config.disableSkipping !== undefined); //should view counts be tracked var trackViewCount = false; @@ -97,16 +87,17 @@ if (trackViewCountStorage != undefined) { //happens when the user click's the "Don't show notice again" button //option renamed when new notice was made var dontShowNotice = false; -let dontShowNoticeAgain = SB.config.dontShowNotice; -if (dontShowNoticeAgain != undefined) { - dontShowNotice = dontShowNoticeAgain; + +dontShowNoticeAgain2 = SB.config.dontShowNoticeAgain; + +if (dontShowNoticeAgain2 != undefined) { + dontShowNotice = dontShowNoticeAgain2; } //load the legacy option to hide the notice var dontShowNoticeOld = false; -let dontShowNoticeAgain = SB.config.dontShowNoticeAgain; -if (dontShowNoticeAgain != undefined) { - dontShowNoticeOld = dontShowNoticeAgain; +if (dontShowNoticeAgain2 != undefined) { + dontShowNoticeOld = dontShowNoticeAgain2; } //get messages from the background script and the popup From 87098d1c3e8594c7a554d57271a78a635cf6313e Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:04:40 +0000 Subject: [PATCH 15/70] Update content.js --- content.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/content.js b/content.js index f02c72d0..d86d25de 100644 --- a/content.js +++ b/content.js @@ -70,17 +70,13 @@ var sponsorTimesSubmitting = []; //this is used to close the popup on YouTube when the other popup opens var popupInitialised = false; -//should skips happen at all -var disableSkipping = (SB.config.disableSkipping !== undefined); -var disableAutoSkip = (SB.config.disableSkipping !== undefined); - //should view counts be tracked -var trackViewCount = false; -let trackViewCountStorage = SB.config.trackViewCount; -if (trackViewCountStorage != undefined) { - trackViewCount = trackViewCountStorage; +var SB.config.trackViewCount = false; +let SB.config.trackViewCountStorage = SB.config.SB.config.trackViewCount; +if (SB.config.trackViewCountStorage != undefined) { + SB.config.trackViewCount = SB.config.trackViewCountStorage; } else { - trackViewCount = true; + SB.config.trackViewCount = true; } //if the notice should not be shown @@ -200,8 +196,7 @@ function messageListener(request, sender, sendResponse) { break; case "trackViewCount": - trackViewCount = request.value; - + SB.config.trackViewCount = request.value; break; } } @@ -434,7 +429,7 @@ function sponsorsLookup(id, channelIDPromise) { }); //add the event to run on the videos "ontimeupdate" - if (!disableSkipping) { + if (!SB.config.disableSkipping) { v.ontimeupdate = function () { sponsorCheck(); }; @@ -524,7 +519,7 @@ function whitelistCheck() { //video skipping function sponsorCheck() { - if (disableSkipping) { + if (SB.config.disableSkipping) { // Make sure this isn't called again v.ontimeupdate = null; return; @@ -590,7 +585,7 @@ 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) { - if (!disableAutoSkip) { + if (!SB.config.disableAutoSkip) { v.currentTime = sponsorTimes[index][1]; } @@ -602,7 +597,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, disableAutoSkip); + let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip); if (dontShowNoticeOld) { //show why this notice is showing @@ -614,17 +609,17 @@ function skipToTime(v, index, sponsorTimes, openNotice) { } //auto-upvote this sponsor - if (trackViewCount && !disableAutoSkip) { + if (SB.config.trackViewCount && !SB.config.disableAutoSkip) { vote(1, currentUUID, null); } } } //send telemetry that a this sponsor was skipped - if (trackViewCount && !sponsorSkipped[index]) { + if (SB.config.trackViewCount && !sponsorSkipped[index]) { sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID); - if (!disableAutoSkip) { + if (!SB.config.disableAutoSkip) { // Count this as a skip if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0; From da17dd8bae356d974edae2bb0000d5d174977ef5 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:46:16 +0000 Subject: [PATCH 16/70] Added addDefaults and resetConfig --- SB.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 75b98294..89332ae5 100644 --- a/SB.js +++ b/SB.js @@ -27,10 +27,31 @@ fetchConfig = _ => new Promise(function(resolve, reject) { }); async function config() { - SB.localconfig = {}; await fetchConfig(); + addDefaults(); SB.config = configProxy(); } +SB.defaults = { + "startSponsorKeybind": ";", + "submitKeybind": "'", + "minutesSaved": 0, + "skipCount": 0 +} + +// Reset config +function resetConfig() { + SB.config = SB.defaults; +}; + +// Add defaults +function addDefaults() { + Object.keys(SB.defaults).forEach(key => { + if(!SB.localconfig.hasOwnProperty(key)) { + SB.localconfig = SB.defaults[key]; + } + }); +}; + // Sync config config(); From 5e2bc437229c7b25c180c22e9364747580ede033 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:48:29 +0000 Subject: [PATCH 17/70] Update SB.js --- SB.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 89332ae5..e577b25f 100644 --- a/SB.js +++ b/SB.js @@ -36,7 +36,9 @@ SB.defaults = { "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, - "skipCount": 0 + "skipCount": 0, + "disableSkipping": false, + "disableAutoSkip": false } // Reset config From 1ac99892885edfe04f4a4b596182373d52a58e6f Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:50:52 +0000 Subject: [PATCH 18/70] Use defaults --- content.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/content.js b/content.js index d86d25de..c2e146d7 100644 --- a/content.js +++ b/content.js @@ -212,13 +212,6 @@ document.onkeydown = async function(e){ let submitKey = SB.config.submitKeybind; - if (startSponsorKey.startSponsorKeybind === undefined) { - startSponsorKey.startSponsorKeybind = ";" - } - if (submitKey.submitKeybind === undefined) { - submitKey.submitKeybind = "'" - } - //is the video in focus, otherwise they could be typing a comment if (document.activeElement === video) { if(key == startSponsorKey.startSponsorKeybind){ @@ -621,11 +614,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) { if (!SB.config.disableAutoSkip) { // Count this as a skip - if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0; - SB.config.minutesSaved = SB.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60; - if (SB.config.skipCount === undefined) SB.config.skipCount = 0; - SB.config.skipCount = SB.config.skipCount + 1; sponsorSkipped[index] = true; } @@ -907,11 +896,9 @@ function vote(type, UUID, skipNotice) { } // Count this as a skip - if (SB.config.minutesSaved === undefined) SB.config.minutesSaved = 0; - SB.config.minutesSaved = SB.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60; - if (SB.config.skipCount === undefined) SB.config.skipCount = 0; + SB.config.skipCount = 0; SB.config.skipCount = SB.config.skipCount + factor * 1; } From 41352a5116947cd2d2db3d4040c19a71192123ca Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:52:41 +0000 Subject: [PATCH 19/70] Update content.js --- content.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/content.js b/content.js index c2e146d7..81388d51 100644 --- a/content.js +++ b/content.js @@ -70,15 +70,6 @@ var sponsorTimesSubmitting = []; //this is used to close the popup on YouTube when the other popup opens var popupInitialised = false; -//should view counts be tracked -var SB.config.trackViewCount = false; -let SB.config.trackViewCountStorage = SB.config.SB.config.trackViewCount; -if (SB.config.trackViewCountStorage != undefined) { - SB.config.trackViewCount = SB.config.trackViewCountStorage; -} else { - SB.config.trackViewCount = true; -} - //if the notice should not be shown //happens when the user click's the "Don't show notice again" button //option renamed when new notice was made From 9dd954e7d85a6af0053c600a76c3608bdabdebc6 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Tue, 31 Dec 2019 22:54:02 +0000 Subject: [PATCH 20/70] Added default for trackViewCount --- SB.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index e577b25f..aa325348 100644 --- a/SB.js +++ b/SB.js @@ -38,7 +38,8 @@ SB.defaults = { "minutesSaved": 0, "skipCount": 0, "disableSkipping": false, - "disableAutoSkip": false + "disableAutoSkip": false, + "trackViewCount": false } // Reset config From 477ae3eb2c731d400eb926699c45a5d1ef663de9 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 12:27:59 +0000 Subject: [PATCH 21/70] Update SB.js --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index aa325348..6d521a1f 100644 --- a/SB.js +++ b/SB.js @@ -51,7 +51,7 @@ function resetConfig() { function addDefaults() { Object.keys(SB.defaults).forEach(key => { if(!SB.localconfig.hasOwnProperty(key)) { - SB.localconfig = SB.defaults[key]; + SB.localconfig[key] = SB.defaults[key]; } }); }; From 32356d711de4cfe23a056ee23694ebc1231d6cb8 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 12:35:54 +0000 Subject: [PATCH 22/70] Update SB.js --- SB.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 6d521a1f..6cfc470f 100644 --- a/SB.js +++ b/SB.js @@ -39,7 +39,8 @@ SB.defaults = { "skipCount": 0, "disableSkipping": false, "disableAutoSkip": false, - "trackViewCount": false + "trackViewCount": false, + "dontShowNoticeAgain": false } // Reset config From a9b678f0ffa3ad086e777d0fdcb9b72dc42217ca Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 12:36:29 +0000 Subject: [PATCH 23/70] dontShowNoticeAgain --- content.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/content.js b/content.js index 81388d51..86bbe1e7 100644 --- a/content.js +++ b/content.js @@ -73,19 +73,7 @@ var popupInitialised = false; //if the notice should not be shown //happens when the user click's the "Don't show notice again" button //option renamed when new notice was made -var dontShowNotice = false; - -dontShowNoticeAgain2 = SB.config.dontShowNoticeAgain; - -if (dontShowNoticeAgain2 != undefined) { - dontShowNotice = dontShowNoticeAgain2; -} - -//load the legacy option to hide the notice -var dontShowNoticeOld = false; -if (dontShowNoticeAgain2 != undefined) { - dontShowNoticeOld = dontShowNoticeAgain2; -} +dontShowNoticeAgain = SB.config.dontShowNoticeAgain; //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); From e35774138f708c783520a4a0d7a5a3237814afe7 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 13:01:18 +0000 Subject: [PATCH 24/70] Added run_at document_start --- manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index b128617a..f87d2d31 100644 --- a/manifest.json +++ b/manifest.json @@ -6,6 +6,7 @@ "description": "__MSG_Description__", "content_scripts": [ { + "run_at": "document_start", "matches": [ "https://*.youtube.com/*", "https://www.youtube-nocookie.com/embed/*" @@ -13,7 +14,7 @@ "all_frames": true, "js": [ "config.js", - "SB.js", + "SB.js", "utils/previewBar.js", "utils/skipNotice.js", "utils.js", From c65e3c21e325b29be689f75ff65bb28554fd2efe Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 13:01:42 +0000 Subject: [PATCH 25/70] fix --- content.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/content.js b/content.js index 86bbe1e7..5f3478db 100644 --- a/content.js +++ b/content.js @@ -70,11 +70,6 @@ var sponsorTimesSubmitting = []; //this is used to close the popup on YouTube when the other popup opens var popupInitialised = false; -//if the notice should not be shown -//happens when the user click's the "Don't show notice again" button -//option renamed when new notice was made -dontShowNoticeAgain = SB.config.dontShowNoticeAgain; - //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); @@ -148,15 +143,16 @@ function messageListener(request, sender, sendResponse) { break; case "dontShowNotice": - dontShowNotice = false; + SB.config.dontShowNotice = true; break; case "changeStartSponsorButton": changeStartSponsorButton(request.showStartSponsor, request.uploadButtonVisible); break; + case "showNoticeAgain": - dontShowNotice = false; + SB.config.dontShowNotice = true; break; case "changeVideoPlayerControlsVisibility": @@ -568,16 +564,14 @@ function skipToTime(v, index, sponsorTimes, openNotice) { if (openNotice) { //send out the message saying that a sponsor message was skipped - if (!dontShowNotice) { + if (!SB.config.dontShowNotice) { let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip); if (dontShowNoticeOld) { //show why this notice is showing skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2")); - //remove this setting - delete SB.config["dontShowNoticeAgain"]; - dontShowNoticeOld = false; + SB.config.dontShowNotice = false; } //auto-upvote this sponsor @@ -918,9 +912,6 @@ function closeAllSkipNotices(){ function dontShowNoticeAgain() { SB.config.dontShowNotice = true; - - dontShowNotice = true; - closeAllSkipNotices(); } From 46c3187c89fd78ee8d67778c7671556ffc36ab7a Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 13:46:09 +0000 Subject: [PATCH 26/70] Update content.js --- content.js | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/content.js b/content.js index 5f3478db..0d93bd84 100644 --- a/content.js +++ b/content.js @@ -58,11 +58,6 @@ var lastSponsorTimeSkippedUUID = null; //if showing the start sponsor button or the end sponsor button on the player var showingStartSponsor = true; -//should the video controls buttons be added -var hideVideoPlayerControls = false; -var hideInfoButtonPlayerControls = false; -var hideDeleteButtonPlayerControls = false; - //the sponsor times being prepared to be submitted var sponsorTimesSubmitting = []; @@ -153,20 +148,20 @@ function messageListener(request, sender, sendResponse) { case "showNoticeAgain": SB.config.dontShowNotice = true; - break; + case "changeVideoPlayerControlsVisibility": - hideVideoPlayerControls = request.value; + SB.config.hideVideoPlayerControls = request.value; updateVisibilityOfPlayerControlsButton(); break; case "changeInfoButtonPlayerControlsVisibility": - hideInfoButtonPlayerControls = request.value; + SB.config.hideInfoButtonPlayerControls = request.value; updateVisibilityOfPlayerControlsButton(); break; case "changeDeleteButtonPlayerControlsVisibility": - hideDeleteButtonPlayerControls = request.value; + SB.config.hideDeleteButtonPlayerControls = request.value; updateVisibilityOfPlayerControlsButton(); break; @@ -297,25 +292,8 @@ function videoIDChange(id) { } }); }); - - //see if video controls buttons should be added - if (SB.config.hideVideoPlayerControls != undefined) { - hideVideoPlayerControls = SB.config.hideVideoPlayerControls; - } - - updateVisibilityOfPlayerControlsButton(); - - if (SB.config.hideInfoButtonPlayerControls != undefined) { - hideInfoButtonPlayerControls = SB.config.hideInfoButtonPlayerControls; - } - - updateVisibilityOfPlayerControlsButton(); - - if (SB.config.hideDeleteButtonPlayerControls != undefined) { - hideDeleteButtonPlayerControls = SB.config.hideDeleteButtonPlayerControls; - } - - updateVisibilityOfPlayerControlsButton(false); + updateVisibilityOfPlayerControlsButton(); + updateVisibilityOfPlayerControlsButton(false); } function sponsorsLookup(id, channelIDPromise) { @@ -665,14 +643,14 @@ async function updateVisibilityOfPlayerControlsButton() { await createButtons(); - if (hideVideoPlayerControls) { + if (SB.config.hideDeleteButtonPlayerControls) { removePlayerControlsButton(); } //don't show the info button on embeds - if (hideInfoButtonPlayerControls || document.URL.includes("/embed/")) { + if (SB.config.hideInfoButtonPlayerControls || document.URL.includes("/embed/")) { document.getElementById("infoButton").style.display = "none"; } - if (hideDeleteButtonPlayerControls) { + if (SB.config.hideDeleteButtonPlayerControls) { document.getElementById("deleteButton").style.display = "none"; } } @@ -724,7 +702,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) { await wait(isSubmitButtonLoaded); //if it isn't visible, there is no data - let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset" : "none" + let shouldHide = (uploadButtonVisible && !SB.config.hideDeleteButtonPlayerControls) ? "unset" : "none" document.getElementById("deleteButton").style.display = shouldHide; if (showStartSponsor) { @@ -732,7 +710,7 @@ async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) { document.getElementById("startSponsorImage").src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker256px.png"); document.getElementById("startSponsorButton").setAttribute("title", chrome.i18n.getMessage("sponsorStart")); - if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !hideInfoButtonPlayerControls) { + if (document.getElementById("startSponsorImage").style.display != "none" && uploadButtonVisible && !SB.config.hideInfoButtonPlayerControls) { document.getElementById("submitButton").style.display = "unset"; } else if (!uploadButtonVisible) { //disable submit button From 4ebdcf1cc555704a23723d7c4233fb6ce870f77d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:04:18 +0000 Subject: [PATCH 27/70] Update content.js --- content.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content.js b/content.js index 0d93bd84..71fee845 100644 --- a/content.js +++ b/content.js @@ -65,6 +65,10 @@ var sponsorTimesSubmitting = []; //this is used to close the popup on YouTube when the other popup opens var popupInitialised = false; +if (SB.config.dontShowNotice) { + SB.config.dontShowNoticeOld = true; +} + //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); From 0241c0a036edaf34ca9e49871539757f3eee8da5 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:04:49 +0000 Subject: [PATCH 28/70] Update SB.js --- SB.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 6cfc470f..c8e8cf6a 100644 --- a/SB.js +++ b/SB.js @@ -40,7 +40,11 @@ SB.defaults = { "disableSkipping": false, "disableAutoSkip": false, "trackViewCount": false, - "dontShowNoticeAgain": false + "dontShowNotice": false, + "hideVideoPlayerControls": false, + "hideInfoButtonPlayerControls": false, + "hideDeleteButtonPlayerControls": false, + "dontShowNoticeOld": false } // Reset config From 6f682baa4547e13ce9c79cfebb64455c600e0a7e Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:30:23 +0000 Subject: [PATCH 29/70] Update content.js --- content.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/content.js b/content.js index 71fee845..888040ba 100644 --- a/content.js +++ b/content.js @@ -65,10 +65,6 @@ var sponsorTimesSubmitting = []; //this is used to close the popup on YouTube when the other popup opens var popupInitialised = false; -if (SB.config.dontShowNotice) { - SB.config.dontShowNoticeOld = true; -} - //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); @@ -77,7 +73,6 @@ function messageListener(request, sender, sendResponse) { switch(request.message){ case "update": videoIDChange(getYouTubeVideoID(document.URL)); - break; case "sponsorStart": sponsorMessageStarted(sendResponse); @@ -549,11 +544,10 @@ function skipToTime(v, index, sponsorTimes, openNotice) { if (!SB.config.dontShowNotice) { let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip); - if (dontShowNoticeOld) { + if (!SB.config.dontShowNoticeOld) { //show why this notice is showing skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2")); - - SB.config.dontShowNotice = false; + SB.config.dontShowNoticeOld = true; } //auto-upvote this sponsor From 039c1a178fb314a2d5ac59582893ad0b64f1e0eb Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:44:39 +0000 Subject: [PATCH 30/70] Update background.js --- background.js | 155 ++++++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 86 deletions(-) diff --git a/background.js b/background.js index f2759f1f..0d1c4696 100644 --- a/background.js +++ b/background.js @@ -19,7 +19,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { case "getSponsorTimes": getSponsorTimes(request.videoID, function(sponsorTimes) { callback({ - sponsorTimes: sponsorTimes + sponsorTimes: sponsorTimes }) }); @@ -43,22 +43,18 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //add help page on install chrome.runtime.onInstalled.addListener(function (object) { setTimeout(function() { - chrome.storage.sync.get(["userID"], function(result) { - const userID = result.userID; + const userID = result.userID; - // If there is no userID, then it is the first install. - if (!userID){ - //open up the install page - chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")}); + // If there is no userID, then it is the first install. + if (!userID){ + //open up the install page + chrome.tabs.create({url: chrome.extension.getURL("/help/index_en.html")}); - //generate a userID - const newUserID = generateUserID(); - //save this UUID - chrome.storage.sync.set({ - "userID": newUserID - }); - } - }); + //generate a userID + const newUserID = generateUserID(); + //save this UUID + SB.config.userID = newUserID; + } }, 1500); }); @@ -66,14 +62,12 @@ chrome.runtime.onInstalled.addListener(function (object) { function getSponsorTimes(videoID, callback) { let sponsorTimes = []; let sponsorTimeKey = "sponsorTimes" + videoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimesStorage = result[sponsorTimeKey]; - if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { - sponsorTimes = sponsorTimesStorage; - } - - callback(sponsorTimes) - }); + let sponsorTimesStorage = SB.config.sponsorTimeKey[sponsorTimeKey]; + + if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { + sponsorTimes = sponsorTimesStorage; + } + callback(sponsorTimes); } function addSponsorTime(time, videoID, callback) { @@ -92,7 +86,8 @@ function addSponsorTime(time, videoID, callback) { //save this info let sponsorTimeKey = "sponsorTimes" + videoID; - chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}, callback); + SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + callback(); }); } @@ -103,9 +98,7 @@ function submitVote(type, UUID, callback) { if (userID == undefined || userID === "undefined") { //generate one userID = generateUserID(); - chrome.storage.sync.set({ - "userID": userID - }); + SB.config.userID = userID; } //publish this vote @@ -134,68 +127,58 @@ function submitVote(type, UUID, callback) { function submitTimes(videoID, callback) { //get the video times from storage let sponsorTimeKey = 'sponsorTimes' + videoID; - chrome.storage.sync.get([sponsorTimeKey, "userID"], async function(result) { - let sponsorTimes = result[sponsorTimeKey]; - let userID = result.userID; - - if (sponsorTimes != undefined && sponsorTimes.length > 0) { - let durationResult = await new Promise((resolve, reject) => { - chrome.tabs.query({ - active: true, - currentWindow: true - }, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, { - message: "getVideoDuration" - }, (response) => resolve(response)); - }); + let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; + let userID = SB.config.userID; + + if (sponsorTimes != undefined && sponsorTimes.length > 0) { + let durationResult = await new Promise((resolve, reject) => { + chrome.tabs.query({ + active: true, + currentWindow: true + }, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, { + message: "getVideoDuration" + }, (response) => resolve(response)); }); + }); - //check if a sponsor exceeds the duration of the video - for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i][1] > durationResult.duration) { - sponsorTimes[i][1] = durationResult.duration; - } - } - - //submit these times - for (let i = 0; i < sponsorTimes.length; i++) { - //to prevent it from happeneing twice - let increasedContributionAmount = false; - - //submit the sponsorTime - sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] - + "&userID=" + userID, function(xmlhttp, error) { - if (xmlhttp.readyState == 4 && !error) { - callback({ - statusCode: xmlhttp.status - }); - - if (xmlhttp.status == 200) { - //add these to the storage log - chrome.storage.sync.get(["sponsorTimesContributed"], function(result) { - let currentContributionAmount = 0; - if (result.sponsorTimesContributed != undefined) { - //current contribution amount is known - currentContributionAmount = result.sponsorTimesContributed; - } - - //save the amount contributed - if (!increasedContributionAmount) { - increasedContributionAmount = true; - - chrome.storage.sync.set({"sponsorTimesContributed": currentContributionAmount + sponsorTimes.length}); - } - }); - } - } else if (error) { - callback({ - statusCode: -1 - }); - } - }); + //check if a sponsor exceeds the duration of the video + for (let i = 0; i < sponsorTimes.length; i++) { + if (sponsorTimes[i][1] > durationResult.duration) { + sponsorTimes[i][1] = durationResult.duration; } } - }); + + //submit these times + for (let i = 0; i < sponsorTimes.length; i++) { + //to prevent it from happeneing twice + let increasedContributionAmount = false; + + //submit the sponsorTime + sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1] + + "&userID=" + userID, function(xmlhttp, error) { + if (xmlhttp.readyState == 4 && !error) { + callback({ + statusCode: xmlhttp.status + }); + + if (xmlhttp.status == 200) { + //add these to the storage log + currentContributionAmount = SB.config.sponsorTimesContributed; + //save the amount contributed + if (!increasedContributionAmount) { + increasedContributionAmount = true; + SB.config.sponsorTimesContributed = currentContributionAmount + sponsorTimes.length; + } + } + } else if (error) { + callback({ + statusCode: -1 + }); + } + }); + } + } } function sendRequestToServer(type, address, callback) { @@ -215,4 +198,4 @@ function sendRequestToServer(type, address, callback) { //submit this request xmlhttp.send(); -} \ No newline at end of file +} From e02ca1c8226911c3b450af950db6180793fb73c7 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:45:22 +0000 Subject: [PATCH 31/70] Update SB.js --- SB.js | 1 + 1 file changed, 1 insertion(+) diff --git a/SB.js b/SB.js index c8e8cf6a..e730b75d 100644 --- a/SB.js +++ b/SB.js @@ -37,6 +37,7 @@ SB.defaults = { "submitKeybind": "'", "minutesSaved": 0, "skipCount": 0, + "sponsorTimesContributed": 0, "disableSkipping": false, "disableAutoSkip": false, "trackViewCount": false, From 0533919bdec8ec652bcc62c29afbed86fe3bbda2 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:45:34 +0000 Subject: [PATCH 32/70] Update SB.js --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index e730b75d..c5f8ad01 100644 --- a/SB.js +++ b/SB.js @@ -28,7 +28,7 @@ fetchConfig = _ => new Promise(function(resolve, reject) { async function config() { await fetchConfig(); - addDefaults(); + addDefaults(); SB.config = configProxy(); } From 6c4d5c07055572d7a5e91b605a9141452e8d6bc2 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:47:41 +0000 Subject: [PATCH 33/70] submitTimes async --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 0d1c4696..8e45f5ac 100644 --- a/background.js +++ b/background.js @@ -124,7 +124,7 @@ function submitVote(type, UUID, callback) { }) } -function submitTimes(videoID, callback) { +async function submitTimes(videoID, callback) { //get the video times from storage let sponsorTimeKey = 'sponsorTimes' + videoID; let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; From 1d2b6b2010d10822a39e9275c7ff607b9d2da9d6 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 14:50:05 +0000 Subject: [PATCH 34/70] userID --- background.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index 8e45f5ac..b9aa7670 100644 --- a/background.js +++ b/background.js @@ -43,7 +43,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //add help page on install chrome.runtime.onInstalled.addListener(function (object) { setTimeout(function() { - const userID = result.userID; + const userID = SB.config.userID; // If there is no userID, then it is the first install. if (!userID){ @@ -92,8 +92,7 @@ function addSponsorTime(time, videoID, callback) { } function submitVote(type, UUID, callback) { - chrome.storage.sync.get(["userID"], function(result) { - let userID = result.userID; + let userID = SB.config.userID; if (userID == undefined || userID === "undefined") { //generate one @@ -121,7 +120,6 @@ function submitVote(type, UUID, callback) { }); } }) - }) } async function submitTimes(videoID, callback) { From ecd9f6eaffd10d97886d735f59117a548a61972d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 15:09:13 +0000 Subject: [PATCH 35/70] Update content.js --- content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content.js b/content.js index 888040ba..df98cda4 100644 --- a/content.js +++ b/content.js @@ -813,7 +813,7 @@ function clearSponsorTimes() { //clear the sponsor times let sponsorTimeKey = "sponsorTimes" + currentVideoID; - SB.config.sponsorTimeKey = []; + delete SB.config.sponsorTimeKey[sponsorTimeKey] //clear sponsor times submitting sponsorTimesSubmitting = []; @@ -971,7 +971,7 @@ function sendSubmitMessage(){ //clear the sponsor times let sponsorTimeKey = "sponsorTimes" + currentVideoID; - SB.config.sponsorTimeKey[sponsorTimeKey] = []; + delete SB.config.sponsorTimeKey[sponsorTimeKey]; //add submissions to current sponsors list sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); From 278e40207c377ed9f1140b233b8482787e137220 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 18:00:47 +0000 Subject: [PATCH 36/70] Create empty array for sponsorTimeKey --- SB.js | 1 + 1 file changed, 1 insertion(+) diff --git a/SB.js b/SB.js index c5f8ad01..dfd62503 100644 --- a/SB.js +++ b/SB.js @@ -33,6 +33,7 @@ async function config() { } SB.defaults = { + "sponsorTimeKey": []; "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, From 10057830341f90cb9c22f2d3154f5d0f24f3bf26 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 18:02:16 +0000 Subject: [PATCH 37/70] Update SB.js --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index dfd62503..8fb06d59 100644 --- a/SB.js +++ b/SB.js @@ -33,7 +33,7 @@ async function config() { } SB.defaults = { - "sponsorTimeKey": []; + "sponsorTimeKey": [], "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, From a3f5200c9a81e3c63f43a4338a44ad299926cbbb Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:10:34 +0000 Subject: [PATCH 38/70] Map test --- content.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/content.js b/content.js index df98cda4..c5979307 100644 --- a/content.js +++ b/content.js @@ -238,8 +238,7 @@ function videoIDChange(id) { //warn them if they had unsubmitted times if (previousVideoID != null) { //get the sponsor times from storage - let sponsorTimeKey = 'sponsorTimes' + previousVideoID; - let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimes.get(previousVideoID); if (sponsorTimes != undefined && sponsorTimes.length > 0) { //warn them that they have unsubmitted sponsor times chrome.runtime.sendMessage({ @@ -803,8 +802,7 @@ function clearSponsorTimes() { let currentVideoID = sponsorVideoID; - let sponsorTimeKey = 'sponsorTimes' + currentVideoID; - let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID); if (sponsorTimes != undefined && sponsorTimes.length > 0) { let confirmMessage = chrome.i18n.getMessage("clearThis") + getSponsorTimesMessage(sponsorTimes); @@ -812,8 +810,7 @@ function clearSponsorTimes() { if(!confirm(confirmMessage)) return; //clear the sponsor times - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - delete SB.config.sponsorTimeKey[sponsorTimeKey] + SB.config.sponsorTimes.delete(currentVideoID); //clear sponsor times submitting sponsorTimesSubmitting = []; @@ -914,8 +911,7 @@ function submitSponsorTimes() { let currentVideoID = sponsorVideoID; - let sponsorTimeKey = 'sponsorTimes' + currentVideoID; - let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID); if (sponsorTimes != undefined && sponsorTimes.length > 0) { //check if a sponsor exceeds the duration of the video @@ -925,7 +921,7 @@ function submitSponsorTimes() { } } //update sponsorTimes - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); //update sponsorTimesSubmitting sponsorTimesSubmitting = sponsorTimes; @@ -970,8 +966,7 @@ function sendSubmitMessage(){ submitButton.addEventListener("animationend", animationEndListener); //clear the sponsor times - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - delete SB.config.sponsorTimeKey[sponsorTimeKey]; + SB.config.sponsorTimes.delete(currentVideoID); //add submissions to current sponsors list sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting); From a70aa7723e2a5938ffef11aaf27b3d6a3a8569a1 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:11:17 +0000 Subject: [PATCH 39/70] Map test --- background.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index b9aa7670..406db770 100644 --- a/background.js +++ b/background.js @@ -15,7 +15,8 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { addSponsorTime(request.time, request.videoID, callback); //this allows the callback to be called later - return true; + return true; + case "getSponsorTimes": getSponsorTimes(request.videoID, function(sponsorTimes) { callback({ @@ -61,12 +62,12 @@ chrome.runtime.onInstalled.addListener(function (object) { //gets the sponsor times from memory function getSponsorTimes(videoID, callback) { let sponsorTimes = []; - let sponsorTimeKey = "sponsorTimes" + videoID; - let sponsorTimesStorage = SB.config.sponsorTimeKey[sponsorTimeKey]; - + let sponsorTimesStorage = SB.config.sponsorTimes.get(videoID); + if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { sponsorTimes = sponsorTimesStorage; } + callback(sponsorTimes); } @@ -85,8 +86,7 @@ function addSponsorTime(time, videoID, callback) { } //save this info - let sponsorTimeKey = "sponsorTimes" + videoID; - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + SB.config.sponsorTimes.set(videoID, sponsorTimes); callback(); }); } @@ -124,8 +124,7 @@ function submitVote(type, UUID, callback) { async function submitTimes(videoID, callback) { //get the video times from storage - let sponsorTimeKey = 'sponsorTimes' + videoID; - let sponsorTimes = SB.config.sponsorTimeKey[sponsorTimeKey]; + let sponsorTimes = SB.config.sponsorTimes.get(videoID); let userID = SB.config.userID; if (sponsorTimes != undefined && sponsorTimes.length > 0) { From 1362331a9367b7ad0bebf81d4d133fc6d3c56adf Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:12:15 +0000 Subject: [PATCH 40/70] Map test --- SB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SB.js b/SB.js index 8fb06d59..62fe058f 100644 --- a/SB.js +++ b/SB.js @@ -28,12 +28,12 @@ fetchConfig = _ => new Promise(function(resolve, reject) { async function config() { await fetchConfig(); - addDefaults(); + addDefaults(); SB.config = configProxy(); } SB.defaults = { - "sponsorTimeKey": [], + "sponsorTimes": new Map(), "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, From 2a4abf958d46efd2fcfd1261c510dce19327559b Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:20:14 +0000 Subject: [PATCH 41/70] Map test --- popup.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/popup.js b/popup.js index 0e01caa6..f07050bd 100644 --- a/popup.js +++ b/popup.js @@ -229,8 +229,7 @@ async function runThePopup() { } //load video times for this video - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - let sponsorTimesStorage = SB.config.sponsorTimeKey[sponsorTimeKey]; + let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID); if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) { startTimeChosen = true; @@ -324,10 +323,9 @@ async function runThePopup() { } sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time; - - let sponsorTimeKey = "sponsorTimes" + currentVideoID; + let localStartTimeChosen = startTimeChosen; - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); //send a message to the client script if (localStartTimeChosen) { chrome.tabs.query({ @@ -659,8 +657,7 @@ async function runThePopup() { sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index); //save this - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); chrome.tabs.query({ active: true, currentWindow: true @@ -699,8 +696,7 @@ async function runThePopup() { sponsorTimes.splice(index, 1); //save this - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); chrome.tabs.query({ active: true, currentWindow: true @@ -750,9 +746,8 @@ async function runThePopup() { //reset sponsorTimes sponsorTimes = []; - - let sponsorTimeKey = "sponsorTimes" + currentVideoID; - SB.config.sponsorTimeKey[sponsorTimeKey] = sponsorTimes; + + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); chrome.tabs.query({ active: true, currentWindow: true From bdae68be35aa5305dc84e349132245fdfb6de8db Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 18:56:37 +0000 Subject: [PATCH 42/70] () => --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 62fe058f..9d7ee95b 100644 --- a/SB.js +++ b/SB.js @@ -19,7 +19,7 @@ function configProxy() { return new Proxy({}, handler); } -fetchConfig = _ => new Promise(function(resolve, reject) { +fetchConfig = () => new Promise((resolve, reject) => { chrome.storage.sync.get(null, function(items) { SB.localconfig = items; // Data is ready resolve(); From 92f10d51aa530ebabc7ec31a6ffaa08903fcad99 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 18:58:47 +0000 Subject: [PATCH 43/70] Removed SB.config.dontShowNoticeOld --- content.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/content.js b/content.js index c5979307..b4575ca4 100644 --- a/content.js +++ b/content.js @@ -542,13 +542,6 @@ function skipToTime(v, index, sponsorTimes, openNotice) { //send out the message saying that a sponsor message was skipped if (!SB.config.dontShowNotice) { let skipNotice = new SkipNotice(this, currentUUID, SB.config.disableAutoSkip); - - if (!SB.config.dontShowNoticeOld) { - //show why this notice is showing - skipNotice.addNoticeInfoMessage(chrome.i18n.getMessage("noticeUpdate"), chrome.i18n.getMessage("noticeUpdate2")); - SB.config.dontShowNoticeOld = true; - } - //auto-upvote this sponsor if (SB.config.trackViewCount && !SB.config.disableAutoSkip) { vote(1, currentUUID, null); From f1c68a98cf1df932a3faddc63fc6996a3cc195e4 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 18:59:38 +0000 Subject: [PATCH 44/70] removed SB.config.dontShowNoticeOld --- SB.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SB.js b/SB.js index 9d7ee95b..da91cea3 100644 --- a/SB.js +++ b/SB.js @@ -28,7 +28,7 @@ fetchConfig = () => new Promise((resolve, reject) => { async function config() { await fetchConfig(); - addDefaults(); + addDefaults(); SB.config = configProxy(); } @@ -45,8 +45,7 @@ SB.defaults = { "dontShowNotice": false, "hideVideoPlayerControls": false, "hideInfoButtonPlayerControls": false, - "hideDeleteButtonPlayerControls": false, - "dontShowNoticeOld": false + "hideDeleteButtonPlayerControls": false } // Reset config From 3627661e1f5013a6a753950ab116e27deba7daf1 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:11:37 +0000 Subject: [PATCH 45/70] Backwards compatibility --- SB.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SB.js b/SB.js index da91cea3..aed6ad91 100644 --- a/SB.js +++ b/SB.js @@ -26,9 +26,19 @@ fetchConfig = () => new Promise((resolve, reject) => { }); }); +function migrate() { // Convert sponsorTimes format + for (key in SB.localconfig) { + if (key.startsWith("sponsortime")) { + SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); + delete SB.config[key]; + } + } +} + async function config() { await fetchConfig(); addDefaults(); + migrate(); SB.config = configProxy(); } From c99f7925eb34058a9c75abbbd35167952e6bf150 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 6 Jan 2020 16:13:50 -0500 Subject: [PATCH 46/70] Fixed migrate --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index aed6ad91..b2d5df30 100644 --- a/SB.js +++ b/SB.js @@ -28,7 +28,7 @@ fetchConfig = () => new Promise((resolve, reject) => { function migrate() { // Convert sponsorTimes format for (key in SB.localconfig) { - if (key.startsWith("sponsortime")) { + if (key.startsWith("sponsorTimes")) { SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); delete SB.config[key]; } From d8ae73e96afd6089c04151a093f57d3c9e559467 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:14:31 +0000 Subject: [PATCH 47/70] Update SB.js --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index b2d5df30..d74489db 100644 --- a/SB.js +++ b/SB.js @@ -29,7 +29,7 @@ fetchConfig = () => new Promise((resolve, reject) => { function migrate() { // Convert sponsorTimes format for (key in SB.localconfig) { if (key.startsWith("sponsorTimes")) { - SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); + SB.config.sponsorTimes.set(key.substr(11), SB.config[key]); delete SB.config[key]; } } From 0b9def800ba0cbbc55f1a57b904dc22177917545 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:17:28 +0000 Subject: [PATCH 48/70] Update SB.js --- SB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SB.js b/SB.js index d74489db..a82dc07a 100644 --- a/SB.js +++ b/SB.js @@ -28,8 +28,8 @@ fetchConfig = () => new Promise((resolve, reject) => { function migrate() { // Convert sponsorTimes format for (key in SB.localconfig) { - if (key.startsWith("sponsorTimes")) { - SB.config.sponsorTimes.set(key.substr(11), SB.config[key]); + if (key.startsWith("sponsorTimes") && key !== "sponsorTimes")) { + SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); delete SB.config[key]; } } From c20b67d11f0f1d3695647947942155f77330fe17 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:20:22 +0000 Subject: [PATCH 49/70] Fixed syntax --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index a82dc07a..c1085db0 100644 --- a/SB.js +++ b/SB.js @@ -28,7 +28,7 @@ fetchConfig = () => new Promise((resolve, reject) => { function migrate() { // Convert sponsorTimes format for (key in SB.localconfig) { - if (key.startsWith("sponsorTimes") && key !== "sponsorTimes")) { + if (key.startsWith("sponsorTimes") && key !== "sponsorTimes") { SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); delete SB.config[key]; } From a7dc207c5ffc14f0c55f24e55fb41d9c1ca44d92 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 23:12:48 +0000 Subject: [PATCH 50/70] Fix format conflict --- SB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SB.js b/SB.js index c1085db0..adeb48d0 100644 --- a/SB.js +++ b/SB.js @@ -28,7 +28,7 @@ fetchConfig = () => new Promise((resolve, reject) => { function migrate() { // Convert sponsorTimes format for (key in SB.localconfig) { - if (key.startsWith("sponsorTimes") && key !== "sponsorTimes") { + if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") { SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); delete SB.config[key]; } @@ -38,8 +38,8 @@ function migrate() { // Convert sponsorTimes format async function config() { await fetchConfig(); addDefaults(); - migrate(); SB.config = configProxy(); + migrate(); } SB.defaults = { From cbd451949ba48504360e1b0a0dc09badfff6ba7c Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 23:27:07 +0000 Subject: [PATCH 51/70] Added hideDiscordLink, hideDiscordLink --- SB.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SB.js b/SB.js index adeb48d0..38d0bd38 100644 --- a/SB.js +++ b/SB.js @@ -56,6 +56,8 @@ SB.defaults = { "hideVideoPlayerControls": false, "hideInfoButtonPlayerControls": false, "hideDeleteButtonPlayerControls": false + "hideDiscordLaunches": 0, + "hideDiscordLink": false } // Reset config From 601ff441452347f34e1e1691465714153522938b Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 23:29:04 +0000 Subject: [PATCH 52/70] Forgot comma --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 38d0bd38..7f9a8fec 100644 --- a/SB.js +++ b/SB.js @@ -55,7 +55,7 @@ SB.defaults = { "dontShowNotice": false, "hideVideoPlayerControls": false, "hideInfoButtonPlayerControls": false, - "hideDeleteButtonPlayerControls": false + "hideDeleteButtonPlayerControls": false, "hideDiscordLaunches": 0, "hideDiscordLink": false } From 47d9d93818ee3144b138daba9e7359bd100063ba Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 23:34:33 +0000 Subject: [PATCH 53/70] Added SB.js to options html --- options/options.html | 1 + 1 file changed, 1 insertion(+) diff --git a/options/options.html b/options/options.html index 45983d58..2e01e997 100644 --- a/options/options.html +++ b/options/options.html @@ -4,6 +4,7 @@ + From d15785146f211e33e0f4520514a097da7997f219 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 6 Jan 2020 23:42:02 +0000 Subject: [PATCH 54/70] Update options.js --- options/options.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/options/options.js b/options/options.js index d1fef77b..0b3c3dce 100644 --- a/options/options.js +++ b/options/options.js @@ -27,7 +27,7 @@ async function init() { } checkbox.addEventListener("click", () =>{ - setOptionValue(option, reverse ? !checkbox.checked : checkbox.checked) + SB.config[option] = reverse ? !checkbox.checked : checkbox.checked; }); } @@ -123,23 +123,11 @@ function activateTextChange(element) { let textBox = element.querySelector(".option-text-box"); let option = element.getAttribute("sync-option"); + + textBox.value = SB.config[option]; - chrome.storage.sync.get([option], function(result) { - textBox.value = result[option]; + let setButton = element.querySelector(".text-change-set"); +setButton.addEventListener("click", () => {SB.config[option] = textBox.value}); - let setButton = element.querySelector(".text-change-set"); - setButton.addEventListener("click", () => setOptionValue(option, textBox.value)); - - element.querySelector(".option-hidden-section").classList.remove("hidden"); - }); + element.querySelector(".option-hidden-section").classList.remove("hidden"); } - -/** - * Called when an option has been changed. - * - * @param {string} option - * @param {*} value - */ -function setOptionValue(option, value) { - chrome.storage.sync.set({[option]: value}); -} \ No newline at end of file From b8ebe5076b92fd2e6d785510a1f44ea15a61d197 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 7 Jan 2020 21:23:59 -0500 Subject: [PATCH 55/70] Fixed indentation. --- options/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/options.js b/options/options.js index 0b3c3dce..a87d150f 100644 --- a/options/options.js +++ b/options/options.js @@ -127,7 +127,7 @@ function activateTextChange(element) { textBox.value = SB.config[option]; let setButton = element.querySelector(".text-change-set"); -setButton.addEventListener("click", () => {SB.config[option] = textBox.value}); + setButton.addEventListener("click", () => {SB.config[option] = textBox.value}); element.querySelector(".option-hidden-section").classList.remove("hidden"); } From da8a1376a782aec9344fb6b6b6679b4f6c619e04 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 7 Jan 2020 22:02:16 -0500 Subject: [PATCH 56/70] Converted options page to new config system. --- options/options.js | 61 ++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/options/options.js b/options/options.js index a87d150f..14ed32ad 100644 --- a/options/options.js +++ b/options/options.js @@ -3,38 +3,33 @@ window.addEventListener('DOMContentLoaded', init); async function init() { localizeHtmlPage(); + await wait(() => SB.config !== undefined); + // Set all of the toggle options to the correct option let optionsContainer = document.getElementById("options"); let optionsElements = optionsContainer.children; - // How many checks are left to be done - let checksLeft = 0; - for (let i = 0; i < optionsElements.length; i++) { switch (optionsElements[i].getAttribute("option-type")) { case "toggle": let option = optionsElements[i].getAttribute("sync-option"); - chrome.storage.sync.get([option], function(result) { - let optionResult = result[option]; - if (optionResult != undefined) { - let checkbox = optionsElements[i].querySelector("input"); - checkbox.checked = optionResult; - let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse"; + let optionResult = SB.config[option]; - if (reverse) { - optionsElements[i].querySelector("input").checked = !optionResult; - } + let checkbox = optionsElements[i].querySelector("input"); + let reverse = optionsElements[i].getAttribute("toggle-type") === "reverse"; - checkbox.addEventListener("click", () =>{ - SB.config[option] = reverse ? !checkbox.checked : checkbox.checked; - }); + if (optionResult != undefined) { + checkbox.checked = optionResult; + + if (reverse) { + optionsElements[i].querySelector("input").checked = !optionResult; } + } - checksLeft--; + checkbox.addEventListener("click", () =>{ + SB.config[option] = reverse ? !checkbox.checked : checkbox.checked; }); - - checksLeft++; break; case "text-change": let button = optionsElements[i].querySelector(".trigger-button"); @@ -49,8 +44,6 @@ async function init() { } } - await wait(() => checksLeft == 0, 1000, 50); - optionsContainer.classList.remove("hidden"); optionsContainer.classList.add("animated"); } @@ -68,21 +61,19 @@ function activateKeybindChange(element) { let option = element.getAttribute("sync-option"); - chrome.storage.sync.get([option], function(result) { - let currentlySet = result[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : ""; - - let status = element.querySelector(".option-hidden-section > .keybind-status"); - status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet; - - if (result[option] !== null) { - let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key"); - statusKey.innerText = result[option]; - } + let currentlySet = SB.config[option] !== null ? chrome.i18n.getMessage("keybindCurrentlySet") : ""; - element.querySelector(".option-hidden-section").classList.remove("hidden"); - - document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true}); - }); + let status = element.querySelector(".option-hidden-section > .keybind-status"); + status.innerText = chrome.i18n.getMessage("keybindDescription") + currentlySet; + + if (SB.config[option] !== null) { + let statusKey = element.querySelector(".option-hidden-section > .keybind-status-key"); + statusKey.innerText = SB.config[option]; + } + + element.querySelector(".option-hidden-section").classList.remove("hidden"); + + document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true}); } /** @@ -97,7 +88,7 @@ function keybindKeyPressed(element, e) { let option = element.getAttribute("sync-option"); - chrome.storage.sync.set({[option]: key}); + SB.config[option] = key; let status = element.querySelector(".option-hidden-section > .keybind-status"); status.innerText = chrome.i18n.getMessage("keybindDescriptionComplete"); From eb4bf89194ff08766088c26b5b445c563772d853 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 7 Jan 2020 22:12:53 -0500 Subject: [PATCH 57/70] Fixed default --- SB.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 7f9a8fec..66da94d4 100644 --- a/SB.js +++ b/SB.js @@ -51,7 +51,7 @@ SB.defaults = { "sponsorTimesContributed": 0, "disableSkipping": false, "disableAutoSkip": false, - "trackViewCount": false, + "trackViewCount": true, "dontShowNotice": false, "hideVideoPlayerControls": false, "hideInfoButtonPlayerControls": false, From fa19e435cc0f9997e15e213717cdf108610db27f Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 7 Jan 2020 22:59:50 -0500 Subject: [PATCH 58/70] Switched to a listener map. --- SB.js | 61 ++++++++++++++- background.js | 4 +- content.js | 56 +++++++------- popup.js | 206 +++++++++++++++++++++++++------------------------- 4 files changed, 193 insertions(+), 134 deletions(-) diff --git a/SB.js b/SB.js index 66da94d4..a52f45d6 100644 --- a/SB.js +++ b/SB.js @@ -1,21 +1,69 @@ SB = {}; +class ListenerMap extends Map { + constructor(name) { + super(); + + this.name = name; + } + + set(key, value) { + super.set(key, value); + + this.updateListener(this.name, this); + } + + delete(key) { + this.updateListener(this.name, this); + + return super.set(key); + } + + clear() { + return super.clear(); + } + + forEach(callbackfn) { + return super.forEach(callbackfn); + } + + get(key) { + return super.get(key); + } + + has(key) { + return super.has(key); + } +} + +function mapHandler(name, object) { + SB.config[name] = SB.config[name]; + // chrome.storage.sync.set({ + // [name]: object + // }); + + // console.log(name) + // console.log(object) +} + function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { SB.localconfig[key] = changes[key].newValue; } }); + var handler = { set: function(obj, prop, value) { chrome.storage.sync.set({ [prop]: value - }) + }); }, get: function(obj, prop) { - return SB.localconfig[prop] + return SB.localconfig[prop]; } }; + return new Proxy({}, handler); } @@ -38,12 +86,17 @@ function migrate() { // Convert sponsorTimes format async function config() { await fetchConfig(); addDefaults(); + // Setup sponsorTime listener + SB.localconfig.sponsorTimes.updateListener = mapHandler; + SB.config = configProxy(); - migrate(); + migrate(); + + } SB.defaults = { - "sponsorTimes": new Map(), + "sponsorTimes": new ListenerMap("sponsorTimes"), "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, diff --git a/background.js b/background.js index 406db770..409e59af 100644 --- a/background.js +++ b/background.js @@ -4,7 +4,9 @@ chrome.tabs.onUpdated.addListener(function(tabId) { }, () => void chrome.runtime.lastError ); // Suppress error on Firefox }); -chrome.runtime.onMessage.addListener(function (request, sender, callback) { +chrome.runtime.onMessage.addListener(async function (request, sender, callback) { + await wait(() => SB.config !== undefined); + switch(request.message) { case "submitTimes": submitTimes(request.videoID, callback); diff --git a/content.js b/content.js index b4575ca4..175bcb6c 100644 --- a/content.js +++ b/content.js @@ -238,17 +238,17 @@ function videoIDChange(id) { //warn them if they had unsubmitted times if (previousVideoID != null) { //get the sponsor times from storage - let sponsorTimes = SB.config.sponsorTimes.get(previousVideoID); - if (sponsorTimes != undefined && sponsorTimes.length > 0) { - //warn them that they have unsubmitted sponsor times - chrome.runtime.sendMessage({ - message: "alertPrevious", - previousVideoID: previousVideoID - }) - } + let sponsorTimes = SB.config.sponsorTimes.get(previousVideoID); + if (sponsorTimes != undefined && sponsorTimes.length > 0) { + //warn them that they have unsubmitted sponsor times + chrome.runtime.sendMessage({ + message: "alertPrevious", + previousVideoID: previousVideoID + }) + } - //set the previous video id to the currentID - previousVideoID = id; + //set the previous video id to the currentID + previousVideoID = id; } else { //set the previous id now, don't wait for chrome.storage.get previousVideoID = id; @@ -904,27 +904,27 @@ function submitSponsorTimes() { let currentVideoID = sponsorVideoID; - let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID); + let sponsorTimes = SB.config.sponsorTimes.get(currentVideoID); - if (sponsorTimes != undefined && sponsorTimes.length > 0) { - //check if a sponsor exceeds the duration of the video - for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i][1] > v.duration) { - sponsorTimes[i][1] = v.duration; - } + if (sponsorTimes != undefined && sponsorTimes.length > 0) { + //check if a sponsor exceeds the duration of the video + for (let i = 0; i < sponsorTimes.length; i++) { + if (sponsorTimes[i][1] > v.duration) { + sponsorTimes[i][1] = v.duration; } - //update sponsorTimes - SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); - - //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(); } + //update sponsorTimes + SB.config.sponsorTimes.set(currentVideoID, sponsorTimes); + + //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(); + } } diff --git a/popup.js b/popup.js index f07050bd..19408027 100644 --- a/popup.js +++ b/popup.js @@ -21,6 +21,8 @@ async function runThePopup() { inPopup = false; } + await wait(() => SB.config !== undefined); + ["sponsorStart", // Top toggles "whitelistChannel", @@ -102,107 +104,107 @@ async function runThePopup() { let currentVideoID = null; //see if discord link can be shown - let hideDiscordLink = SB.config.hideDiscordLink; - if (hideDiscordLink == undefined || !hideDiscordLink) { - let hideDiscordLaunches = SB.config.hideDiscordLaunches; - //only if less than 10 launches - if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) { - SB.discordButtonContainer.style.display = null; - - if (hideDiscordLaunches == undefined) { - hideDiscordLaunches = 1; - } - SB.config.hideDiscordLaunches = hideDiscordLaunches + 1; + let hideDiscordLink = SB.config.hideDiscordLink; + if (hideDiscordLink == undefined || !hideDiscordLink) { + let hideDiscordLaunches = SB.config.hideDiscordLaunches; + //only if less than 10 launches + if (hideDiscordLaunches == undefined || hideDiscordLaunches < 10) { + SB.discordButtonContainer.style.display = null; + + if (hideDiscordLaunches == undefined) { + hideDiscordLaunches = 1; } - } + SB.config.hideDiscordLaunches = hideDiscordLaunches + 1; + } + } //show proper disable skipping button - let disableSkipping = SB.config.disableSkipping; - if (disableSkipping != undefined && disableSkipping) { - SB.disableSkipping.style.display = "none"; - SB.enableSkipping.style.display = "unset"; - } + let disableSkipping = SB.config.disableSkipping; + if (disableSkipping != undefined && disableSkipping) { + SB.disableSkipping.style.display = "none"; + SB.enableSkipping.style.display = "unset"; + } //if the don't show notice again variable is true, an option to // disable should be available - let dontShowNotice = SB.config.dontShowNotice; - if (dontShowNotice != undefined && dontShowNotice) { - SB.showNoticeAgain.style.display = "unset"; - } + let dontShowNotice = SB.config.dontShowNotice; + if (dontShowNotice != undefined && dontShowNotice) { + SB.showNoticeAgain.style.display = "unset"; + } //get the amount of times this user has contributed and display it to thank them - if (SB.config.sponsorTimesContributed != undefined) { - if (SB.config.sponsorTimesContributed > 1) { - SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors"); - } else { - SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor"); - } - SB.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed; - SB.sponsorTimesContributionsContainer.style.display = "unset"; - - //get the userID - let userID = SB.config.userID; - if (userID != undefined) { - //there are probably some views on these submissions then - //get the amount of views from the sponsors submitted - sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - let viewCount = JSON.parse(xmlhttp.responseText).viewCount; - if (viewCount != 0) { - if (viewCount > 1) { - SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments"); - } else { - SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment"); - } - - SB.sponsorTimesViewsDisplay.innerText = viewCount; - SB.sponsorTimesViewsContainer.style.display = "unset"; - } - } - }); - - //get this time in minutes - sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) { - if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved; - if (minutesSaved != 0) { - if (minutesSaved != 1) { - SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); - } else { - SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); - } - - SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); - SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset"; - } - } - }); - } + if (SB.config.sponsorTimesContributed != undefined) { + if (SB.config.sponsorTimesContributed > 1) { + SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsors"); + } else { + SB.sponsorTimesContributionsDisplayEndWord.innerText = chrome.i18n.getMessage("Sponsor"); } + SB.sponsorTimesContributionsDisplay.innerText = SB.config.sponsorTimesContributed; + SB.sponsorTimesContributionsContainer.style.display = "unset"; + + //get the userID + let userID = SB.config.userID; + if (userID != undefined) { + //there are probably some views on these submissions then + //get the amount of views from the sponsors submitted + sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + let viewCount = JSON.parse(xmlhttp.responseText).viewCount; + if (viewCount != 0) { + if (viewCount > 1) { + SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segments"); + } else { + SB.sponsorTimesViewsDisplayEndWord.innerText = chrome.i18n.getMessage("Segment"); + } + + SB.sponsorTimesViewsDisplay.innerText = viewCount; + SB.sponsorTimesViewsContainer.style.display = "unset"; + } + } + }); + + //get this time in minutes + sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved; + if (minutesSaved != 0) { + if (minutesSaved != 1) { + SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); + } else { + SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); + } + + SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); + SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset"; + } + } + }); + } + } //get the amount of times this user has skipped a sponsor - if (SB.config.skipCount != undefined) { - if (SB.config.skipCount != 1) { - SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors"); - } else { - SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor"); - } - - SB.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount; - SB.sponsorTimesSkipsDoneContainer.style.display = "unset"; + if (SB.config.skipCount != undefined) { + if (SB.config.skipCount != 1) { + SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors"); + } else { + SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor"); } + SB.sponsorTimesSkipsDoneDisplay.innerText = SB.config.skipCount; + SB.sponsorTimesSkipsDoneContainer.style.display = "unset"; + } + //get the amount of time this user has saved. - if (SB.config.minutesSaved != undefined) { - if (SB.config.minutesSaved != 1) { - SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); - } else { - SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); - } - - SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(SB.config.minutesSaved); - SB.sponsorTimeSavedContainer.style.display = "unset"; + if (SB.config.minutesSaved != undefined) { + if (SB.config.minutesSaved != 1) { + SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); + } else { + SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); } + + SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(SB.config.minutesSaved); + SB.sponsorTimeSavedContainer.style.display = "unset"; + } chrome.tabs.query({ active: true, @@ -229,22 +231,24 @@ async function runThePopup() { } //load video times for this video - let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID); - if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { - if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) { - startTimeChosen = true; - SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd"); - } - - sponsorTimes = sponsorTimesStorage; - - displaySponsorTimes(); - - //show submission section - SB.submissionSection.style.display = "unset"; - - showSubmitTimesIfNecessary(); + console.log( SB.config.sponsorTimes.set) + setTimeout(()=> console.log( SB.config.sponsorTimes.set), 200 ) + let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID); + if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { + if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) { + startTimeChosen = true; + SB.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd"); } + + sponsorTimes = sponsorTimesStorage; + + displaySponsorTimes(); + + //show submission section + SB.submissionSection.style.display = "unset"; + + showSubmitTimesIfNecessary(); + } //check if this video's sponsors are known chrome.tabs.sendMessage( From bfa0472f84faaba92b2ec3a282aeccaf72c1236d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 8 Jan 2020 19:52:41 +0000 Subject: [PATCH 59/70] Reflect --- SB.js | 57 ++++----------------------------------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/SB.js b/SB.js index a52f45d6..95153e7e 100644 --- a/SB.js +++ b/SB.js @@ -1,58 +1,11 @@ SB = {}; -class ListenerMap extends Map { - constructor(name) { - super(); - - this.name = name; - } - - set(key, value) { - super.set(key, value); - - this.updateListener(this.name, this); - } - - delete(key) { - this.updateListener(this.name, this); - - return super.set(key); - } - - clear() { - return super.clear(); - } - - forEach(callbackfn) { - return super.forEach(callbackfn); - } - - get(key) { - return super.get(key); - } - - has(key) { - return super.has(key); - } -} - -function mapHandler(name, object) { - SB.config[name] = SB.config[name]; - // chrome.storage.sync.set({ - // [name]: object - // }); - - // console.log(name) - // console.log(object) -} - function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - SB.localconfig[key] = changes[key].newValue; + Reflect.set(SB.localconfig, key, changes[key].newValue); } }); - var handler = { set: function(obj, prop, value) { chrome.storage.sync.set({ @@ -60,8 +13,9 @@ function configProxy() { }); }, get: function(obj, prop) { - return SB.localconfig[prop]; + return Reflect.get(SB.localconfig, prop); } + }; return new Proxy({}, handler); @@ -86,9 +40,6 @@ function migrate() { // Convert sponsorTimes format async function config() { await fetchConfig(); addDefaults(); - // Setup sponsorTime listener - SB.localconfig.sponsorTimes.updateListener = mapHandler; - SB.config = configProxy(); migrate(); @@ -96,7 +47,7 @@ async function config() { } SB.defaults = { - "sponsorTimes": new ListenerMap("sponsorTimes"), + "sponsorTimes": new Map(), "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, From a314139302b80e7de60333a3a820ef59354d297e Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 8 Jan 2020 22:22:18 +0000 Subject: [PATCH 60/70] Map storage encoding --- SB.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/SB.js b/SB.js index 95153e7e..9b989e26 100644 --- a/SB.js +++ b/SB.js @@ -1,19 +1,36 @@ SB = {}; +Map.prototype.toJSON = function() { + return Array.from(this.entries()); +}; + +function storeEncode(data) { + if(!(data instanceof Map)) return data; + return JSON.stringify(data); +} + +function strParser(data) { + try { + return new Map(JSON.parse(data)); + } catch(e) { + return data + } +} + function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - Reflect.set(SB.localconfig, key, changes[key].newValue); + Reflect.set(SB.localconfig, key, changes[key].newValue); } }); var handler = { set: function(obj, prop, value) { chrome.storage.sync.set({ - [prop]: value + [prop]: storeEncode(value) }); }, get: function(obj, prop) { - return Reflect.get(SB.localconfig, prop); + return strParser(Reflect.get(SB.localconfig, prop)); } }; @@ -42,8 +59,6 @@ async function config() { addDefaults(); SB.config = configProxy(); migrate(); - - } SB.defaults = { From c0c3640638e000f34dc007dd80bef7532d885024 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 8 Jan 2020 23:16:02 +0000 Subject: [PATCH 61/70] Reverted back --- SB.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/SB.js b/SB.js index 9b989e26..25ca5065 100644 --- a/SB.js +++ b/SB.js @@ -17,6 +17,46 @@ function strParser(data) { } } +class ListenerMap extends Map { + constructor(name) { + super(); + + this.name = name; + } + + set(key, value) { + super.set(key, value); + + this.updateListener(this.name, this); + } + + delete(key) { + this.updateListener(this.name, this); + + return super.set(key); + } + + clear() { + return super.clear(); + } + + forEach(callbackfn) { + return super.forEach(callbackfn); + } + + get(key) { + return super.get(key); + } + + has(key) { + return super.has(key); + } +} + +function mapHandler(name, object) { + SB.config[name] = storeEncode(object); +} + function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { @@ -57,12 +97,14 @@ function migrate() { // Convert sponsorTimes format async function config() { await fetchConfig(); addDefaults(); + // Setup sponsorTime listener + SB.localconfig.sponsorTimes.updateListener = mapHandler; SB.config = configProxy(); migrate(); } SB.defaults = { - "sponsorTimes": new Map(), + "sponsorTimes": new ListenerMap("sponsorTimes"), "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, From 339d05e157ba2f543ff58c1b9b806017c55f999a Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Wed, 8 Jan 2020 23:27:34 +0000 Subject: [PATCH 62/70] :/ --- SB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SB.js b/SB.js index 25ca5065..ce53925f 100644 --- a/SB.js +++ b/SB.js @@ -45,7 +45,7 @@ class ListenerMap extends Map { } get(key) { - return super.get(key); + return strParser(super.get(key)); } has(key) { @@ -54,7 +54,7 @@ class ListenerMap extends Map { } function mapHandler(name, object) { - SB.config[name] = storeEncode(object); + SB.config[name] = storeEncode(object.value); } function configProxy() { From 52f60d70e2a5a0eb7e9db3118f2e811aff0d1093 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 9 Jan 2020 16:39:23 +0000 Subject: [PATCH 63/70] Map support :D --- SB.js | 95 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/SB.js b/SB.js index ce53925f..0eb8cfb0 100644 --- a/SB.js +++ b/SB.js @@ -9,60 +9,77 @@ function storeEncode(data) { return JSON.stringify(data); } -function strParser(data) { +function mapDecode(data, key) { + if(typeof data !== "string") return data; try { - return new Map(JSON.parse(data)); + let str = JSON.parse(data); + if(!Array.isArray(str)) return data; + return new Map(str); } catch(e) { return data } } -class ListenerMap extends Map { - constructor(name) { - super(); +function mapProxy(data, key) { + if(!(data instanceof Map)) return data; + return new mapIO(key); +} - this.name = name; +class mapIO extends Map { + constructor(id) { + super(); + this.id = id; + this.map = SB.localconfig[this.id]; } set(key, value) { - super.set(key, value); - - this.updateListener(this.name, this); + SB.localconfig[this.id].set(key, value); + chrome.storage.sync.set({ + [this.id]: storeEncode(this.map) + }); + return this.map } - - delete(key) { - this.updateListener(this.name, this); - - return super.set(key); + + get(key) { + return this.map.get(key) } - - clear() { - return super.clear(); + + has(key) { + return this.map.has(key) } - - forEach(callbackfn) { - return super.forEach(callbackfn); + + toJSON() { + return Array.from(this.map.entries()) } - - get(key) { - return strParser(super.get(key)); + + deleteProperty(key) { + if (this.map.has(key)) { + this.map.delete(key); + return true; + } else { + return false; + } + } + + size() { + return this.map.size } - - has(key) { - return super.has(key); + + delete(key) { + this.map.delete(key); + chrome.storage.sync.set({ + [this.id]: storeEncode(this.map) + }); } } -function mapHandler(name, object) { - SB.config[name] = storeEncode(object.value); -} - function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - Reflect.set(SB.localconfig, key, changes[key].newValue); + Reflect.set(SB.localconfig, key, mapDecode(changes[key].newValue, key)); } }); + var handler = { set: function(obj, prop, value) { chrome.storage.sync.set({ @@ -70,7 +87,7 @@ function configProxy() { }); }, get: function(obj, prop) { - return strParser(Reflect.get(SB.localconfig, prop)); + return mapProxy(Reflect.get(SB.localconfig, prop), prop); } }; @@ -96,15 +113,14 @@ function migrate() { // Convert sponsorTimes format async function config() { await fetchConfig(); - addDefaults(); - // Setup sponsorTime listener - SB.localconfig.sponsorTimes.updateListener = mapHandler; - SB.config = configProxy(); + addDefaults(); + convertJson(); + SB.config = configProxy(); migrate(); } SB.defaults = { - "sponsorTimes": new ListenerMap("sponsorTimes"), + "sponsorTimes": new Map(), "startSponsorKeybind": ";", "submitKeybind": "'", "minutesSaved": 0, @@ -126,6 +142,11 @@ function resetConfig() { SB.config = SB.defaults; }; +function convertJson() { + Object.keys(SB.defaults).forEach(key => { + SB.localconfig[key] = mapDecode(SB.localconfig[key], key); + }); +} // Add defaults function addDefaults() { Object.keys(SB.defaults).forEach(key => { From f42c23cd9a84e3172bb3f30966943bf8d96fafb2 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 12:12:49 -0500 Subject: [PATCH 64/70] Formatting fixes --- SB.js | 42 +++++++++++++++++++++--------------------- popup.js | 30 +++++++++++++++--------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/SB.js b/SB.js index 0eb8cfb0..b38c9642 100644 --- a/SB.js +++ b/SB.js @@ -4,27 +4,6 @@ Map.prototype.toJSON = function() { return Array.from(this.entries()); }; -function storeEncode(data) { - if(!(data instanceof Map)) return data; - return JSON.stringify(data); -} - -function mapDecode(data, key) { - if(typeof data !== "string") return data; - try { - let str = JSON.parse(data); - if(!Array.isArray(str)) return data; - return new Map(str); - } catch(e) { - return data - } -} - -function mapProxy(data, key) { - if(!(data instanceof Map)) return data; - return new mapIO(key); -} - class mapIO extends Map { constructor(id) { super(); @@ -73,6 +52,27 @@ class mapIO extends Map { } } +function storeEncode(data) { + if(!(data instanceof Map)) return data; + return JSON.stringify(data); +} + +function mapDecode(data, key) { + if(typeof data !== "string") return data; + try { + let str = JSON.parse(data); + if(!Array.isArray(str)) return data; + return new Map(str); + } catch(e) { + return data + } +} + +function mapProxy(data, key) { + if(!(data instanceof Map)) return data; + return new mapIO(key); +} + function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { diff --git a/popup.js b/popup.js index 19408027..15b489f8 100644 --- a/popup.js +++ b/popup.js @@ -4,21 +4,21 @@ async function runThePopup() { //is it in the popup or content script var inPopup = true; if (chrome.tabs == undefined) { - //this is on the content script, use direct communication - chrome.tabs = {}; - chrome.tabs.sendMessage = function(id, request, callback) { - messageListener(request, null, callback); - } - - //add a dummy query method - chrome.tabs.query = function(config, callback) { - callback([{ - url: document.URL, - id: -1 - }]); - } - - inPopup = false; + //this is on the content script, use direct communication + chrome.tabs = {}; + chrome.tabs.sendMessage = function(id, request, callback) { + messageListener(request, null, callback); + } + + //add a dummy query method + chrome.tabs.query = function(config, callback) { + callback([{ + url: document.URL, + id: -1 + }]); + } + + inPopup = false; } await wait(() => SB.config !== undefined); From a2e968841820e09f9a6aa1fb00293916de130f9c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 12:30:09 -0500 Subject: [PATCH 65/70] Formatting + duplicate code removal. --- SB.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/SB.js b/SB.js index b38c9642..d33dfc88 100644 --- a/SB.js +++ b/SB.js @@ -4,31 +4,32 @@ Map.prototype.toJSON = function() { return Array.from(this.entries()); }; -class mapIO extends Map { +class MapIO extends Map { constructor(id) { - super(); + super(); + this.id = id; this.map = SB.localconfig[this.id]; } set(key, value) { - SB.localconfig[this.id].set(key, value); - chrome.storage.sync.set({ - [this.id]: storeEncode(this.map) - }); - return this.map + this.map.set(key, value); + + SB.config.handler.set(undefined, this.id, storeEncode(this.map)); + + return this.map; } get(key) { - return this.map.get(key) + return this.map.get(key); } has(key) { - return this.map.has(key) + return this.map.has(key); } toJSON() { - return Array.from(this.map.entries()) + return Array.from(this.map.entries()); } deleteProperty(key) { @@ -41,14 +42,13 @@ class mapIO extends Map { } size() { - return this.map.size + return this.map.size; } delete(key) { this.map.delete(key); - chrome.storage.sync.set({ - [this.id]: storeEncode(this.map) - }); + + SB.config.handler.set(undefined, this.id, storeEncode(this.map)); } } @@ -58,7 +58,8 @@ function storeEncode(data) { } function mapDecode(data, key) { - if(typeof data !== "string") return data; + if(typeof data !== "string") return data; + try { let str = JSON.parse(data); if(!Array.isArray(str)) return data; @@ -70,7 +71,7 @@ function mapDecode(data, key) { function mapProxy(data, key) { if(!(data instanceof Map)) return data; - return new mapIO(key); + return new MapIO(key); } function configProxy() { @@ -87,12 +88,12 @@ function configProxy() { }); }, get: function(obj, prop) { - return mapProxy(Reflect.get(SB.localconfig, prop), prop); + return obj[prop] || mapProxy(Reflect.get(SB.localconfig, prop), prop); } }; - return new Proxy({}, handler); + return new Proxy({handler}, handler); } fetchConfig = () => new Promise((resolve, reject) => { From d0e7213cc433f4a1aa5f784c0ded838d8c371202 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 12:38:15 -0500 Subject: [PATCH 66/70] Added docs and removed reflection. Also removed inheritance. --- SB.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/SB.js b/SB.js index d33dfc88..70c05590 100644 --- a/SB.js +++ b/SB.js @@ -4,10 +4,8 @@ Map.prototype.toJSON = function() { return Array.from(this.entries()); }; -class MapIO extends Map { +class MapIO { constructor(id) { - super(); - this.id = id; this.map = SB.localconfig[this.id]; } @@ -57,27 +55,31 @@ function storeEncode(data) { return JSON.stringify(data); } -function mapDecode(data, key) { +/** + * A Map cannot be stored in the chrome storage. + * This data will be decoded from the array it is stored in + * + * @param {*} data + */ +function decodeStoredItem(data) { if(typeof data !== "string") return data; try { - let str = JSON.parse(data); + let str = JSON.parse(data); + if(!Array.isArray(str)) return data; return new Map(str); } catch(e) { - return data - } -} -function mapProxy(data, key) { - if(!(data instanceof Map)) return data; - return new MapIO(key); + // If all else fails, return the data + return data; + } } function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - Reflect.set(SB.localconfig, key, mapDecode(changes[key].newValue, key)); + SB.localconfig[key] = decodeStoredItem(changes[key].newValue); } }); @@ -88,7 +90,10 @@ function configProxy() { }); }, get: function(obj, prop) { - return obj[prop] || mapProxy(Reflect.get(SB.localconfig, prop), prop); + let data = SB.localconfig[prop]; + if(data instanceof Map) data = new MapIO(prop); + + return obj[prop] || data; } }; @@ -145,7 +150,7 @@ function resetConfig() { function convertJson() { Object.keys(SB.defaults).forEach(key => { - SB.localconfig[key] = mapDecode(SB.localconfig[key], key); + SB.localconfig[key] = decodeStoredItem(SB.localconfig[key], key); }); } // Add defaults From 309b1b007e17501ee20d4617acba4617df22a3bd Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 12:39:48 -0500 Subject: [PATCH 67/70] Removed unneeded function --- SB.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SB.js b/SB.js index 70c05590..769f716a 100644 --- a/SB.js +++ b/SB.js @@ -26,10 +26,6 @@ class MapIO { return this.map.has(key); } - toJSON() { - return Array.from(this.map.entries()); - } - deleteProperty(key) { if (this.map.has(key)) { this.map.delete(key); From 8fd671d4d366bd44b16fa3dab16ca88a9002a06b Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 12:46:04 -0500 Subject: [PATCH 68/70] Added docs and improved consistency. --- SB.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/SB.js b/SB.js index 769f716a..b393f28f 100644 --- a/SB.js +++ b/SB.js @@ -1,5 +1,7 @@ SB = {}; +// Function setup + Map.prototype.toJSON = function() { return Array.from(this.entries()); }; @@ -13,7 +15,7 @@ class MapIO { set(key, value) { this.map.set(key, value); - SB.config.handler.set(undefined, this.id, storeEncode(this.map)); + SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map)); return this.map; } @@ -42,11 +44,17 @@ class MapIO { delete(key) { this.map.delete(key); - SB.config.handler.set(undefined, this.id, storeEncode(this.map)); + SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map)); } } -function storeEncode(data) { +/** + * A Map cannot be stored in the chrome storage. + * This data will be encoded into an array instead as specified by the toJSON function. + * + * @param {*} data + */ +function encodeStoredItem(data) { if(!(data instanceof Map)) return data; return JSON.stringify(data); } @@ -82,7 +90,7 @@ function configProxy() { var handler = { set: function(obj, prop, value) { chrome.storage.sync.set({ - [prop]: storeEncode(value) + [prop]: encodeStoredItem(value) }); }, get: function(obj, prop) { @@ -97,14 +105,16 @@ function configProxy() { return new Proxy({handler}, handler); } -fetchConfig = () => new Promise((resolve, reject) => { - chrome.storage.sync.get(null, function(items) { - SB.localconfig = items; // Data is ready - resolve(); +function fetchConfig() { + return new Promise((resolve, reject) => { + chrome.storage.sync.get(null, function(items) { + SB.localconfig = items; // Data is ready + resolve(); + }); }); -}); +} -function migrate() { // Convert sponsorTimes format +function migrateOldFormats() { // Convert sponsorTimes format for (key in SB.localconfig) { if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") { SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); @@ -113,12 +123,12 @@ function migrate() { // Convert sponsorTimes format } } -async function config() { +async function setupConfig() { await fetchConfig(); addDefaults(); - convertJson(); + convertJSON(); SB.config = configProxy(); - migrate(); + migrateOldFormats(); } SB.defaults = { @@ -144,11 +154,12 @@ function resetConfig() { SB.config = SB.defaults; }; -function convertJson() { +function convertJSON() { Object.keys(SB.defaults).forEach(key => { SB.localconfig[key] = decodeStoredItem(SB.localconfig[key], key); }); } + // Add defaults function addDefaults() { Object.keys(SB.defaults).forEach(key => { @@ -159,4 +170,4 @@ function addDefaults() { }; // Sync config -config(); +setupConfig(); From 4ba82f6e001b02d2f89f3c8f3042fb78e579f9d9 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 13:16:27 -0500 Subject: [PATCH 69/70] Set local config right away --- SB.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SB.js b/SB.js index b393f28f..989e31f1 100644 --- a/SB.js +++ b/SB.js @@ -89,6 +89,8 @@ function configProxy() { var handler = { set: function(obj, prop, value) { + SB.localconfig[prop] = value; + chrome.storage.sync.set({ [prop]: encodeStoredItem(value) }); From a8fc22eae806934146e178212c679a82fa1f3abf Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 9 Jan 2020 13:17:26 -0500 Subject: [PATCH 70/70] Reformatted variable name. --- SB.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SB.js b/SB.js index 989e31f1..eb6c489f 100644 --- a/SB.js +++ b/SB.js @@ -9,7 +9,7 @@ Map.prototype.toJSON = function() { class MapIO { constructor(id) { this.id = id; - this.map = SB.localconfig[this.id]; + this.map = SB.localConfig[this.id]; } set(key, value) { @@ -83,20 +83,20 @@ function decodeStoredItem(data) { function configProxy() { chrome.storage.onChanged.addListener((changes, namespace) => { for (key in changes) { - SB.localconfig[key] = decodeStoredItem(changes[key].newValue); + SB.localConfig[key] = decodeStoredItem(changes[key].newValue); } }); var handler = { set: function(obj, prop, value) { - SB.localconfig[prop] = value; + SB.localConfig[prop] = value; chrome.storage.sync.set({ [prop]: encodeStoredItem(value) }); }, get: function(obj, prop) { - let data = SB.localconfig[prop]; + let data = SB.localConfig[prop]; if(data instanceof Map) data = new MapIO(prop); return obj[prop] || data; @@ -110,14 +110,14 @@ function configProxy() { function fetchConfig() { return new Promise((resolve, reject) => { chrome.storage.sync.get(null, function(items) { - SB.localconfig = items; // Data is ready + SB.localConfig = items; // Data is ready resolve(); }); }); } function migrateOldFormats() { // Convert sponsorTimes format - for (key in SB.localconfig) { + for (key in SB.localConfig) { if (key.startsWith("sponsorTimes") && key !== "sponsorTimes" && key !== "sponsorTimesContributed") { SB.config.sponsorTimes.set(key.substr(12), SB.config[key]); delete SB.config[key]; @@ -158,15 +158,15 @@ function resetConfig() { function convertJSON() { Object.keys(SB.defaults).forEach(key => { - SB.localconfig[key] = decodeStoredItem(SB.localconfig[key], key); + SB.localConfig[key] = decodeStoredItem(SB.localConfig[key], key); }); } // Add defaults function addDefaults() { Object.keys(SB.defaults).forEach(key => { - if(!SB.localconfig.hasOwnProperty(key)) { - SB.localconfig[key] = SB.defaults[key]; + if(!SB.localConfig.hasOwnProperty(key)) { + SB.localConfig[key] = SB.defaults[key]; } }); };