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
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user