From dc9c08f1fab285ee456c81fedca56348fd857ea3 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 24 Dec 2024 14:29:07 -0500 Subject: [PATCH] Fix chapter titles still showing on hover after they've been removed from the seek bar --- src/js-components/previewBar.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 59b4484f..0a93d9c9 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)) {