From 9b152a552505b561f4a68ad33e431c0b2c2d1ab8 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 28 Dec 2021 12:52:48 -0500 Subject: [PATCH] Fix preview bar not being recreated --- src/content.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index c8dd4ac6..881765e7 100644 --- a/src/content.ts +++ b/src/content.ts @@ -87,6 +87,7 @@ const playerButtons: Record Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document))); +addPageListeners(); addHotkeyListener(); //the amount of times the sponsor lookup has retried @@ -377,7 +378,7 @@ function createPreviewBar(): void { ]; for (const selector of progressElementSelectors) { - const el = document.querySelector(selector); + const el = findValidElement(document.querySelectorAll(selector)); if (el) { previewBar = new PreviewBar(el, onMobileYouTube, onInvidious); @@ -550,6 +551,14 @@ function refreshVideoAttachments() { setupVideoListeners(); setupSkipButtonControlBar(); } + + // Create a new bar in the new video element + if (previewBar && !utils.findReferenceNode()?.contains(previewBar.container)) { + previewBar.remove(); + previewBar = null; + + createPreviewBar(); + } } } @@ -1843,6 +1852,16 @@ function getSegmentsMessage(sponsorTimes: SponsorTime[]): string { return sponsorTimesMessage; } +function addPageListeners(): void { + const refreshListners = () => { + if (!isVisible(video)) { + refreshVideoAttachments(); + } + }; + + document.addEventListener("yt-navigate-finish", refreshListners); +} + function addHotkeyListener(): void { document.addEventListener("keydown", hotkeyListener); }