From 4de0ae51e83593ee0deb70b92f03e67b8e86ac86 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sat, 11 Jan 2020 19:42:35 +0000 Subject: [PATCH 1/3] Formatting changes & proxy delete support --- SB.js | 107 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/SB.js b/SB.js index ef624dc7..df833a05 100644 --- a/SB.js +++ b/SB.js @@ -24,33 +24,33 @@ class MapIO { SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map)); - return this.map; + return this.map; } - get(key) { - return this.map.get(key); - } - - has(key) { - return this.map.has(key); - } - - deleteProperty(key) { - if (this.map.has(key)) { - this.map.delete(key); - return true; - } else { - return false; - } + get(key) { + return this.map.get(key); } - size() { - return this.map.size; + has(key) { + return this.map.has(key); } - delete(key) { - this.map.delete(key); - + deleteProperty(key) { + if (this.map.has(key)) { + this.map.delete(key); + return true; + } else { + return false; + } + } + + size() { + return this.map.size; + } + + delete(key) { + this.map.delete(key); + SB.config.handler.set(undefined, this.id, encodeStoredItem(this.map)); } } @@ -75,11 +75,11 @@ function encodeStoredItem(data) { function decodeStoredItem(data) { if(typeof data !== "string") return data; - try { + try { let str = JSON.parse(data); - if(!Array.isArray(str)) return data; - return new Map(str); + if(!Array.isArray(str)) return data; + return new Map(str); } catch(e) { // If all else fails, return the data @@ -99,18 +99,23 @@ function configProxy() { }); var handler = { - set: function(obj, prop, value) { + set(obj, prop, value) { SB.localConfig[prop] = value; chrome.storage.sync.set({ [prop]: encodeStoredItem(value) }); }, - get: function(obj, prop) { + + get(obj, prop) { let data = SB.localConfig[prop]; if(data instanceof Map) data = new MapIO(prop); - return obj[prop] || data; + return obj[prop] || data; + }, + + deleteProperty(obj, prop) { + chrome.storage.sync.remove(key); } }; @@ -131,34 +136,34 @@ 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]); - chrome.storage.sync.remove(key); + delete SB.config[key]; } } } async function setupConfig() { await fetchConfig(); - addDefaults(); - convertJSON(); - SB.config = configProxy(); + addDefaults(); + convertJSON(); + SB.config = configProxy(); migrateOldFormats(); } SB.defaults = { - "sponsorTimes": new Map(), - "startSponsorKeybind": ";", - "submitKeybind": "'", - "minutesSaved": 0, - "skipCount": 0, - "sponsorTimesContributed": 0, - "disableSkipping": false, - "disableAutoSkip": false, - "trackViewCount": true, - "dontShowNotice": false, - "hideVideoPlayerControls": false, - "hideInfoButtonPlayerControls": false, - "hideDeleteButtonPlayerControls": false, - "hideDiscordLaunches": 0, + "sponsorTimes": new Map(), + "startSponsorKeybind": ";", + "submitKeybind": "'", + "minutesSaved": 0, + "skipCount": 0, + "sponsorTimesContributed": 0, + "disableSkipping": false, + "disableAutoSkip": false, + "trackViewCount": true, + "dontShowNotice": false, + "hideVideoPlayerControls": false, + "hideInfoButtonPlayerControls": false, + "hideDeleteButtonPlayerControls": false, + "hideDiscordLaunches": 0, "hideDiscordLink": false, "invidiousInstances": ["invidio.us", "invidiou.sh", "invidious.snopyta.org"], "invidiousUpdateInfoShowCount": 0, @@ -167,21 +172,21 @@ SB.defaults = { // Reset config function resetConfig() { - SB.config = SB.defaults; + SB.config = SB.defaults; }; function convertJSON() { - Object.keys(SB.defaults).forEach(key => { - SB.localConfig[key] = decodeStoredItem(SB.localConfig[key], key); - }); + Object.keys(SB.defaults).forEach(key => { + SB.localConfig[key] = decodeStoredItem(SB.localConfig[key], key); + }); } // Add defaults function addDefaults() { for (const key in SB.defaults) { if(!SB.localConfig.hasOwnProperty(key)) { - SB.localConfig[key] = SB.defaults[key]; - } + SB.localConfig[key] = SB.defaults[key]; + } } }; From 7c809419f8164c659d99338134ffde662e27f7c2 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 11 Jan 2020 14:48:17 -0500 Subject: [PATCH 2/3] Formatting changes --- SB.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SB.js b/SB.js index df833a05..c17d6a31 100644 --- a/SB.js +++ b/SB.js @@ -78,8 +78,8 @@ function decodeStoredItem(data) { try { let str = JSON.parse(data); - if(!Array.isArray(str)) return data; - return new Map(str); + if(!Array.isArray(str)) return data; + return new Map(str); } catch(e) { // If all else fails, return the data @@ -115,7 +115,7 @@ function configProxy() { }, deleteProperty(obj, prop) { - chrome.storage.sync.remove(key); + chrome.storage.sync.remove(key); } }; From 1163b6f0cebb0eeab1c1aa9b837b24aa49c6f922 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 11 Jan 2020 14:50:11 -0500 Subject: [PATCH 3/3] Fixed wrong variabled being used. --- SB.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SB.js b/SB.js index c17d6a31..336e7057 100644 --- a/SB.js +++ b/SB.js @@ -115,7 +115,7 @@ function configProxy() { }, deleteProperty(obj, prop) { - chrome.storage.sync.remove(key); + chrome.storage.sync.remove(prop); } }; @@ -133,7 +133,7 @@ function fetchConfig() { } function migrateOldFormats() { // Convert sponsorTimes format - for (key in SB.localConfig) { + for (const 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];