From a1dd401efc7d8aa4c625f90851539e905e5d61f6 Mon Sep 17 00:00:00 2001 From: qinglong Date: Thu, 11 Jun 2026 12:46:33 +0800 Subject: [PATCH] Fix theme toggle: move init to app.js, remove duplicate script - Theme initialized BEFORE page render (no flash) - toggleTheme() now in app.js global scope - Proxy page rewritten with btn-filled MD3 class --- static/web_panel/home.html | 15 --------------- static/web_panel/js/app.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/static/web_panel/home.html b/static/web_panel/home.html index 2828200..50f6375 100644 --- a/static/web_panel/home.html +++ b/static/web_panel/home.html @@ -58,18 +58,3 @@ - - diff --git a/static/web_panel/js/app.js b/static/web_panel/js/app.js index f388c27..e26fa2c 100644 --- a/static/web_panel/js/app.js +++ b/static/web_panel/js/app.js @@ -1,5 +1,22 @@ +// 主题初始化 (必须在渲染前执行, 防止闪白) +(function(){ + var s = localStorage.getItem("sensu-theme") || "dark"; + document.documentElement.setAttribute("data-theme", s); +})(); + +window.toggleTheme = function(){ + var t = document.documentElement.getAttribute("data-theme") === "light" ? "dark" : "light"; + document.documentElement.setAttribute("data-theme", t); + localStorage.setItem("sensu-theme", t); + var btn = document.querySelector(".theme-toggle"); + if(btn) btn.textContent = t === "light" ? "☀️" : "🌙"; +}; + // 初始化检查 window.onload = async () => { + // 设置按钮初始图标 + var btn = document.querySelector(".theme-toggle"); + if(btn) btn.textContent = document.documentElement.getAttribute("data-theme") === "light" ? "☀️" : "🌙"; try { const res = await fetch('./api/auth/status', { credentials: 'include' }); if(res.status === 401) { window.location.href = './index.html'; return; }