diff options
author | Ajay <[email protected]> | 2024-12-08 20:02:32 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2024-12-08 20:02:32 -0500 |
commit | 15976777ed95699df46251f792d19f07a32ecb30 (patch) | |
tree | cc14f2d0441ad301f0a80f73275d6219ce913198 /src/js-components/previewBar.ts | |
parent | 9ad636fdadc5709d7205e81d12ae80334ed08a3a (diff) | |
download | SponsorBlock-15976777ed95699df46251f792d19f07a32ecb30.tar.gz SponsorBlock-15976777ed95699df46251f792d19f07a32ecb30.zip |
Add option to hide autogenerated chapters by YouTube
Diffstat (limited to 'src/js-components/previewBar.ts')
-rw-r--r-- | src/js-components/previewBar.ts | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 84c1e2fd..59b4484f 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -13,7 +13,7 @@ import { DEFAULT_CATEGORY, shortCategoryName } from "../utils/categoryUtils"; import { normalizeChapterName } from "../utils/exporter"; import { findValidElement } from "../../maze-utils/src/dom"; import { addCleanupListener } from "../../maze-utils/src/cleanup"; -import { isVisible } from "../utils/pageUtils"; +import { hasAutogeneratedChapters, isVisible } from "../utils/pageUtils"; import { isVorapisInstalled } from "../utils/compatibility"; const TOOLTIP_VISIBLE_CLASS = 'sponsorCategoryTooltipVisible'; @@ -365,11 +365,13 @@ class PreviewBar { // Merge overlapping chapters this.unfilteredChapterGroups = this.createChapterRenderGroups(segments); } - - if (segments.every((segments) => segments.source === SponsorSourceType.YouTube) + + if ((segments.every((segments) => segments.source === SponsorSourceType.YouTube) || (!Config.config.renderSegmentsAsChapters && segments.every((segment) => segment.actionType !== ActionType.Chapter - || segment.source === SponsorSourceType.YouTube))) { + || segment.source === SponsorSourceType.YouTube))) + && !(hasAutogeneratedChapters() && !Config.config.showAutogeneratedChapters)) { + if (this.customChaptersBar) this.customChaptersBar.style.display = "none"; this.originalChapterBar.style.removeProperty("display"); return; @@ -395,6 +397,15 @@ class PreviewBar { this.chapterGroups = this.unfilteredChapterGroups; } + if (this.chapterGroups.length === 0 && !Config.config.showAutogeneratedChapters && hasAutogeneratedChapters()) { + // Add placeholder chapter group for whole video + this.chapterGroups = [{ + segment: [0, this.videoDuration], + originalDuration: 0, + actionType: null + }]; + } + if (!this.chapterGroups || this.chapterGroups.length <= 0) { if (this.customChaptersBar) this.customChaptersBar.style.display = "none"; this.originalChapterBar.style.removeProperty("display"); @@ -787,7 +798,8 @@ class PreviewBar { updateChapterText(segments: SponsorTime[], submittingSegments: SponsorTime[], currentTime: number): SponsorTime[] { if (!Config.config.showSegmentNameInChapterBar || Config.config.disableSkipping - || ((!segments || segments.length <= 0) && submittingSegments?.length <= 0)) { + || ((!segments || segments.length <= 0) && submittingSegments?.length <= 0 + && (Config.config.showAutogeneratedChapters || !hasAutogeneratedChapters()))) { const chaptersContainer = this.getChaptersContainer(); if (chaptersContainer) { chaptersContainer.querySelector(".sponsorChapterText")?.remove(); @@ -875,6 +887,18 @@ class PreviewBar { } else { this.chapterVote.setVisibility(false); } + } else if (!Config.config.showAutogeneratedChapters && hasAutogeneratedChapters()) { + // Keep original hidden + chaptersContainer.querySelector(".sponsorChapterText")?.remove(); + const chapterTitle = chaptersContainer.querySelector(".ytp-chapter-title-content") as HTMLDivElement; + + chapterTitle.style.display = "none"; + chaptersContainer.classList.remove("sponsorblock-chapter-visible"); + + const titlePrefixDot = chaptersContainer.querySelector(".ytp-chapter-title-prefix") as HTMLElement; + if (titlePrefixDot) titlePrefixDot.style.display = "none"; + + this.chapterVote.setVisibility(false); } else { chaptersContainer.querySelector(".sponsorChapterText")?.remove(); const chapterTitle = chaptersContainer.querySelector(".ytp-chapter-title-content") as HTMLDivElement; |