Add delay to fetch on hover to make it less easy to trigger

This commit is contained in:
Ajay
2025-01-17 04:33:56 -05:00
parent 9e4939e2e3
commit 0f4c1c50cb

View File

@@ -58,10 +58,27 @@ function thumbnailHoverListener(e: MouseEvent) {
if (!thumbnail) return; if (!thumbnail) return;
// Pre-fetch data for this video // Pre-fetch data for this video
const videoID = extractVideoID(thumbnail); let fetched = false;
if (videoID) { const preFetch = () => {
void getSegmentsForVideo(videoID, false); fetched = true;
} const videoID = extractVideoID(thumbnail);
if (videoID) {
void getSegmentsForVideo(videoID, false);
}
};
const timeout = setTimeout(preFetch, 200);
const onMouseDown = () => {
clearTimeout(timeout);
if (!fetched) {
preFetch();
}
};
e.target.addEventListener("mousedown", onMouseDown, { once: true });
e.target.addEventListener("mouseleave", () => {
clearTimeout(timeout);
e.target.removeEventListener("mousedown", onMouseDown);
}, { once: true });
} }
function getLink(thumbnail: HTMLImageElement): HTMLAnchorElement | null { function getLink(thumbnail: HTMLImageElement): HTMLAnchorElement | null {