diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.ts | 4 | ||||
-rw-r--r-- | src/content.ts | 6 | ||||
-rw-r--r-- | src/js-components/previewBar.ts | 11 | ||||
-rw-r--r-- | src/utils.ts | 4 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/config.ts b/src/config.ts index f74edd5e..f1692344 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,7 +9,7 @@ interface SBConfig { /* Contains unsubmitted segments that the user has created. */ unsubmittedSegments: Record<string, SponsorTime[]>, defaultCategory: Category, - renderAsChapters: boolean, + renderSegmentsAsChapters: boolean, whitelistedChannels: string[], forceChannelCheck: boolean, minutesSaved: number, @@ -132,7 +132,7 @@ const Config: SBObject = { isVip: false, unsubmittedSegments: {}, defaultCategory: "chooseACategory" as Category, - renderAsChapters: true, + renderSegmentsAsChapters: true, whitelistedChannels: [], forceChannelCheck: false, minutesSaved: 0, diff --git a/src/content.ts b/src/content.ts index 09137e0f..cb52983f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -958,7 +958,11 @@ async function sponsorsLookup(keepOldSubmissions = true) { } function importExistingChapters(wait: boolean) { - if (Config.config.renderAsChapters && !existingChaptersImported + const containsChapter = sponsorTimes?.some((segment) => segment.actionType === ActionType.Chapter) + || sponsorTimesSubmitting.some((segment) => segment.actionType === ActionType.Chapter); + + if ((Config.config.renderSegmentsAsChapters || containsChapter) + && !existingChaptersImported && (sponsorTimes?.length > 0 || sponsorTimesSubmitting.length > 0)) { GenericUtils.wait(() => video && getExistingChapters(sponsorVideoID, video.duration), wait ? 5000 : 0, 100, (c) => c?.length > 0).then((chapters) => { diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 9f587b42..b93ba60f 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -220,7 +220,8 @@ class PreviewBar { this.createChaptersBar(segments.sort((a, b) => a.segment[0] - b.segment[0])); const chapterChevron = document.querySelector(".ytp-chapter-title-chevron") as HTMLElement; - if (!Config.config.renderAsChapters || segments.some((segment) => segment.source === SponsorSourceType.YouTube)) { + if (!Config.config.renderSegmentsAsChapters + || segments.some((segment) => segment.source === SponsorSourceType.YouTube)) { chapterChevron.style.removeProperty("display"); } else { chapterChevron.style.display = "none"; @@ -243,8 +244,7 @@ class PreviewBar { bar.style.position = "absolute"; const duration = Math.min(segment[1], this.videoDuration) - segment[0]; if (duration > 0) { - bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${ - Config.config.renderAsChapters && this.chapterFilter(barSegment) ? ' - 2px' : ''})`; + bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${this.chapterFilter(barSegment) ? ' - 2px' : ''})`; } const time = segment[1] ? Math.min(this.videoDuration, segment[0]) : segment[0]; @@ -258,7 +258,7 @@ class PreviewBar { const chapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement; if (!progressBar || !chapterBar || chapterBar.childElementCount <= 0) return; - if (!Config.config.renderAsChapters) { + if (!Config.config.renderSegmentsAsChapters && segments.every((segment) => segment.actionType !== ActionType.Chapter)) { if (this.customChaptersBar) this.customChaptersBar.style.display = "none"; chapterBar.style.removeProperty("display"); return; @@ -649,7 +649,8 @@ class PreviewBar { } private chapterFilter(segment: PreviewBarSegment): boolean { - return segment.actionType !== ActionType.Poi + return (Config.config.renderSegmentsAsChapters || segment.actionType === ActionType.Chapter) + && segment.actionType !== ActionType.Poi && this.chapterGroupFilter(segment); } diff --git a/src/utils.ts b/src/utils.ts index cda228fe..d7e6fcf8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -440,8 +440,4 @@ export default class Utils { Config.forceLocalUpdate("downvotedSegments"); } - - chaptersEnabled(): boolean { - return Config.config.renderAsChapters && !!this.getCategorySelection("chapter"); - } } |