forked from xingguangcuican6666/ABK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
31 lines (26 loc) · 904 Bytes
/
Copy paththeme.js
File metadata and controls
31 lines (26 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* 主题切换模块(深色/浅色)
*/
import { t } from './i18n.js';
export function initTheme() {
var themeToggle = document.getElementById('themeToggle');
var themeIcon = document.getElementById('themeIcon');
var themeLabel = document.getElementById('themeLabel');
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
if (theme === 'dark') {
themeIcon.textContent = '\u263D';
themeLabel.textContent = t.light;
} else {
themeIcon.textContent = '\u2600';
themeLabel.textContent = t.dark;
}
}
var savedTheme = localStorage.getItem('theme') || 'dark';
setTheme(savedTheme);
themeToggle.addEventListener('click', function () {
var current = document.documentElement.getAttribute('data-theme');
setTheme(current === 'dark' ? 'light' : 'dark');
});
}