修复深色与浅色主题无法切换的问题

修正 CSS 选择器避免 :root 始终应用深色变量,并改进 theme.js 点击绑定与首屏主题恢复。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 16:29:34 +08:00
parent 2b383b84ce
commit 0e385b057d
3 changed files with 34 additions and 14 deletions
+15 -7
View File
@@ -33,13 +33,21 @@
apply(prefersLight ? 'light' : 'dark');
}
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('click', function (e) {
var btn = e.target.closest('[data-theme-pick]');
if (!btn) return;
e.preventDefault();
apply(btn.getAttribute('data-theme-pick'));
});
function syncButtons() {
var cur = document.documentElement.getAttribute('data-theme') || 'dark';
updateButtons(cur);
document.querySelectorAll('[data-theme-pick]').forEach(function (btn) {
btn.addEventListener('click', function () {
apply(btn.getAttribute('data-theme-pick'));
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', syncButtons);
} else {
syncButtons();
}
})();