/* 霜曜 / 黑金主题:仅记忆主题偏好,不写任何业务数据。 */ (function (global) { var KEY = "jinniu-theme"; function read() { try { return localStorage.getItem(KEY) === "night" ? "night" : "day"; } catch (err) { return "day"; } } function syncButtons(theme) { document.querySelectorAll("[data-theme-set]").forEach(function (btn) { var on = btn.getAttribute("data-theme-set") === theme; btn.classList.toggle("is-active", on); btn.setAttribute("aria-pressed", on ? "true" : "false"); }); } function apply(theme, animate) { var next = theme === "night" ? "night" : "day"; var root = document.documentElement; root.classList.add("v-fusion"); if (animate) { root.setAttribute("data-theme-anim", ""); window.setTimeout(function () { root.removeAttribute("data-theme-anim"); }, 220); } root.setAttribute("data-theme", next); if (document.body) document.body.setAttribute("data-theme", next); syncButtons(next); } function set(theme) { var next = theme === "night" ? "night" : "day"; try { localStorage.setItem(KEY, next); } catch (err) { /* 无本地存储时仍切换当次会话 */ } apply(next, true); } apply(read(), false); document.addEventListener("click", function (event) { var btn = event.target.closest("[data-theme-set]"); if (!btn) return; event.preventDefault(); set(btn.getAttribute("data-theme-set")); }); global.JinniuTheme = { apply: apply, set: set, read: read }; })(window);