diff --git a/webui/app.js b/webui/app.js index 938e120..2bbf5c7 100644 --- a/webui/app.js +++ b/webui/app.js @@ -74,13 +74,13 @@ const TIMELINE_LAYOUT = Object.freeze({ }); const TIMELINE_STROKES = Object.freeze({ - fudai_open_detail: { stroke: "var(--primary)", dash: "" }, - fudai_attend_ok: { stroke: "var(--primary)", dash: "6 4" }, - fudai_attend_fail: { stroke: "var(--danger)", dash: "" }, - fudai_result_win: { stroke: "var(--danger)", dash: "6 4" }, - fudai_result_no_win: { stroke: "var(--muted)", dash: "" }, - fudai_skip: { stroke: "var(--muted)", dash: "6 4" }, - switch_room: { stroke: "var(--text)", dash: "2 4" }, + fudai_open_detail: { stroke: "var(--primary)", opacity: 1.0, dash: "" }, + fudai_attend_ok: { stroke: "var(--primary)", opacity: 0.7, dash: "" }, + fudai_attend_fail: { stroke: "var(--primary)", opacity: 0.4, dash: "4 3" }, + fudai_result_win: { stroke: "var(--primary)", opacity: 1.0, dash: "2 3" }, + fudai_result_no_win:{ stroke: "var(--primary)", opacity: 0.4, dash: "" }, + fudai_skip: { stroke: "var(--muted)", opacity: 0.7, dash: "4 3" }, + switch_room: { stroke: "var(--muted)", opacity: 1.0, dash: "2 3" }, }); const BUSY_DISABLED_BUTTONS = new Set(["btnStart", "btnSave"]); @@ -221,6 +221,41 @@ const DEFAULTS = { function $(id) { return document.getElementById(id); } +function initTheme() { + const root = document.documentElement; + const btn = $("btnTheme"); + const mql = window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null; + + const apply = (theme) => { + root.setAttribute("data-theme", theme); + if (btn) btn.setAttribute("aria-label", theme === "dark" ? "切换到浅色" : "切换到深色"); + }; + + // Initial: respect inline-set attribute (set by head bootstrap), or fall back. + const initial = root.getAttribute("data-theme") + || (mql && mql.matches ? "dark" : "light"); + apply(initial); + + if (btn) { + btn.addEventListener("click", () => { + const next = root.getAttribute("data-theme") === "dark" ? "light" : "dark"; + try { localStorage.setItem("ui-theme", next); } catch (_) {} + apply(next); + }); + } + + // Follow system changes only when user hasn't picked manually. + if (mql && typeof mql.addEventListener === "function") { + mql.addEventListener("change", (ev) => { + let saved = null; + try { saved = localStorage.getItem("ui-theme"); } catch (_) {} + if (saved !== "dark" && saved !== "light") { + apply(ev.matches ? "dark" : "light"); + } + }); + } +} + function initTabs() { const tabButtons = Array.from(document.querySelectorAll(".tabBtn[data-target]")); const panels = Array.from(document.querySelectorAll(".panel[data-panel]")); @@ -667,7 +702,8 @@ function renderTimeline(containerId, timeline) { p.setAttribute("d", d); p.setAttribute("fill", "none"); p.setAttribute("stroke", TIMELINE_STROKES[k]?.stroke || "var(--primary)"); - p.setAttribute("stroke-width", "2"); + p.setAttribute("stroke-width", "1.5"); + p.setAttribute("stroke-opacity", String(TIMELINE_STROKES[k]?.opacity ?? 1)); if (TIMELINE_STROKES[k]?.dash) p.setAttribute("stroke-dasharray", TIMELINE_STROKES[k].dash); p.setAttribute("stroke-linecap", "round"); p.setAttribute("stroke-linejoin", "round"); @@ -1475,6 +1511,7 @@ function startStatsPolling() { } window.addEventListener("DOMContentLoaded", async () => { + initTheme(); initTabs(); $("btnRefresh").addEventListener("click", refreshDevices); $("btnLoad").addEventListener("click", async () => { await loadConfig(); }); diff --git a/webui/index.html b/webui/index.html index 190ea85..aa48d6a 100644 --- a/webui/index.html +++ b/webui/index.html @@ -4,7 +4,18 @@