diff options
author | Ajay Ramachandran <[email protected]> | 2021-08-03 15:19:29 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-08-03 15:19:29 -0400 |
commit | a56bba06124fb5e30139e796646f01322a9292ab (patch) | |
tree | 6c36d6875f0daf79669f8940a9df6ff3ef2fd746 | |
parent | afeba5f0771e7f784a4c46010665f42933534f25 (diff) | |
download | SponsorBlock-a56bba06124fb5e30139e796646f01322a9292ab.tar.gz SponsorBlock-a56bba06124fb5e30139e796646f01322a9292ab.zip |
Add skipping all segments when a non music segment exists
-rw-r--r-- | public/_locales/en/messages.json | 3 | ||||
-rw-r--r-- | public/options/options.html | 16 | ||||
-rw-r--r-- | src/config.ts | 14 | ||||
-rw-r--r-- | src/content.ts | 13 |
4 files changed, 42 insertions, 4 deletions
diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index e3c22e40..bb6dac47 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -559,6 +559,9 @@ "showOverlay": { "message": "Show In Seek Bar" }, + "autoSkipOnMusicVideos": { + "message": "Auto skip all segments when there is a non-music segment" + }, "colorFormatIncorrect": { "message": "Your color is formatted incorrectly. It should be a 3 or 6 digit hex code with a number sign at the beginning." }, diff --git a/public/options/options.html b/public/options/options.html index 405b5de7..52bce8e2 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -29,6 +29,22 @@ </div> + <div option-type="toggle" sync-option="autoSkipOnMusicVideos"> + <label class="switch-container"> + <label class="switch"> + <input type="checkbox" checked> + <span class="slider round"></span> + </label> + <div class="switch-label"> + __MSG_autoSkipOnMusicVideos__ + </div> + </label> + + <br/> + <br/> + <br/> + </div> + <br/> <br/> diff --git a/src/config.ts b/src/config.ts index 6e7e4248..bc920d5a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -41,6 +41,7 @@ interface SBConfig { ytInfoPermissionGranted: boolean, allowExpirements: boolean, autoHideInfoButton: boolean, + autoSkipOnMusicVideos: boolean, // What categories should be skipped categorySelections: CategorySelection[], @@ -180,6 +181,7 @@ const Config: SBObject = { ytInfoPermissionGranted: false, allowExpirements: true, autoHideInfoButton: true, + autoSkipOnMusicVideos: false, categorySelections: [{ name: "sponsor", @@ -347,6 +349,18 @@ function migrateOldFormats(config: SBConfig) { chrome.storage.sync.remove("askAboutUnlistedVideos"); } + if (!config["autoSkipOnMusicVideosUpdate"]) { + config["autoSkipOnMusicVideosUpdate"] = true; + for (const selection of config.categorySelections) { + if (selection.name === "music_offtopic" + && selection.option === CategorySkipOption.AutoSkip) { + + config.autoSkipOnMusicVideos = true; + break; + } + } + } + // Adding preview category if (!config["previewCategoryUpdate"]) { config["previewCategoryUpdate"] = true; diff --git a/src/content.ts b/src/content.ts index e86738b6..e8746a9f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -426,7 +426,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?: skippingSegments = []; for (const segment of skipInfo.array) { - if (utils.getCategorySelection(segment.category).option === CategorySkipOption.AutoSkip && + if (shouldAutoSkip(segment) && segment.segment[0] >= skipTime[0] && segment.segment[1] <= skipTime[1]) { skippingSegments.push(segment); } @@ -927,7 +927,7 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideHiddenSponsors = true): number { // Only combine segments for AutoSkip if (index == -1 || - utils.getCategorySelection(sponsorTimes[index].category)?.option !== CategorySkipOption.AutoSkip) return index; + shouldAutoSkip(sponsorTimes[index])) return index; // Default to the normal endTime let latestEndTimeIndex = index; @@ -938,7 +938,7 @@ function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideH if (currentSegment[0] <= latestEndTime && currentSegment[1] > latestEndTime && (!hideHiddenSponsors || sponsorTimes[i].hidden === SponsorHideType.Visible) - && utils.getCategorySelection(sponsorTimes[i].category).option === CategorySkipOption.AutoSkip) { + && shouldAutoSkip(sponsorTimes[i])) { // Overlapping segment latestEndTimeIndex = i; } @@ -1019,7 +1019,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped: //skip from the start time to the end time for a certain index sponsor time function skipToTime(v: HTMLVideoElement, skipTime: number[], skippingSegments: SponsorTime[], openNotice: boolean) { // There will only be one submission if it is manual skip - const autoSkip: boolean = utils.getCategorySelection(skippingSegments[0].category)?.option === CategorySkipOption.AutoSkip; + const autoSkip: boolean = shouldAutoSkip(skippingSegments[0]); if ((autoSkip || sponsorTimesSubmitting.includes(skippingSegments[0])) && v.currentTime !== skipTime[1]) { // Fix for looped videos not working when skipping to the end #426 @@ -1097,6 +1097,11 @@ function createButton(baseID: string, title: string, callback: () => void, image return newButton; } +function shouldAutoSkip(segment: SponsorTime): boolean { + return utils.getCategorySelection(segment.category)?.option === CategorySkipOption.AutoSkip || + (Config.config.autoSkipOnMusicVideos && sponsorTimes.some((s) => s.category === "music_offtopic")); +} + function getControls(): HTMLElement | false { const controlsSelectors = [ // YouTube |