移除卡片四角装饰,主题切换改为深色/浅色分段按钮

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 16:15:35 +08:00
parent a12da042cc
commit 2b383b84ce
5 changed files with 59 additions and 78 deletions
+19 -10
View File
@@ -1,16 +1,24 @@
(function () {
var KEY = 'qihuo-theme';
function updateButtons(theme) {
document.querySelectorAll('[data-theme-pick]').forEach(function (btn) {
var pick = btn.getAttribute('data-theme-pick');
var on = pick === theme;
btn.classList.toggle('active', on);
btn.setAttribute('aria-pressed', on ? 'true' : 'false');
});
}
function apply(theme) {
if (theme !== 'light' && theme !== 'dark') {
theme = 'dark';
}
document.documentElement.setAttribute('data-theme', theme);
try {
localStorage.setItem(KEY, theme);
} catch (e) { /* ignore */ }
var btn = document.getElementById('theme-toggle');
if (btn) {
btn.setAttribute('data-active', theme);
btn.setAttribute('aria-label', theme === 'light' ? '切换到深色' : '切换到浅色');
}
updateButtons(theme);
}
var saved = null;
@@ -26,11 +34,12 @@
}
document.addEventListener('DOMContentLoaded', function () {
var btn = document.getElementById('theme-toggle');
if (!btn) return;
btn.addEventListener('click', function () {
var cur = document.documentElement.getAttribute('data-theme') || 'dark';
apply(cur === 'dark' ? 'light' : 'dark');
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'));
});
});
});
})();