From e6ef27936ec6ea72d009bc73bd4ed0a74180db21 Mon Sep 17 00:00:00 2001 From: Lartza Date: Fri, 24 Jan 2020 01:02:23 +0200 Subject: [PATCH 01/11] Add minimum duration option --- SB.js | 3 ++- _locales/en/messages.json | 8 +++++++- content.js | 4 ++++ options/options.css | 9 +++++++++ options/options.html | 16 +++++++++++++++- options/options.js | 14 ++++++++++++++ 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/SB.js b/SB.js index 86582311..3026c90f 100644 --- a/SB.js +++ b/SB.js @@ -176,7 +176,8 @@ SB.defaults = { "hideDiscordLink": false, "invidiousInstances": ["invidio.us", "invidiou.sh", "invidious.snopyta.org"], "invidiousUpdateInfoShowCount": 0, - "autoUpvote": true + "autoUpvote": true, + "minDuration": 0 } // Reset config diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 51017402..ca9ce167 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -386,5 +386,11 @@ }, "invidiousInfo2": { "message": "You MUST enable it in the options for it to work." - } + }, + "minDuration": { + "message": "Minimum duration (seconds)" + }, + "minDurationDescription": { + "message": "Sponsor segments shorter than the set value will be ignored." + } } diff --git a/content.js b/content.js index fd36a886..0ad119fc 100644 --- a/content.js +++ b/content.js @@ -521,6 +521,10 @@ function checkSponsorTime(sponsorTimes, index, openNotice) { lastTime = v.currentTime - 0.0001; } + if (sponsorTimes[index][1] - sponsorTimes[index][0] < SB.config.minDuration) { + return false; + } + if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0], sponsorTimes[index][1]) && !hiddenSponsorTimes.includes(index)) { //skip it skipToTime(v, index, sponsorTimes, openNotice); diff --git a/options/options.css b/options/options.css index 7cfa094e..bc8e2f92 100644 --- a/options/options.css +++ b/options/options.css @@ -309,4 +309,13 @@ h1,h2,h3,h4,h5,h6 { svg { text-decoration: none; +} + +.number-container:before { + content: attr(label-name); + padding-right: 4px; + width: max-content; + + font-size: 14px; + color: white; } \ No newline at end of file diff --git a/options/options.html b/options/options.html index 19354139..1eea3cb5 100644 --- a/options/options.html +++ b/options/options.html @@ -78,6 +78,20 @@

+
+ + +
+
+ +
__MSG_minDurationDescription__
+
+ +
+
+
+ +
+
+ +
+ + +
+
+ +
__MSG_minDurationDescription__
+


From afe16e6623a2d5937f51765175b0ca17ebe94e9f Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 19:27:38 -0500 Subject: [PATCH 10/11] Improved confirm message. --- public/_locales/en/messages.json | 2 +- src/content.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index a7ad101d..0900962e 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -394,6 +394,6 @@ "message": "Sponsor segments shorter than the set value will not be skipeed or show in the player." }, "shortCheck": { - "message": "One of the segments is shorter than your minimum duration. Do you still want to submit?" + "message": "The following submission is shorter than your minimum duration option. This could mean that this is already submitted, and just being ignored due to this option. Are you sure you would like to submit?" } } diff --git a/src/content.ts b/src/content.ts index ab75c270..d88f8be4 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1022,11 +1022,14 @@ function submitSponsorTimes() { //update sponsorTimesSubmitting sponsorTimesSubmitting = sponsorTimes; - for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i][1] - sponsorTimes[i][0] < Config.config.minDuration) { - let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes); - if(!confirm(confirmShort)) return; - break; + // Check to see if any of the submissions are below the minimum duration set + if (Config.config.minDuration > 0) { + for (let i = 0; i < sponsorTimes.length; i++) { + if (sponsorTimes[i][1] - sponsorTimes[i][0] < Config.config.minDuration) { + let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes); + + if(!confirm(confirmShort)) return; + } } } From 553581f67b049902423d4d411731d7482de3cf28 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 19:28:23 -0500 Subject: [PATCH 11/11] Removed extra file --- SB.js | 204 ---------------------------------------------------------- 1 file changed, 204 deletions(-) delete mode 100644 SB.js diff --git a/SB.js b/SB.js deleted file mode 100644 index 3026c90f..00000000 --- a/SB.js +++ /dev/null @@ -1,204 +0,0 @@ -SB = { - /** - * Callback function when an option is updated - * - * @type {CallableFunction} - */ - configListeners: [] -}; - -// Function setup - -// Allows a map to be conveted into json form -// Currently used for local storage -Map.prototype.toJSON = function() { - return Array.from(this.entries()); -}; - -// Proxy Map changes to Map in SB.localConfig -// Saves the changes to chrome.storage in json form -class MapIO { - constructor(id) { - // The name of the item in the array - this.id = id; - // A local copy of the map (SB.config.mapname.map) - this.map = SB.localConfig[this.id]; - } - set(key, value) { - // Proxy to map - this.map.set(key, value); - // Store updated map locally - chrome.storage.sync.set({ - [this.id]: encodeStoredItem(this.map) - }); - return this.map; - } - - get(key) { - return this.map.get(key); - } - - has(key) { - return this.map.has(key); - } - - size() { - return this.map.size; - } - - delete(key) { - // Proxy to map - this.map.delete(key); - // Store updated map locally - chrome.storage.sync.set({ - [this.id]: encodeStoredItem(this.map) - }); - } - - clear() { - this.map.clear(); - chrome.storage.sync.set({ - [this.id]: encodeStoredItem(this.map) - }); - } -} - -/** - * 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 is Map convert to json for storing - if(!(data instanceof Map)) return data; - return JSON.stringify(data); -} - -/** - * 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); - - if(!Array.isArray(str)) return data; - return new Map(str); - } catch(e) { - - // If all else fails, return the data - return data; - } -} - -function configProxy() { - chrome.storage.onChanged.addListener((changes, namespace) => { - for (const key in changes) { - SB.localConfig[key] = decodeStoredItem(changes[key].newValue); - } - - for (const callback of SB.configListeners) { - callback(changes); - } - }); - - var handler = { - set(obj, prop, value) { - SB.localConfig[prop] = value; - - chrome.storage.sync.set({ - [prop]: encodeStoredItem(value) - }); - }, - - get(obj, prop) { - let data = SB.localConfig[prop]; - if(data instanceof Map) data = new MapIO(prop); - - return obj[prop] || data; - }, - - deleteProperty(obj, prop) { - chrome.storage.sync.remove(prop); - } - - }; - - return new Proxy({handler}, handler); -} - -function fetchConfig() { - return new Promise((resolve, reject) => { - chrome.storage.sync.get(null, function(items) { - SB.localConfig = items; // Data is ready - resolve(); - }); - }); -} - -function migrateOldFormats() { // Convert sponsorTimes format - 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]; - } - } -} - -async function setupConfig() { - await fetchConfig(); - 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, - "hideDiscordLink": false, - "invidiousInstances": ["invidio.us", "invidiou.sh", "invidious.snopyta.org"], - "invidiousUpdateInfoShowCount": 0, - "autoUpvote": true, - "minDuration": 0 -} - -// Reset config -function resetConfig() { - SB.config = SB.defaults; -}; - -function convertJSON() { - 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]; - } - } -}; - -// Sync config -setupConfig();