diff --git a/src/content.ts b/src/content.ts index 57877380..4f87f39a 100644 --- a/src/content.ts +++ b/src/content.ts @@ -17,7 +17,7 @@ import { getCategoryActionType } from "./utils/categoryUtils"; import { SkipButtonControlBar } from "./js-components/skipButtonControlBar"; import { Tooltip } from "./render/Tooltip"; import { getStartTimeFromUrl } from "./utils/urlParser"; -import { findValidElement, getControls, getHashParams, isVisible } from "./utils/pageUtils"; +import { findValidElement, getControls, getHashParams, isVisible, getHoverPreview } from "./utils/pageUtils"; import { CategoryPill } from "./render/CategoryPill"; import { AnimationUtils } from "./utils/animationUtils"; import { GenericUtils } from "./utils/genericUtils"; @@ -92,6 +92,8 @@ const playerButtons: Record Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document))); +// wait infinitely for hover preview +utils.wait(() => getHoverPreview(), 0, 500).then(() => refreshVideoAttachments()) addPageListeners(); addHotkeyListener(); diff --git a/src/utils/genericUtils.ts b/src/utils/genericUtils.ts index b146e57a..ad44827b 100644 --- a/src/utils/genericUtils.ts +++ b/src/utils/genericUtils.ts @@ -1,10 +1,11 @@ /** Function that can be used to wait for a condition before returning. */ async function wait(condition: () => T | false, timeout = 5000, check = 100): Promise { return await new Promise((resolve, reject) => { - setTimeout(() => { + const failTimeout = setTimeout(() => { clearInterval(interval); reject("TIMEOUT"); }, timeout); + if (timeout === 0) clearTimeout(failTimeout); const intervalCheck = () => { const result = condition(); diff --git a/src/utils/pageUtils.ts b/src/utils/pageUtils.ts index 28ac37d8..0a5d7a37 100644 --- a/src/utils/pageUtils.ts +++ b/src/utils/pageUtils.ts @@ -19,6 +19,11 @@ export function getControls(): HTMLElement | false { return false; } +export function getHoverPreview(): Element | false { + const hoverPreview = document.querySelector(".ytp-inline-preview-ui"); + return hoverPreview || false; +} + export function isVisible(element: HTMLElement): boolean { return element && element.offsetWidth > 0 && element.offsetHeight > 0; }