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:
@@ -58,18 +58,3 @@
|
|||||||
<script src="./static/js/app.js"></script>
|
<script src="./static/js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
<script>
|
|
||||||
function toggleTheme(){
|
|
||||||
var t=document.documentElement.getAttribute("data-theme")==="light"?"dark":"light";
|
|
||||||
document.documentElement.setAttribute("data-theme",t);
|
|
||||||
localStorage.setItem("sensu-theme",t);
|
|
||||||
document.querySelector(".theme-toggle").textContent=t==="light"?"☀️":"🌙";
|
|
||||||
}
|
|
||||||
(function(){
|
|
||||||
var s=localStorage.getItem("sensu-theme")||"dark";
|
|
||||||
document.documentElement.setAttribute("data-theme",s);
|
|
||||||
var btn=document.querySelector(".theme-toggle");
|
|
||||||
if(btn) btn.textContent=s==="light"?"☀️":"🌙";
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -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 () => {
|
window.onload = async () => {
|
||||||
|
// 设置按钮初始图标
|
||||||
|
var btn = document.querySelector(".theme-toggle");
|
||||||
|
if(btn) btn.textContent = document.documentElement.getAttribute("data-theme") === "light" ? "☀️" : "🌙";
|
||||||
try {
|
try {
|
||||||
const res = await fetch('./api/auth/status', { credentials: 'include' });
|
const res = await fetch('./api/auth/status', { credentials: 'include' });
|
||||||
if(res.status === 401) { window.location.href = './index.html'; return; }
|
if(res.status === 401) { window.location.href = './index.html'; return; }
|
||||||
|
|||||||
Reference in New Issue
Block a user