mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
add infinite wait for hover preview
This commit is contained in:
@@ -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<string, {button: HTMLButtonElement, image: HTMLImage
|
||||
|
||||
// Direct Links after the config is loaded
|
||||
utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document)));
|
||||
// wait infinitely for hover preview
|
||||
utils.wait(() => getHoverPreview(), 0, 500).then(() => refreshVideoAttachments())
|
||||
addPageListeners();
|
||||
addHotkeyListener();
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/** 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> {
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user