diff options
author | Ajay Ramachandran <[email protected]> | 2020-04-26 23:14:18 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-04-26 23:14:18 -0400 |
commit | fbafb723cb187da2470afacff62b49bf018cd664 (patch) | |
tree | fba0586997664566ada5511550c01cd2b8103dc0 | |
parent | 797fbf563b1cd851ec950801f158c63af61117d3 (diff) | |
download | SponsorBlock-fbafb723cb187da2470afacff62b49bf018cd664.tar.gz SponsorBlock-fbafb723cb187da2470afacff62b49bf018cd664.zip |
Added option to force a whitelist check before allowing skipping.
-rw-r--r-- | public/_locales/en/messages.json | 9 | ||||
-rw-r--r-- | public/popup.html | 4 | ||||
-rw-r--r-- | src/config.ts | 2 | ||||
-rw-r--r-- | src/content.ts | 62 | ||||
-rw-r--r-- | src/popup.ts | 7 |
5 files changed, 57 insertions, 27 deletions
diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 5183631f..c524c7d0 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -549,5 +549,14 @@ }, "itCouldBeAdblockerIssue": { "message": "If this keeps occuring, it could be caused by your ad blocker. Please check https://github.com/ajayyy/SponsorBlock/wiki/Fix-Ad-Blocker-Blocking-SponsorBlock's-Requests" + }, + "forceChannelCheck": { + "message": "Force Channel Check Before Skipping Sponsors" + }, + "whatForceChannelCheck": { + "message": "By default, it will skip sponsors right away before it even knows what the channel is. By default, some zero second sponsors might be skipped on whitelisted channels. Enabling this option will prevent this but making all skipping have a slight delay as getting the channelID can take some time. This delay might be unnoticeable if you have fast internet." + }, + "forceChannelCheckPopup": { + "message": "Consider Enabling Force Channel Check Before Skipping Sponsors" } } diff --git a/public/popup.html b/public/popup.html index 05ace54f..3fdb3a73 100644 --- a/public/popup.html +++ b/public/popup.html @@ -71,6 +71,10 @@ <button id="whitelistChannel" class="whitelistButton popupElement">__MSG_whitelistChannel__</button> <button id="unwhitelistChannel" class="whitelistButton popupElement" style="display: none">__MSG_removeFromWhitelist__</button> + + <div id="whitelistForceCheck" style="text-decoration: underline; cursor: pointer;display: none"> + __MSG_forceChannelCheckPopup__ + </div> </div> <br/> diff --git a/src/config.ts b/src/config.ts index 9d69e681..70263d5a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,6 +8,7 @@ interface SBConfig { userID: string, sponsorTimes: SBMap<string, any>, whitelistedChannels: string[], + forceChannelCheck: boolean, startSponsorKeybind: string, submitKeybind: string, minutesSaved: number, @@ -107,6 +108,7 @@ var Config: SBObject = { userID: null, sponsorTimes: new SBMap("sponsorTimes"), whitelistedChannels: [], + forceChannelCheck: false, startSponsorKeybind: ";", submitKeybind: "'", minutesSaved: 0, diff --git a/src/content.ts b/src/content.ts index 83df8952..758a5bb4 100644 --- a/src/content.ts +++ b/src/content.ts @@ -463,7 +463,7 @@ function startSponsorSchedule(includeIntersectingSegments: boolean = false, curr cancelSponsorSchedule(); if (video.paused) return; - if (Config.config.disableSkipping || channelWhitelisted){ + if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){ return; } @@ -637,30 +637,7 @@ function sponsorsLookup(id: string) { } } - if (!switchingVideos) { - // See if there are any starting sponsors - let startingSponsor: number = -1; - for (const time of sponsorTimes) { - if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) { - startingSponsor = time.segment[0]; - break; - } - } - if (startingSponsor === -1) { - for (const time of sponsorTimesSubmitting) { - if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) { - startingSponsor = time.segment[0]; - break; - } - } - } - - if (startingSponsor !== -1) { - startSponsorSchedule(false, startingSponsor); - } else { - startSponsorSchedule(); - } - } + startSkipScheduleCheckingForStartSponsors(); // Reset skip save sponsorSkipped = []; @@ -702,6 +679,38 @@ function sponsorsLookup(id: string) { } /** + * Only should be used when it is okay to skip a sponsor when in the middle of it + * + * Ex. When segments are first loaded + */ +function startSkipScheduleCheckingForStartSponsors() { + if (!switchingVideos) { + // See if there are any starting sponsors + let startingSponsor: number = -1; + for (const time of sponsorTimes) { + if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) { + startingSponsor = time.segment[0]; + break; + } + } + if (startingSponsor === -1) { + for (const time of sponsorTimesSubmitting) { + if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) { + startingSponsor = time.segment[0]; + break; + } + } + } + + if (startingSponsor !== -1) { + startSponsorSchedule(false, startingSponsor); + } else { + startSponsorSchedule(); + } + } +} + +/** * Get the video info for the current tab from YouTube */ function getVideoInfo() { @@ -807,6 +816,9 @@ function whitelistCheck() { if (whitelistedChannels != undefined && whitelistedChannels.includes(channelID)) { channelWhitelisted = true; } + + // check if the start of segments were missed + if (sponsorTimes && sponsorTimes.length > 0) startSkipScheduleCheckingForStartSponsors(); } /** diff --git a/src/popup.ts b/src/popup.ts index 93ab75ca..914dddc5 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -51,6 +51,7 @@ async function runThePopup(messageListener?: MessageListener) { // Top toggles "whitelistChannel", "unwhitelistChannel", + "whitelistForceCheck", "disableSkipping", "enableSkipping", // Options @@ -102,6 +103,7 @@ async function runThePopup(messageListener?: MessageListener) { //setup click listeners PageElements.sponsorStart.addEventListener("click", sendSponsorStartMessage); PageElements.whitelistChannel.addEventListener("click", whitelistChannel); + PageElements.whitelistForceCheck.addEventListener("click", openOptions); PageElements.unwhitelistChannel.addEventListener("click", unwhitelistChannel); PageElements.disableSkipping.addEventListener("click", () => toggleSkipping(true)); PageElements.enableSkipping.addEventListener("click", () => toggleSkipping(false)); @@ -939,6 +941,7 @@ async function runThePopup(messageListener?: MessageListener) { //change button PageElements.whitelistChannel.style.display = "none"; PageElements.unwhitelistChannel.style.display = "unset"; + if (!Config.config.forceChannelCheck) PageElements.whitelistForceCheck.style.display = "unset"; PageElements.downloadedSponsorMessageTimes.innerText = chrome.i18n.getMessage("channelWhitelisted"); PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold"; @@ -971,7 +974,7 @@ async function runThePopup(messageListener?: MessageListener) { }, tabs => { messageHandler.sendMessage( tabs[0].id, - {message: 'getChannelURL'}, + {message: 'getChannelID'}, function(response) { //get whitelisted channels let whitelistedChannels = Config.config.whitelistedChannels; @@ -980,7 +983,7 @@ async function runThePopup(messageListener?: MessageListener) { } //remove this channel - let index = whitelistedChannels.indexOf(response.channelURL); + let index = whitelistedChannels.indexOf(response.channelID); whitelistedChannels.splice(index, 1); //change button |