Skip to content

Commit

Permalink
Add delay to fetch on hover to make it less easy to trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jan 17, 2025
1 parent 9e4939e commit 0f4c1c5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/utils/thumbnails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,27 @@ function thumbnailHoverListener(e: MouseEvent) {
if (!thumbnail) return;

// Pre-fetch data for this video
const videoID = extractVideoID(thumbnail);
if (videoID) {
void getSegmentsForVideo(videoID, false);
}
let fetched = false;
const preFetch = () => {
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 {
Expand Down

0 comments on commit 0f4c1c5

Please sign in to comment.