"use strict"; /* * video-recap 审片台 — minimal, human-first read-only viewer. * Only GET requests are issued; zero parameter clutter. */ const THEME_KEY = "video_recap_dashboard_theme"; const readTheme = () => { try { const value = localStorage.getItem(THEME_KEY); return value === "light" || value === "dark" ? value : "auto"; } catch (_error) { return "auto"; } }; const S = { theme: readTheme(), overview: null, data: null, activePage: "", activePath: "", videoMode: "final", seq: 0, palette: { sel: 0, items: [], timer: null, seq: 0 }, }; function applyTheme() { if (S.theme === "auto") document.documentElement.removeAttribute("data-theme"); else document.documentElement.dataset.theme = S.theme; } applyTheme(); const isDark = () => S.theme === "dark" || (S.theme === "auto" && typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches); function toggleTheme() { S.theme = isDark() ? "light" : "dark"; try { localStorage.setItem(THEME_KEY, S.theme); } catch (_error) { /* private mode */ } applyTheme(); renderTop(); } /* ---- DOM & formatting helpers */ const $ = (selector, root) => (root || document).querySelector(selector); const $$ = (selector, root) => Array.from((root || document).querySelectorAll(selector)); const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); const enc = encodeURIComponent; const mediaUrl = (rel) => `/api/media?path=${enc(rel)}`; const num = (value) => (Number.isFinite(value) ? String(Math.round(value * 10) / 10) : "—"); function clock(seconds) { if (!Number.isFinite(seconds)) return "—"; const sign = seconds < 0 ? "-" : ""; const total = Math.max(0, Math.round(Math.abs(seconds))); const minutes = Math.floor(total / 60); const rest = total % 60; return `${sign}${minutes}:${String(rest).padStart(2, "0")}`; } const IC = { search: '', sun: '', moon: '', refresh: '', alert: '', }; const icon = (name) => ``; async function api(path) { const response = await fetch(path, { headers: { Accept: "application/json" } }); let data = null; try { data = await response.json(); } catch (_error) { throw new Error("看板服务返回了无法读取的内容"); } if (!response.ok) throw new Error((data && data.error) || `HTTP ${response.status}`); return data; } /* ---- routing */ function parseRoute(hash) { const raw = (hash || "").replace(/^#/, "") || "/"; const [pathPart, qs = ""] = raw.split("?"); const parts = pathPart.split("/").filter(Boolean); const q = new URLSearchParams(qs); if (["run", "library"].includes(parts[0]) && parts[1]) { let path = parts[1]; try { path = decodeURIComponent(parts[1]); } catch (_error) { /* keep raw */ } return { page: parts[0], path, view: parts[2] || "", q }; } if (parts[0] === "runs") return { page: "runs", path: "", view: "", q }; if (parts[0] === "libraries") return { page: "libraries", path: "", view: "", q }; return { page: "home", path: "", view: "", q }; } const href = (page, path, view = "", query = "") => `#/${page}/${enc(path)}${view ? `/${view}` : ""}${query ? `?${query}` : ""}`; function go(hash) { if (location.hash === hash) render(); else location.hash = hash; } function topRuns(overview) { if (!overview || !overview.runs) return []; const list = overview.runs.filter((r) => !r.internal); return [ ...list.filter((r) => r.has_video), ...list.filter((r) => !r.has_video), ]; } function resolveTarget(route, overview) { const runs = topRuns(overview); const allRuns = overview.runs || []; if (route.page === "run" || route.page === "library") { return { page: route.page, path: route.path, view: route.view, q: route.q }; } if (route.page === "libraries") { const first = overview.libraries[0]; return first ? { page: "library", path: first.path, view: "", q: route.q } : { page: "libraries-empty", path: "", view: "", q: route.q }; } if (runs.length || allRuns.length) { const first = runs[0] || allRuns[0]; return { page: "run", path: first.path, view: "", q: route.q }; } if (overview.libraries.length) { return { page: "library", path: overview.libraries[0].path, view: "", q: route.q }; } return { page: "runs-empty", path: "", view: "", q: route.q }; } /* ---- top chrome */ function renderTop() { const O = S.overview; const hasLib = Boolean(O && O.libraries && O.libraries.length > 0); const onLib = S.activePage.startsWith("librar"); const nav = hasLib ? `` : `
`; $("#topbar").innerHTML = ` 片 审片台 ${nav}
`; } function applyCss(root) { for (const node of $$("[data-css]", root)) { for (const rule of node.dataset.css.split(";")) { const at = rule.indexOf(":"); if (at > 0) node.style.setProperty(rule.slice(0, at).trim(), rule.slice(at + 1).trim()); } node.removeAttribute("data-css"); } } /* ---- main render cycle */ async function render() { const seq = ++S.seq; const rawRoute = parseRoute(location.hash); const view = $("#view"); closePalette(); closeLightbox(); try { if (!S.overview) S.overview = await api("/api/overview"); } catch (error) { if (seq !== S.seq) return; S.activePage = "error"; renderTop(); view.innerHTML = `

无法读取目录

${esc(error.message)}

`; return; } if (seq !== S.seq) return; const target = resolveTarget(rawRoute, S.overview); // Switching 解说词 / 镜头 inside the same video keeps