From cfa8eee19352e9dbdf23872def6d815ca7fc40c8 Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 27 Nov 2024 23:54:09 -0500 Subject: Fix full video label sometimes not appearing when you open a video in a background tab --- maze-utils | 2 +- src/content.ts | 8 +++++--- src/render/CategoryPill.tsx | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/maze-utils b/maze-utils index 67700871..7a49dc6d 160000 --- a/maze-utils +++ b/maze-utils @@ -1 +1 @@ -Subproject commit 6770087140715ab4f7d298add61770da63157b73 +Subproject commit 7a49dc6d5e77e53c6f4c57299012134bd0d7f50b diff --git a/src/content.ts b/src/content.ts index 222f9514..2cb5f6a2 100644 --- a/src/content.ts +++ b/src/content.ts @@ -35,7 +35,7 @@ import { ChapterVote } from "./render/ChapterVote"; import { openWarningDialog } from "./utils/warnings"; import { isFirefoxOrSafari, waitFor } from "../maze-utils/src"; import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating"; -import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube, getLastNonInlineVideoID, triggerVideoIDChange, triggerVideoElementChange, getIsInline, getCurrentTime, setCurrentTime, getVideoDuration, verifyCurrentTime } from "../maze-utils/src/video"; +import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube, getLastNonInlineVideoID, triggerVideoIDChange, triggerVideoElementChange, getIsInline, getCurrentTime, setCurrentTime, getVideoDuration, verifyCurrentTime, waitForVideo } from "../maze-utils/src/video"; import { Keybind, StorageChangesObject, isSafari, keybindEquals, keybindToString } from "../maze-utils/src/config"; import { findValidElement } from "../maze-utils/src/dom" import { getHash, HashedValue } from "../maze-utils/src/hash"; @@ -1230,7 +1230,7 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreCache = false) { if (!getVideo()) { //there is still no video here - await waitFor(() => getVideo(), 5000, 10); + await waitForVideo(); } startSkipScheduleCheckingForStartSponsors(); @@ -1375,7 +1375,9 @@ function startSkipScheduleCheckingForStartSponsors() { const fullVideoSegment = sponsorTimes.filter((time) => time.actionType === ActionType.Full)[0]; if (fullVideoSegment) { - categoryPill?.setSegment(fullVideoSegment); + waitFor(() => categoryPill).then(() => { + categoryPill?.setSegment(fullVideoSegment); + }); } if (startingSegmentTime !== -1) { diff --git a/src/render/CategoryPill.tsx b/src/render/CategoryPill.tsx index 20923fba..3a11e09c 100644 --- a/src/render/CategoryPill.tsx +++ b/src/render/CategoryPill.tsx @@ -43,7 +43,7 @@ export class CategoryPill { } private async attachToPageInternal(): Promise { - let referenceNode = + let referenceNode = await waitFor(() => getYouTubeTitleNode()); // Experimental YouTube layout with description on right @@ -119,6 +119,8 @@ export class CategoryPill { } async setSegment(segment: SponsorTime): Promise { + await waitFor(() => this.ref.current); + if (this.ref.current?.state?.segment !== segment) { const newState = { segment, -- cgit v1.2.3