feat: add remembered theme.

This commit is contained in:
jaywcjlove
2022-10-01 11:59:29 +08:00
parent 53de582bb9
commit e76c245a61
2 changed files with 9 additions and 3 deletions

View File

@ -2,10 +2,17 @@ import path from 'path';
import { getSVGNode } from './getSVGNode.mjs';
const scripts = `
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;
document.documentElement.setAttribute('data-color-mode', theme === 'light' ? 'dark' : 'light');
const mode = theme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-color-mode', mode);
localStorage.setItem(LOCAL_NANE, mode);
}
`;