diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 59b4484f7..0a93d9c90 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -52,6 +52,7 @@ class PreviewBar { progressBar: HTMLElement; segments: PreviewBarSegment[] = []; + hasYouTubeChapters = false; existingChapters: PreviewBarSegment[] = []; videoDuration = 0; updateExistingChapters: () => void; @@ -136,7 +137,7 @@ class PreviewBar { // Find the segment at that location, using the shortest if multiple found const [normalSegments, chapterSegments] = - partition(this.segments.filter((s) => s.source !== SponsorSourceType.YouTube), + partition(this.segments, (segment) => segment.actionType !== ActionType.Chapter); let mainSegment = this.getSmallestSegment(timeInSeconds, normalSegments, "normal"); let secondarySegment = this.getSmallestSegment(timeInSeconds, chapterSegments, "chapter"); @@ -145,9 +146,19 @@ class PreviewBar { secondarySegment = this.getSmallestSegment(timeInSeconds, chapterSegments.filter((s) => s !== secondarySegment)); } + const hasAYouTubeChapterRemoved = this.hasYouTubeChapters + || (!Config.config.showAutogeneratedChapters && hasAutogeneratedChapters()); + if (hasAYouTubeChapterRemoved) { + // Hide original tooltip if some chapter has been filtered out + originalTooltip.style.display = "none"; + noYoutubeChapters = true; + } + if (mainSegment === null && secondarySegment === null) { - this.categoryTooltipContainer.classList.remove(TOOLTIP_VISIBLE_CLASS); - originalTooltip.style.removeProperty("display"); + if (!hasAYouTubeChapterRemoved) { + this.categoryTooltipContainer.classList.remove(TOOLTIP_VISIBLE_CLASS); + originalTooltip.style.removeProperty("display"); + } } else { this.categoryTooltipContainer.classList.add(TOOLTIP_VISIBLE_CLASS); if (mainSegment !== null && secondarySegment !== null) { @@ -172,16 +183,16 @@ class PreviewBar { originalTooltip.style.removeProperty("display"); } - // Used to prevent overlapping - this.categoryTooltip.classList.toggle("ytp-tooltip-text-no-title", noYoutubeChapters); - this.chapterTooltip.classList.toggle("ytp-tooltip-text-no-title", noYoutubeChapters); - // To prevent offset issue this.categoryTooltip.style.right = titleTooltip.style.right; this.chapterTooltip.style.right = titleTooltip.style.right; this.categoryTooltip.style.textAlign = titleTooltip.style.textAlign; this.chapterTooltip.style.textAlign = titleTooltip.style.textAlign; } + + // Used to prevent overlapping + this.categoryTooltip.classList.toggle("ytp-tooltip-text-no-title", noYoutubeChapters); + this.chapterTooltip.classList.toggle("ytp-tooltip-text-no-title", noYoutubeChapters); }); } @@ -232,6 +243,7 @@ class PreviewBar { set(segments: PreviewBarSegment[], videoDuration: number): void { this.segments = segments ?? []; this.videoDuration = videoDuration ?? 0; + this.hasYouTubeChapters = segments.some((segment) => segment.source === SponsorSourceType.YouTube); // Remove unnecessary original chapters if submitted replacements exist for (const chapter of this.segments.filter((s) => s.actionType === ActionType.Chapter && s.source === SponsorSourceType.Server)) {