1
0
Fork 0

refine theme logic

This commit is contained in:
nanxiaobei 2022-10-24 21:31:58 +08:00
parent bdeb5df5a5
commit 2ba0c005b9

View file

@ -37,8 +37,12 @@
// init // init
const darkScheme = window.matchMedia('(prefers-color-scheme: dark)'); const darkScheme = window.matchMedia('(prefers-color-scheme: dark)');
if (htmlClass.contains('dark')) {
setDark(true);
} else {
const darkVal = localStorage.getItem('dark'); const darkVal = localStorage.getItem('dark');
setDark(darkVal ? darkVal === 'true' : darkScheme.matches); setDark(darkVal ? darkVal === 'true' : darkScheme.matches);
}
// listen system // listen system
darkScheme.addEventListener('change', (event) => { darkScheme.addEventListener('change', (event) => {