add infinite wait for hover preview

This commit is contained in:
Michael C
2022-01-19 01:47:43 -05:00
parent b210b22af3
commit e4aa7efd3c
3 changed files with 10 additions and 2 deletions

View File

@@ -17,7 +17,7 @@ import { getCategoryActionType } from "./utils/categoryUtils";
import { SkipButtonControlBar } from "./js-components/skipButtonControlBar"; import { SkipButtonControlBar } from "./js-components/skipButtonControlBar";
import { Tooltip } from "./render/Tooltip"; import { Tooltip } from "./render/Tooltip";
import { getStartTimeFromUrl } from "./utils/urlParser"; 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 { CategoryPill } from "./render/CategoryPill";
import { AnimationUtils } from "./utils/animationUtils"; import { AnimationUtils } from "./utils/animationUtils";
import { GenericUtils } from "./utils/genericUtils"; import { GenericUtils } from "./utils/genericUtils";
@@ -92,6 +92,8 @@ const playerButtons: Record<string, {button: HTMLButtonElement, image: HTMLImage
// Direct Links after the config is loaded // Direct Links after the config is loaded
utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document))); utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document)));
// wait infinitely for hover preview
utils.wait(() => getHoverPreview(), 0, 500).then(() => refreshVideoAttachments())
addPageListeners(); addPageListeners();
addHotkeyListener(); addHotkeyListener();

View File

@@ -1,10 +1,11 @@
/** Function that can be used to wait for a condition before returning. */ /** Function that can be used to wait for a condition before returning. */
async function wait<T>(condition: () => T | false, timeout = 5000, check = 100): Promise<T> { async function wait<T>(condition: () => T | false, timeout = 5000, check = 100): Promise<T> {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
setTimeout(() => { const failTimeout = setTimeout(() => {
clearInterval(interval); clearInterval(interval);
reject("TIMEOUT"); reject("TIMEOUT");
}, timeout); }, timeout);
if (timeout === 0) clearTimeout(failTimeout);
const intervalCheck = () => { const intervalCheck = () => {
const result = condition(); const result = condition();

View File

@@ -19,6 +19,11 @@ export function getControls(): HTMLElement | false {
return 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 { export function isVisible(element: HTMLElement): boolean {
return element && element.offsetWidth > 0 && element.offsetHeight > 0; return element && element.offsetWidth > 0 && element.offsetHeight > 0;
} }