移除卡片四角装饰,主题切换改为深色/浅色分段按钮
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+19
-10
@@ -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'));
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user