From 5ac6dd1a7f14415a972058fba0aa64f1e13ed9fb Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 20:48:39 -0400 Subject: Update description --- public/_locales/en/messages.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index a1beb859..f0c7907a 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -218,7 +218,7 @@ "message": "Show Notice Again" }, "longDescription": { - "message": "SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that lets anyone submit the start and end times of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.", + "message": "SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that lets anyone submit the start and end times of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment. \n\n You can also skip intros, outros, reminders to subscribe and other categories.", "description": "Full description of the extension on the store pages." }, "website": { -- cgit v1.2.3 From 5c4f0c960c339aa456042df922b1e5f6b9741489 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 20:50:06 -0400 Subject: Reload after importing options --- src/options.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/options.ts b/src/options.ts index 0a196a9a..ce1f31fb 100644 --- a/src/options.ts +++ b/src/options.ts @@ -460,15 +460,14 @@ function activatePrivateTextChange(element: HTMLElement) { } Config.convertJSON(); - // Reload options on page - init(); - if (newConfig.supportInvidious) { let checkbox = document.querySelector("#support-invidious > label > label > input"); checkbox.checked = true; invidiousOnClick(checkbox, "supportInvidious"); } + + window.location.reload(); } catch (e) { alert(chrome.i18n.getMessage("incorrectlyFormattedOptions")); -- cgit v1.2.3 From cd0b1f4a31271eb0b020d80c30a26068801aecd5 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 20:56:41 -0400 Subject: Wait for permissions before reloading --- src/options.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/options.ts b/src/options.ts index ce1f31fb..5309290b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -298,19 +298,23 @@ function invidiousInit(checkbox: HTMLInputElement, option: string) { * @param checkbox * @param option */ -function invidiousOnClick(checkbox: HTMLInputElement, option: string) { - if (checkbox.checked) { - utils.setupExtraSitePermissions(function (granted) { - if (!granted) { - Config.config[option] = false; - checkbox.checked = false; - } else { - checkbox.checked = true; - } - }); - } else { - utils.removeExtraSiteRegistration(); - } +async function invidiousOnClick(checkbox: HTMLInputElement, option: string) { + return new Promise((resolve) => { + if (checkbox.checked) { + utils.setupExtraSitePermissions(function (granted) { + if (!granted) { + Config.config[option] = false; + checkbox.checked = false; + } else { + checkbox.checked = true; + } + + resolve(); + }); + } else { + utils.removeExtraSiteRegistration(); + } + }); } /** @@ -445,7 +449,7 @@ function activatePrivateTextChange(element: HTMLElement) { textBox.value = result; let setButton = element.querySelector(".text-change-set"); - setButton.addEventListener("click", () => { + setButton.addEventListener("click", async () => { let confirmMessage = element.getAttribute("confirm-message"); if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) { @@ -464,7 +468,7 @@ function activatePrivateTextChange(element: HTMLElement) { let checkbox = document.querySelector("#support-invidious > label > label > input"); checkbox.checked = true; - invidiousOnClick(checkbox, "supportInvidious"); + await invidiousOnClick(checkbox, "supportInvidious"); } window.location.reload(); -- cgit v1.2.3 From 955ee32b462a185ceb181c9b4c048d49ddb09246 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 21:13:07 -0400 Subject: Remove category update message --- src/components/SkipNoticeComponent.tsx | 7 ------- src/config.ts | 9 ++++----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index 022490d0..9dab754b 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -134,13 +134,6 @@ class SkipNoticeComponent extends React.Component chrome.runtime.sendMessage({"message": "openConfig"}) - , chrome.i18n.getMessage("categoryUpdate1"), chrome.i18n.getMessage("categoryUpdate2")); - - Config.config.categoryUpdateShowCount = Config.config.categoryUpdateShowCount + 1 - } } render() { diff --git a/src/config.ts b/src/config.ts index 634947a9..4198b7d6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -33,8 +33,6 @@ interface SBConfig { checkForUnlistedVideos: boolean, testingServer: boolean, - categoryUpdateShowCount: number, - // What categories should be skipped categorySelections: CategorySelection[], @@ -151,8 +149,6 @@ var Config: SBObject = { checkForUnlistedVideos: false, testingServer: false, - categoryUpdateShowCount: 0, - categorySelections: [{ name: "sponsor", option: CategorySkipOption.AutoSkip @@ -328,11 +324,14 @@ async function migrateOldFormats() { if (Config.config["autoUpvote"]) { chrome.storage.sync.remove("autoUpvote"); } - // mobileUpdateShowCount removal if (Config.config["mobileUpdateShowCount"] !== undefined) { chrome.storage.sync.remove("mobileUpdateShowCount"); } + // categoryUpdateShowCount removal + if (Config.config["categoryUpdateShowCount"] !== undefined) { + chrome.storage.sync.remove("categoryUpdateShowCount"); + } // Channel URLS if (Config.config.whitelistedChannels.length > 0 && -- cgit v1.2.3 From 367657e44ea56bae46f0ea9962cc9d98f6c2b5f7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 21:37:38 -0400 Subject: Added intermission category --- config.json.example | 2 +- public/_locales/en/messages.json | 6 ++++++ src/config.ts | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index 09cf2bba..3fabce07 100644 --- a/config.json.example +++ b/config.json.example @@ -2,5 +2,5 @@ "serverAddress": "https://sponsor.ajay.app", "testingServerAddress": "https://sponsor.ajay.app/test", "serverAddressComment": "This specifies the default SponsorBlock server to connect to", - "categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "music_offtopic"] + "categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "intermission", "music_offtopic"] } diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index f0c7907a..55bd3744 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -512,6 +512,12 @@ "category_selfpromo_description": { "message": "Similar to \"sponsor\" except for unpaid or self promotion. This includes sections about merchandise, donations, or information about who they collaborated with." }, + "category_intermission": { + "message": "Intermission" + }, + "category_intermission_description": { + "message": "An interval without actual content. Could be a pause, static frame, or repeating animation in the video. Should not be used for pauses or transitions with actual content" + }, "category_music_offtopic": { "message": "Music: Non-Music Section" }, diff --git a/src/config.ts b/src/config.ts index 4198b7d6..38225cff 100644 --- a/src/config.ts +++ b/src/config.ts @@ -48,8 +48,10 @@ interface SBConfig { "preview-interaction": PreviewBarOption, "selfpromo": PreviewBarOption, "preview-selfpromo": PreviewBarOption, + "intermission": PreviewBarOption, + "preview-intermission": PreviewBarOption "music_offtopic": PreviewBarOption, - "preview-music_offtopic": PreviewBarOption + "preview-music_offtopic": PreviewBarOption, } } @@ -196,6 +198,14 @@ var Config: SBObject = { color: "#bfbf35", opacity: "0.7" }, + "intermission": { + color: "#45a8ff", + opacity: "0.7" + }, + "preview-intermission": { + color: "#0066bf", + opacity: "0.7" + }, "music_offtopic": { color: "#ff9900", opacity: "0.7" @@ -398,6 +408,12 @@ function addDefaults() { for (const key in Config.defaults) { if(!Config.localConfig.hasOwnProperty(key)) { Config.localConfig[key] = Config.defaults[key]; + } else if (key === "barTypes") { + for (const key2 in Config.defaults[key]) { + if(!Config.localConfig[key].hasOwnProperty(key2)) { + Config.localConfig[key][key2] = Config.defaults[key][key2]; + } + } } } }; -- cgit v1.2.3 From b3a94142c357aea0fe161ab5ddc5f131ddf4e607 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 21:39:00 -0400 Subject: Allow colon on invidious options --- src/options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.ts b/src/options.ts index 5309290b..814fce69 100644 --- a/src/options.ts +++ b/src/options.ts @@ -237,7 +237,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) { let setButton = element.querySelector(".text-change-set"); setButton.addEventListener("click", async function(e) { - if (textBox.value == "" || textBox.value.includes("/") || textBox.value.includes("http") || textBox.value.includes(":")) { + if (textBox.value == "" || textBox.value.includes("/") || textBox.value.includes("http")) { alert(chrome.i18n.getMessage("addInvidiousInstanceError")); } else { // Add this -- cgit v1.2.3 From 1265eeb94165727fe57176f885c43cbb8222b3ea Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 2 Jul 2020 23:34:13 -0400 Subject: Save category with the preview submissions. --- public/_locales/en/messages.json | 2 +- src/background.ts | 47 -------- src/components/SponsorTimeEditComponent.tsx | 4 +- src/config.ts | 159 +++++++++++++++++----------- src/content.ts | 53 ++++------ src/options.ts | 8 +- src/popup.ts | 38 ++++--- 7 files changed, 149 insertions(+), 162 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 55bd3744..ff63a4f7 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -516,7 +516,7 @@ "message": "Intermission" }, "category_intermission_description": { - "message": "An interval without actual content. Could be a pause, static frame, or repeating animation in the video. Should not be used for pauses or transitions with actual content" + "message": "An interval without actual content. Could be a pause, static frame, or repeating animation in the video. Should not be used for pauses or transitions with actual content." }, "category_music_offtopic": { "message": "Music: Non-Music Section" diff --git a/src/background.ts b/src/background.ts index 28a1051e..ec398d59 100644 --- a/src/background.ts +++ b/src/background.ts @@ -40,21 +40,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { }); }); - return true; - case "addSponsorTime": - addSponsorTime(request.time, request.videoID, callback); - - //this allows the callback to be called later - return true; - - case "getSponsorTimes": - getSponsorTimes(request.videoID, function(sponsorTimes) { - callback({ - sponsorTimes - }); - }); - - //this allows the callback to be called later return true; case "submitVote": submitVote(request.type, request.UUID, request.category).then(callback); @@ -127,38 +112,6 @@ function unregisterFirefoxContentScript(id: string) { delete contentScriptRegistrations[id]; } -//gets the sponsor times from memory -function getSponsorTimes(videoID, callback) { - let sponsorTimes = []; - let sponsorTimesStorage = Config.config.sponsorTimes.get(videoID); - - if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { - sponsorTimes = sponsorTimesStorage; - } - - callback(sponsorTimes); -} - -function addSponsorTime(time, videoID, callback) { - getSponsorTimes(videoID, function(sponsorTimes) { - //add to sponsorTimes - if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { - //it is an end time - sponsorTimes[sponsorTimes.length - 1][1] = time; - } else { - //it is a start time - let sponsorTimesIndex = sponsorTimes.length; - sponsorTimes[sponsorTimesIndex] = []; - - sponsorTimes[sponsorTimesIndex][0] = time; - } - - //save this info - Config.config.sponsorTimes.set(videoID, sponsorTimes); - callback(); - }); -} - async function submitVote(type: number, UUID: string, category: string) { let userID = Config.config.userID; diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 52c1da0c..efcf595a 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -322,7 +322,7 @@ class SponsorTimeEditComponent extends React.Component, + // sponsorTimes: SBMap, + segmentTimes: SBMap, whitelistedChannels: string[], forceChannelCheck: boolean, startSponsorKeybind: string, @@ -84,35 +85,39 @@ class SBMap extends Map { } } - set(key, value) { - const result = super.set(key, value); + get(key): U { + return super.get(key); + } + + rawSet(key, value) { + return super.set(key, value); + } + update() { // Store updated SBMap locally chrome.storage.sync.set({ [this.id]: encodeStoredItem(this) }); + } + + set(key: T, value: U) { + const result = super.set(key, value); + this.update(); return result; } delete(key) { const result = super.delete(key); - // Store updated SBMap locally - chrome.storage.sync.set({ - [this.id]: encodeStoredItem(this) - }); - + this.update(); return result; } clear() { const result = super.clear(); - chrome.storage.sync.set({ - [this.id]: encodeStoredItem(this) - }); - + this.update(); return result; } } @@ -124,7 +129,7 @@ var Config: SBObject = { configListeners: [], defaults: { userID: null, - sponsorTimes: new SBMap("sponsorTimes"), + segmentTimes: new SBMap("segmentTimes"), whitelistedChannels: [], forceChannelCheck: false, startSponsorKeybind: ";", @@ -244,24 +249,13 @@ function encodeStoredItem(data: T): T | Array { * * @param {*} data */ -function decodeStoredItem(id: string, data: T): T | SBMap { +function decodeStoredItem(id: string, data: T): T | SBMap { if (!Config.defaults[id]) return data; if (Config.defaults[id] instanceof SBMap) { try { - let jsonData: any = data; - - // Check if data is stored in the old format for SBMap (a JSON string) - if (typeof data === "string") { - try { - jsonData = JSON.parse(data); - } catch(e) { - // Continue normally (out of this if statement) - } - } - - if (!Array.isArray(jsonData)) return data; - return new SBMap(id, jsonData); + if (!Array.isArray(data)) return data; + return new SBMap(id, data); } catch(e) { console.error("Failed to parse SBMap: " + id); } @@ -319,9 +313,9 @@ function fetchConfig() { }); } -async function migrateOldFormats() { - if (Config.config["disableAutoSkip"]) { - for (const selection of Config.config.categorySelections) { +function migrateOldFormats(config: SBConfig) { + if (config["disableAutoSkip"]) { + for (const selection of config.categorySelections) { if (selection.name === "sponsor") { selection.option = CategorySkipOption.ManualSkip; @@ -331,65 +325,108 @@ async function migrateOldFormats() { } // Auto vote removal - if (Config.config["autoUpvote"]) { + if (config["autoUpvote"]) { chrome.storage.sync.remove("autoUpvote"); } // mobileUpdateShowCount removal - if (Config.config["mobileUpdateShowCount"] !== undefined) { + if (config["mobileUpdateShowCount"] !== undefined) { chrome.storage.sync.remove("mobileUpdateShowCount"); } // categoryUpdateShowCount removal - if (Config.config["categoryUpdateShowCount"] !== undefined) { + if (config["categoryUpdateShowCount"] !== undefined) { chrome.storage.sync.remove("categoryUpdateShowCount"); } // Channel URLS - if (Config.config.whitelistedChannels.length > 0 && - (Config.config.whitelistedChannels[0] == null || Config.config.whitelistedChannels[0].includes("/"))) { - let newChannelList: string[] = []; - for (const item of Config.config.whitelistedChannels) { - if (item != null) { - if (item.includes("/channel/")) { - newChannelList.push(item.split("/")[2]); - } else if (item.includes("/user/") && utils.isContentScript()) { - // Replace channel URL with channelID - let response = await utils.asyncRequestToCustomServer("GET", "https://sponsor.ajay.app/invidious/api/v1/channels/" + item.split("/")[2] + "?fields=authorId"); - - if (response.ok) { - newChannelList.push((JSON.parse(response.responseText)).authorId); - } else { - // Add it at the beginning so it gets converted later + if (config.whitelistedChannels.length > 0 && + (config.whitelistedChannels[0] == null || config.whitelistedChannels[0].includes("/"))) { + const channelURLFixer = async() => { + let newChannelList: string[] = []; + for (const item of config.whitelistedChannels) { + if (item != null) { + if (item.includes("/channel/")) { + newChannelList.push(item.split("/")[2]); + } else if (item.includes("/user/") && utils.isContentScript()) { + + + // Replace channel URL with channelID + let response = await utils.asyncRequestToCustomServer("GET", "https://sponsor.ajay.app/invidious/api/v1/channels/" + item.split("/")[2] + "?fields=authorId"); + + if (response.ok) { + newChannelList.push((JSON.parse(response.responseText)).authorId); + } else { + // Add it at the beginning so it gets converted later + newChannelList.unshift(item); + } + } else if (item.includes("/user/")) { + // Add it at the beginning so it gets converted later (The API can only be called in the content script due to CORS issues) newChannelList.unshift(item); + } else { + newChannelList.push(item); } - } else if (item.includes("/user/")) { - // Add it at the beginning so it gets converted later (The API can only be called in the content script due to CORS issues) - newChannelList.unshift(item); - } else { - newChannelList.push(item); } } + + config.whitelistedChannels = newChannelList; } - Config.config.whitelistedChannels = newChannelList; + channelURLFixer(); } // Check if off-topic category needs to be removed - for (let i = 0; i < Config.config.categorySelections.length; i++) { - if (Config.config.categorySelections[i].name === "offtopic") { - Config.config.categorySelections.splice(i, 1); + for (let i = 0; i < config.categorySelections.length; i++) { + if (config.categorySelections[i].name === "offtopic") { + config.categorySelections.splice(i, 1); // Call set listener - Config.config.categorySelections = Config.config.categorySelections; + config.categorySelections = config.categorySelections; break; } } + + // Migrate old "sponsorTimes" + if (config["sponsorTimes"]) { + let jsonData: any = config["sponsorTimes"]; + + // Check if data is stored in the old format for SBMap (a JSON string) + if (typeof jsonData === "string") { + try { + jsonData = JSON.parse(jsonData); + } catch(e) { + // Continue normally (out of this if statement) + } + } + + // Otherwise junk data + if (Array.isArray(jsonData)) { + let oldMap = new Map(jsonData); + oldMap.forEach((sponsorTimes: number[][], key) => { + let segmentTimes: SponsorTime[] = []; + for (const segment of sponsorTimes) { + segmentTimes.push({ + segment: segment, + category: "sponsor", + UUID: null + }); + } + + config.segmentTimes.rawSet(key, segmentTimes); + }); + + config.segmentTimes.update(); + } + + chrome.storage.sync.remove("sponsorTimes"); + } } async function setupConfig() { await fetchConfig(); addDefaults(); convertJSON(); - Config.config = configProxy(); - migrateOldFormats(); + const config = configProxy(); + migrateOldFormats(config); + + Config.config = config; } // Reset config diff --git a/src/content.ts b/src/content.ts index 86ae8342..f8a6ab8b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -323,13 +323,13 @@ async function videoIDChange(id) { //warn them if they had unsubmitted times if (previousVideoID != null) { //get the sponsor times from storage - let sponsorTimes = Config.config.sponsorTimes.get(previousVideoID); + let sponsorTimes = Config.config.segmentTimes.get(previousVideoID); if (sponsorTimes != undefined && sponsorTimes.length > 0) { //warn them that they have unsubmitted sponsor times - chrome.runtime.sendMessage({ - message: "alertPrevious", - previousVideoID: previousVideoID - }) + chrome.runtime.sendMessage({ + message: "alertPrevious", + previousVideoID: previousVideoID + }); } //set the previous video id to the currentID @@ -347,10 +347,10 @@ async function videoIDChange(id) { //make sure everything is properly added updateVisibilityOfPlayerControlsButton().then(() => { //see if the onvideo control image needs to be changed - let segments = Config.config.sponsorTimes.get(sponsorVideoID); - if (segments != null && segments.length > 0 && segments[segments.length - 1].length >= 2) { + let segments = Config.config.segmentTimes.get(sponsorVideoID); + if (segments != null && segments.length > 0 && segments[segments.length - 1].segment.length >= 2) { changeStartSponsorButton(true, true); - } else if (segments != null && segments.length > 0 && segments[segments.length - 1].length < 2) { + } else if (segments != null && segments.length > 0 && segments[segments.length - 1].segment.length < 2) { changeStartSponsorButton(false, true); } else { changeStartSponsorButton(true, false); @@ -1169,31 +1169,24 @@ function startSponsorClicked() { }); } - // Create raw segment list - let segments: number[][] = []; - for (const sponsorTime of sponsorTimesSubmitting) { - segments.push(sponsorTime.segment); - } - //save this info - Config.config.sponsorTimes.set(sponsorVideoID, segments); + Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting); updateSponsorTimesSubmitting(false) } function updateSponsorTimesSubmitting(getFromConfig: boolean = true) { - let segments = Config.config.sponsorTimes.get(sponsorVideoID); + let segmentTimes = Config.config.segmentTimes.get(sponsorVideoID); //see if this data should be saved in the sponsorTimesSubmitting variable - if (getFromConfig && segments != undefined) { + if (getFromConfig && segmentTimes != undefined) { sponsorTimesSubmitting = []; - for (const segment of segments) { + for (const segmentTime of segmentTimes) { sponsorTimesSubmitting.push({ - segment: segment, + segment: segmentTime.segment, UUID: null, - // Default to sponsor - category: "sponsor" + category: segmentTime.category }); } } @@ -1317,7 +1310,7 @@ function clearSponsorTimes() { let currentVideoID = sponsorVideoID; - let sponsorTimes = Config.config.sponsorTimes.get(currentVideoID); + let sponsorTimes = Config.config.segmentTimes.get(currentVideoID); if (sponsorTimes != undefined && sponsorTimes.length > 0) { let confirmMessage = chrome.i18n.getMessage("clearThis") + getSegmentsMessage(sponsorTimes) @@ -1325,7 +1318,7 @@ function clearSponsorTimes() { if(!confirm(confirmMessage)) return; //clear the sponsor times - Config.config.sponsorTimes.delete(currentVideoID); + Config.config.segmentTimes.delete(currentVideoID); //clear sponsor times submitting sponsorTimesSubmitting = []; @@ -1447,14 +1440,14 @@ async function sendSubmitMessage(){ } //update sponsorTimes - Config.config.sponsorTimes.set(sponsorVideoID, utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting)); + Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting); // Check to see if any of the submissions are below the minimum duration set if (Config.config.minDuration > 0) { for (let i = 0; i < sponsorTimesSubmitting.length; i++) { if (sponsorTimesSubmitting[i].segment[1] - sponsorTimesSubmitting[i].segment[0] < Config.config.minDuration) { let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" + - getSegmentsMessage(utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting)); + getSegmentsMessage(sponsorTimesSubmitting); if(!confirm(confirmShort)) return; } @@ -1484,7 +1477,7 @@ async function sendSubmitMessage(){ submitButton.addEventListener("animationend", animationEndListener); //clear the sponsor times - Config.config.sponsorTimes.delete(sponsorVideoID); + Config.config.segmentTimes.delete(sponsorVideoID); //add submissions to current sponsors list if (sponsorTimes === null) sponsorTimes = []; @@ -1512,12 +1505,12 @@ async function sendSubmitMessage(){ } //get the message that visually displays the video times -function getSegmentsMessage(segments: number[][]): string { +function getSegmentsMessage(sponsorTimes: SponsorTime[]): string { let sponsorTimesMessage = ""; - for (let i = 0; i < segments.length; i++) { - for (let s = 0; s < segments[i].length; s++) { - let timeMessage = utils.getFormattedTime(segments[i][s]); + for (let i = 0; i < sponsorTimes.length; i++) { + for (let s = 0; s < sponsorTimes[i].segment.length; s++) { + let timeMessage = utils.getFormattedTime(sponsorTimes[i].segment[s]); //if this is an end time if (s == 1) { timeMessage = " to " + timeMessage; diff --git a/src/options.ts b/src/options.ts index 814fce69..a0d3ccd9 100644 --- a/src/options.ts +++ b/src/options.ts @@ -439,8 +439,8 @@ function activatePrivateTextChange(element: HTMLElement) { case "*": let jsonData = JSON.parse(JSON.stringify(Config.localConfig)); - // Fix sponsorTimes data as it is destroyed from the JSON stringify - jsonData.sponsorTimes = Config.encodeStoredItem(Config.localConfig.sponsorTimes); + // Fix segmentTimes data as it is destroyed from the JSON stringify + jsonData.segmentTimes = Config.encodeStoredItem(Config.localConfig.segmentTimes); result = JSON.stringify(jsonData); break; @@ -522,8 +522,8 @@ function copyDebugOutputToClipboard() { config: JSON.parse(JSON.stringify(Config.localConfig)) // Deep clone config object }; - // Fix sponsorTimes data as it is destroyed from the JSON stringify - output.config.sponsorTimes = Config.encodeStoredItem(Config.localConfig.sponsorTimes); + // Fix segmentTimes data as it is destroyed from the JSON stringify + output.config.segmentTimes = Config.encodeStoredItem(Config.localConfig.segmentTimes); // Sanitise sensitive user config values delete output.config.userID; diff --git a/src/popup.ts b/src/popup.ts index ee5c9930..239fefbd 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -119,7 +119,7 @@ async function runThePopup(messageListener?: MessageListener) { let startTimeChosen = false; //the start and end time pairs (2d) - let sponsorTimes = []; + let sponsorTimes: SponsorTime[] = []; //current video ID of this tab let currentVideoID = null; @@ -252,9 +252,9 @@ async function runThePopup(messageListener?: MessageListener) { } //load video times for this video - let sponsorTimesStorage = Config.config.sponsorTimes.get(currentVideoID); + let sponsorTimesStorage = Config.config.segmentTimes.get(currentVideoID); if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { - if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) { + if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].segment.length < 2) { startTimeChosen = true; PageElements.sponsorStart.innerHTML = chrome.i18n.getMessage("sponsorEnd"); } @@ -336,13 +336,17 @@ async function runThePopup(messageListener?: MessageListener) { let sponsorTimesIndex = sponsorTimes.length - (startTimeChosen ? 1 : 0); if (sponsorTimes[sponsorTimesIndex] == undefined) { - sponsorTimes[sponsorTimesIndex] = []; + sponsorTimes[sponsorTimesIndex] = { + segment: [], + category: "sponsor", + UUID: null + }; } - sponsorTimes[sponsorTimesIndex][startTimeChosen ? 1 : 0] = response.time; + sponsorTimes[sponsorTimesIndex].segment[startTimeChosen ? 1 : 0] = response.time; let localStartTimeChosen = startTimeChosen; - Config.config.sponsorTimes.set(currentVideoID, sponsorTimes); + Config.config.segmentTimes.set(currentVideoID, sponsorTimes); //send a message to the client script if (localStartTimeChosen) { @@ -528,7 +532,7 @@ async function runThePopup(messageListener?: MessageListener) { } function previewSponsorTime(index) { - let skipTime = sponsorTimes[index][0]; + let skipTime = sponsorTimes[index].segment[0]; if (document.getElementById("startTimeMinutes" + index) != null) { //edit is currently open, use that time @@ -575,28 +579,28 @@ async function runThePopup(messageListener?: MessageListener) { startTimeMinutes.id = "startTimeMinutes" + index; startTimeMinutes.className = "sponsorTime popupElement"; startTimeMinutes.type = "text"; - startTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index][0])); + startTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index].segment[0])); startTimeMinutes.style.width = "45px"; let startTimeSeconds = document.createElement("input"); startTimeSeconds.id = "startTimeSeconds" + index; startTimeSeconds.className = "sponsorTime popupElement"; startTimeSeconds.type = "text"; - startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]); + startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index].segment[0]); startTimeSeconds.style.width = "60px"; let endTimeMinutes = document.createElement("input"); endTimeMinutes.id = "endTimeMinutes" + index; endTimeMinutes.className = "sponsorTime popupElement"; endTimeMinutes.type = "text"; - endTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index][1])); + endTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index].segment[1])); endTimeMinutes.style.width = "45px"; let endTimeSeconds = document.createElement("input"); endTimeSeconds.id = "endTimeSeconds" + index; endTimeSeconds.className = "sponsorTime popupElement"; endTimeSeconds.type = "text"; - endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]); + endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index].segment[1]); endTimeSeconds.style.width = "60px"; //the button to set the current time @@ -668,11 +672,11 @@ async function runThePopup(messageListener?: MessageListener) { } function saveSponsorTimeEdit(index, closeEditMode = true) { - sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index); - sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index); + sponsorTimes[index].segment[0] = getSponsorTimeEditTimes("startTime", index); + sponsorTimes[index].segment[1] = getSponsorTimeEditTimes("endTime", index); //save this - Config.config.sponsorTimes.set(currentVideoID, sponsorTimes); + Config.config.segmentTimes.set(currentVideoID, sponsorTimes); messageHandler.query({ active: true, @@ -692,7 +696,7 @@ async function runThePopup(messageListener?: MessageListener) { //deletes the sponsor time submitted at an index function deleteSponsorTime(index) { //if it is not a complete sponsor time - if (sponsorTimes[index].length < 2) { + if (sponsorTimes[index].segment.length < 2) { messageHandler.query({ active: true, currentWindow: true @@ -710,7 +714,7 @@ async function runThePopup(messageListener?: MessageListener) { sponsorTimes.splice(index, 1); //save this - Config.config.sponsorTimes.set(currentVideoID, sponsorTimes); + Config.config.segmentTimes.set(currentVideoID, sponsorTimes); //if they are all removed if (sponsorTimes.length == 0) { @@ -780,7 +784,7 @@ async function runThePopup(messageListener?: MessageListener) { //hides and shows the submit times button when needed function showSubmitTimesIfNecessary() { //check if an end time has been specified for the latest sponsor time - if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length > 1) { + if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].segment.length > 1) { //show submit times button document.getElementById("submitTimesContainer").style.display = "unset"; } else { -- cgit v1.2.3 From 037bd511b085efcd2db292b624ac8eed42cb7e9e Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 19:07:05 -0400 Subject: Remove keybind restriction. Closes https://github.com/ajayyy/SponsorBlock/issues/379 --- public/_locales/en/messages.json | 3 --- src/options.ts | 9 --------- 2 files changed, 12 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index ff63a4f7..91a2cb24 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -466,9 +466,6 @@ "theKey": { "message": "The key" }, - "keyAlreadyUsedByYouTube": { - "message": "is already used by youtube. Please select another key." - }, "keyAlreadyUsed": { "message": "is bound to another action. Please select another key." }, diff --git a/src/options.ts b/src/options.ts index a0d3ccd9..5e184505 100644 --- a/src/options.ts +++ b/src/options.ts @@ -362,15 +362,6 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) { let button: HTMLElement = element.querySelector(".trigger-button"); let option = element.getAttribute("sync-option"); - // Don't allow keys which are already listened for by youtube - let restrictedKeys = "1234567890,.jklftcibmJKLFTCIBMNP/<> -+"; - if (restrictedKeys.indexOf(key) !== -1 ) { - closeKeybindOption(element, button); - - alert(chrome.i18n.getMessage("theKey") + " " + key + " " + chrome.i18n.getMessage("keyAlreadyUsedByYouTube")); - return; - } - // Make sure keybind isn't used by the other listener // TODO: If other keybindings are going to be added, we need a better way to find the other keys used. let otherKeybind = (option === "startSponsorKeybind") ? Config.config['submitKeybind'] : Config.config['startSponsorKeybind']; -- cgit v1.2.3 From e55d1f51155e9d4987872fbe7dd0b2b544a63a54 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 19:31:00 -0400 Subject: Removed intermission category and renamed intro to intermission. --- config.json.example | 2 +- public/_locales/en/messages.json | 12 +++--------- src/config.ts | 10 ---------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/config.json.example b/config.json.example index 3fabce07..09cf2bba 100644 --- a/config.json.example +++ b/config.json.example @@ -2,5 +2,5 @@ "serverAddress": "https://sponsor.ajay.app", "testingServerAddress": "https://sponsor.ajay.app/test", "serverAddressComment": "This specifies the default SponsorBlock server to connect to", - "categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "intermission", "music_offtopic"] + "categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "music_offtopic"] } diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 91a2cb24..5cbbaf57 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -480,13 +480,13 @@ "message": "Paid promotion, paid referrals and direct advertisements. Not for self-promotion or free shoutouts to causes/creators/websites/products they like." }, "category_intro": { - "message": "Intro Animation" + "message": "Intermission/Intro Animation" }, "category_intro_description": { - "message": "Intro animations that are recurring in the series or provide no direct value. This should not be used on music videos." + "message": "An interval without actual content. Could be a pause, static frame, repeating animation. This should not be used for transitions containing information or be used on music videos." }, "category_intro_short": { - "message": "Intro" + "message": "Intermission" }, "category_outro": { "message": "Endcards/Credits" @@ -509,12 +509,6 @@ "category_selfpromo_description": { "message": "Similar to \"sponsor\" except for unpaid or self promotion. This includes sections about merchandise, donations, or information about who they collaborated with." }, - "category_intermission": { - "message": "Intermission" - }, - "category_intermission_description": { - "message": "An interval without actual content. Could be a pause, static frame, or repeating animation in the video. Should not be used for pauses or transitions with actual content." - }, "category_music_offtopic": { "message": "Music: Non-Music Section" }, diff --git a/src/config.ts b/src/config.ts index 54db3c0a..a1b70bd0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -49,8 +49,6 @@ interface SBConfig { "preview-interaction": PreviewBarOption, "selfpromo": PreviewBarOption, "preview-selfpromo": PreviewBarOption, - "intermission": PreviewBarOption, - "preview-intermission": PreviewBarOption "music_offtopic": PreviewBarOption, "preview-music_offtopic": PreviewBarOption, } @@ -203,14 +201,6 @@ var Config: SBObject = { color: "#bfbf35", opacity: "0.7" }, - "intermission": { - color: "#45a8ff", - opacity: "0.7" - }, - "preview-intermission": { - color: "#0066bf", - opacity: "0.7" - }, "music_offtopic": { color: "#ff9900", opacity: "0.7" -- cgit v1.2.3 From 809de0e0fd6b10b5f2d91ecd83df00cfd118ec84 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 19:31:18 -0400 Subject: Increased version number --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 08e507fb..d2626d74 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "SponsorBlock", - "version": "2.0.2.2", + "version": "2.0.3", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [{ -- cgit v1.2.3 From c69047c7f9d801f94914f2ef498fdd30b688d944 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 3 Jul 2020 21:16:38 -0400 Subject: Show short names when hovering the preview bar --- src/js-components/previewBar.ts | 6 ++++-- src/utils.ts | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index e0931d91..bef397c1 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -6,6 +6,8 @@ 'use strict'; import Config from "../config"; +import Utils from "../utils"; +let utils = new Utils(); class PreviewBar { container: HTMLUListElement; @@ -79,8 +81,8 @@ class PreviewBar { tooltipTextWrapper.classList.remove("sbTooltipOneTitleThumbnailOffset"); } else if (category !== null) { categoryTooltip.classList.remove("sbHidden"); - categoryTooltip.textContent = chrome.i18n.getMessage("category_" + category) - || (chrome.i18n.getMessage("preview") + " " + chrome.i18n.getMessage("category_" + category.split("preview-")[1])); + categoryTooltip.textContent = utils.shortCategoryName(category) + || (chrome.i18n.getMessage("preview") + " " + utils.shortCategoryName(category.split("preview-")[1])); // There is a title now tooltip.classList.remove("ytp-tooltip-text-no-title"); diff --git a/src/utils.ts b/src/utils.ts index db766772..ceaefeda 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -350,6 +350,10 @@ class Utils { return formatted; } + shortCategoryName(categoryName: string): string { + return chrome.i18n.getMessage("category_" + categoryName + "_short") || chrome.i18n.getMessage("category_" + categoryName); + } + getRawSeconds(minutes: number, seconds: number): number { return minutes * 60 + seconds; } -- cgit v1.2.3