mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-17 20:51:21 +08:00
website: update dark theme issue.
This commit is contained in:
12
scripts/js/dark.js
Normal file
12
scripts/js/dark.js
Normal file
@ -0,0 +1,12 @@
|
||||
const LOCAL_NANE = '_dark_mode_theme_'
|
||||
const rememberedValue = localStorage.getItem(LOCAL_NANE);
|
||||
if (rememberedValue && ['light', 'dark'].includes(rememberedValue)) {
|
||||
document.documentElement.setAttribute('data-color-mode', rememberedValue);
|
||||
}
|
||||
const button = document.querySelector('#darkMode');
|
||||
button.onclick = () => {
|
||||
const theme = document.documentElement.dataset.colorMode;
|
||||
const mode = theme === 'light' ? 'dark' : 'light';
|
||||
document.documentElement.setAttribute('data-color-mode', mode);
|
||||
localStorage.setItem(LOCAL_NANE, mode);
|
||||
}
|
Reference in New Issue
Block a user