From 0483bc5cc18cbb7f26cb3da692916700e0e0dc26 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Mon, 1 Jun 2026 22:29:42 +0200 Subject: [PATCH] refactor: dedupe scrub seek --- static/player/main.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/static/player/main.ts b/static/player/main.ts index ae6a6b8..3d28af7 100644 --- a/static/player/main.ts +++ b/static/player/main.ts @@ -99,6 +99,19 @@ const initPlayer = (): void => { const loading = container.querySelector("[data-loading]") as HTMLElement | null; const progressWrap = container.querySelector("[data-progress-wrap]") as HTMLElement | null; + const scrubToPointer = (clientX: number, shouldShowControls: boolean): void => { + if (!progressWrap) return; + const rect = progressWrap.getBoundingClientRect(); + state.video.currentTime = absoluteTimeFromRatio( + Math.max(0, Math.min(1, (clientX - rect.left) / rect.width)), + ); + updateTimeline(state.video.currentTime); + updateSkipButton(state.video.currentTime); + if (shouldShowControls) { + showControls(); + } + }; + // build video src from mode, token, and saved quality preference // Only set if not already provided by the inline script during HTML parsing const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best"; @@ -260,13 +273,7 @@ const initPlayer = (): void => { try { (e.currentTarget as HTMLElement).setPointerCapture((e as PointerEvent).pointerId); } catch {} - const rect = progressWrap.getBoundingClientRect(); - state.video.currentTime = absoluteTimeFromRatio( - Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)), - ); - updateTimeline(state.video.currentTime); - updateSkipButton(state.video.currentTime); - showControls(); + scrubToPointer(e.clientX, true); }, { signal }, ); @@ -297,12 +304,7 @@ const initPlayer = (): void => { "pointermove", (e) => { if (!state.isScrubbing || !progressWrap) return; - const rect = progressWrap.getBoundingClientRect(); - state.video.currentTime = absoluteTimeFromRatio( - Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)), - ); - updateTimeline(state.video.currentTime); - updateSkipButton(state.video.currentTime); + scrubToPointer(e.clientX, false); }, { signal }, );