From 44bc8741ef1e85fd38da5f56a77512ed4243c660 Mon Sep 17 00:00:00 2001 From: Michael C Date: Fri, 31 Dec 2021 22:56:46 -0500 Subject: [PATCH] fix UI issues with embeds - add loadStart trigger to create & update preview and buttons - show info button on /embed/ but not /channel/ --- src/content.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/content.ts b/src/content.ts index 0730d59a..b72979ff 100644 --- a/src/content.ts +++ b/src/content.ts @@ -399,6 +399,16 @@ function durationChangeListener(): void { updatePreviewBar(); } +/** + * Triggered once the video is ready. + * This is mainly to attach to embedded players who don't have a video element visible. + */ +function videoOnReadyListener(): void { + createPreviewBar(); + updatePreviewBar(); + createButtons(); +} + function cancelSponsorSchedule(): void { if (currentSkipSchedule !== null) { clearTimeout(currentSkipSchedule); @@ -564,6 +574,7 @@ function refreshVideoAttachments() { function setupVideoListeners() { //wait until it is loaded + video.addEventListener('loadstart', videoOnReadyListener) video.addEventListener('durationchange', durationChangeListener); if (!Config.config.disableSkipping) { @@ -905,17 +916,19 @@ function getYouTubeVideoID(document: Document): string | boolean { const url = document.URL; // skip to URL if matches youtube watch or invidious or matches youtube pattern if ((!url.includes("youtube.com")) || url.includes("/watch") || url.includes("/shorts/") || url.includes("playlist")) return getYouTubeVideoIDFromURL(url); + // skip to document and don't hide if on /embed/ + if (url.includes("/embed/")) return getYouTubeVideoIDFromDocument(document, false); // skip to document if matches pattern - if (url.includes("/channel/") || url.includes("/user/") || url.includes("/c/") || url.includes("/embed/")) return getYouTubeVideoIDFromDocument(document); + if (url.includes("/channel/") || url.includes("/user/") || url.includes("/c/")) return getYouTubeVideoIDFromDocument(document); // not sure, try URL then document return getYouTubeVideoIDFromURL(url) || getYouTubeVideoIDFromDocument(document); } -function getYouTubeVideoIDFromDocument(document: Document): string | boolean { +function getYouTubeVideoIDFromDocument(document: Document, hideIcon = true): string | boolean { // get ID from document (channel trailer / embedded playlist) const videoURL = document.querySelector("[data-sessionlink='feature=player-title']")?.getAttribute("href"); if (videoURL) { - onInvidious = true; + onInvidious = hideIcon; return getYouTubeVideoIDFromURL(videoURL); } else { return false