style: format static/player/skip/segments.ts

This commit is contained in:
2026-06-21 02:04:49 +02:00
committed by Milas Holsting
parent 69d7cad5c1
commit 292f779ee8

View File

@@ -7,8 +7,8 @@ const MAX_INTRO_START = 180; // intro must start before 3min
const MIN_OUTRO_START_RATIO = 0.5; // outro must start at least 50% in const MIN_OUTRO_START_RATIO = 0.5; // outro must start at least 50% in
/** /**
* Filters parsed segments to only those within video bounds and sensible duration. * Filters parsed segments to only those within video bounds and sensible duration. Validates
* Validates intro/outro positioning. * intro/outro positioning.
*/ */
export const resolveActiveSegments = (): void => { export const resolveActiveSegments = (): void => {
const bounds = state.elements.video.duration; const bounds = state.elements.video.duration;
@@ -19,24 +19,36 @@ export const resolveActiveSegments = (): void => {
const normalizeType = (t: string): "op" | "ed" | null => { const normalizeType = (t: string): "op" | "ed" | null => {
const v = (t || "").toLowerCase(); const v = (t || "").toLowerCase();
if (v === "op" || v === "opening" || v === "intro") return "op"; if (v === "op" || v === "opening" || v === "intro") {
if (v === "ed" || v === "ending" || v === "outro") return "ed"; return "op";
}
if (v === "ed" || v === "ending" || v === "outro") {
return "ed";
}
return null; return null;
}; };
state.skip.activeSegments = state.skip.parsedSegments.filter((s) => { state.skip.activeSegments = state.skip.parsedSegments.filter((s) => {
const t = normalizeType(s.type); const t = normalizeType(s.type);
if (!t) return false; if (!t) {
return false;
}
const isOverride = (s.source || "").toLowerCase() === "override"; const isOverride = (s.source || "").toLowerCase() === "override";
const len = s.end - s.start; const len = s.end - s.start;
// duration filter // duration filter
if (len < MIN_SEGMENT_DURATION || len > MAX_SEGMENT_DURATION) return false; if (len < MIN_SEGMENT_DURATION || len > MAX_SEGMENT_DURATION) {
return false;
}
// bounds check // bounds check
if (s.start < 0 || s.end <= s.start || s.end > bounds + 1) return false; if (s.start < 0 || s.end <= s.start || s.end > bounds + 1) {
return false;
}
// User overrides should render even if they don't fit AniSkip's usual OP/ED heuristics. // User overrides should render even if they don't fit AniSkip's usual OP/ED heuristics.
if (isOverride) return true; if (isOverride) {
return true;
}
// intro: starts early, before 50% of video // intro: starts early, before 50% of video
if (t === "op") { if (t === "op") {
@@ -50,16 +62,18 @@ export const resolveActiveSegments = (): void => {
}); });
}; };
/** /** Renders segment markers on the timeline progress bar. */
* Renders segment markers on the timeline progress bar.
*/
export const renderSegments = (): void => { export const renderSegments = (): void => {
const track = state.elements.container.querySelector("[data-segments]") as HTMLElement | null; const track = state.elements.container.querySelector("[data-segments]") as HTMLElement | null;
if (!track) return; if (!track) {
return;
}
track.replaceChildren(); track.replaceChildren();
const bounds = state.elements.video.duration; const bounds = state.elements.video.duration;
if (bounds <= 0) return; if (bounds <= 0) {
return;
}
state.skip.activeSegments.forEach((s) => { state.skip.activeSegments.forEach((s) => {
const bar = document.createElement("div"); const bar = document.createElement("div");
@@ -68,6 +82,6 @@ export const renderSegments = (): void => {
bar.style.height = "calc(100% + 2px)"; bar.style.height = "calc(100% + 2px)";
bar.style.left = `${(s.start / bounds) * 100}%`; bar.style.left = `${(s.start / bounds) * 100}%`;
bar.style.width = `${((s.end - s.start) / bounds) * 100}%`; bar.style.width = `${((s.end - s.start) / bounds) * 100}%`;
track.appendChild(bar); track.append(bar);
}); });
}; };