深色浅色主题切换;去掉新浪行情徽章;科技感卡片样式
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
(function () {
|
||||
var KEY = 'qihuo-theme';
|
||||
|
||||
function apply(theme) {
|
||||
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' ? '切换到深色' : '切换到浅色');
|
||||
}
|
||||
}
|
||||
|
||||
var saved = null;
|
||||
try {
|
||||
saved = localStorage.getItem(KEY);
|
||||
} catch (e) { /* ignore */ }
|
||||
|
||||
if (saved === 'light' || saved === 'dark') {
|
||||
apply(saved);
|
||||
} else {
|
||||
var prefersLight = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
|
||||
apply(prefersLight ? 'light' : 'dark');
|
||||
}
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user