refactor: dedupe scrub seek

This commit is contained in:
2026-06-01 22:29:42 +02:00
committed by Milas Holsting
parent b7f10e71da
commit 322cdac21d

View File

@@ -99,6 +99,19 @@ const initPlayer = (): void => {
const loading = container.querySelector("[data-loading]") as HTMLElement | null; const loading = container.querySelector("[data-loading]") as HTMLElement | null;
const progressWrap = container.querySelector("[data-progress-wrap]") 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 // build video src from mode, token, and saved quality preference
// Only set if not already provided by the inline script during HTML parsing // Only set if not already provided by the inline script during HTML parsing
const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best"; const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best";
@@ -260,13 +273,7 @@ const initPlayer = (): void => {
try { try {
(e.currentTarget as HTMLElement).setPointerCapture((e as PointerEvent).pointerId); (e.currentTarget as HTMLElement).setPointerCapture((e as PointerEvent).pointerId);
} catch {} } catch {}
const rect = progressWrap.getBoundingClientRect(); scrubToPointer(e.clientX, true);
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();
}, },
{ signal }, { signal },
); );
@@ -297,12 +304,7 @@ const initPlayer = (): void => {
"pointermove", "pointermove",
(e) => { (e) => {
if (!state.isScrubbing || !progressWrap) return; if (!state.isScrubbing || !progressWrap) return;
const rect = progressWrap.getBoundingClientRect(); scrubToPointer(e.clientX, false);
state.video.currentTime = absoluteTimeFromRatio(
Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)),
);
updateTimeline(state.video.currentTime);
updateSkipButton(state.video.currentTime);
}, },
{ signal }, { signal },
); );