mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-16 03:09:41 +08:00
优化:默认主题模式选择跟随系统时,无法保存当前浏览器选择的问题
This commit is contained in:
parent
909a14ffcc
commit
acc9ddcbbd
@ -127,15 +127,23 @@
|
|||||||
/** 配置主题模式 */
|
/** 配置主题模式 */
|
||||||
DreamConfig["default_theme"] = '[(${theme.config.basic_style.default_theme})]';
|
DreamConfig["default_theme"] = '[(${theme.config.basic_style.default_theme})]';
|
||||||
(function(){
|
(function(){
|
||||||
let isNight = DreamConfig.default_theme === 'system'? matchMedia('(prefers-color-scheme: dark)').matches : localStorage.getItem('night') || DreamConfig.default_theme === 'night';
|
const hasNightInLocal = () => localStorage.getItem('night') !== null;
|
||||||
|
const getNightInConfig = () => {
|
||||||
|
if (DreamConfig.default_theme === 'night') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (DreamConfig.default_theme === 'system') {
|
||||||
|
return matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let isNight = hasNightInLocal() ? localStorage.getItem('night') : getNightInConfig();
|
||||||
if (isNight.toString() === 'true') {
|
if (isNight.toString() === 'true') {
|
||||||
localStorage.setItem('night', 'true');
|
localStorage.setItem('night', 'true');
|
||||||
document.documentElement.classList.add('night');
|
document.documentElement.classList.add('night');
|
||||||
// 组件配色方案
|
|
||||||
document.documentElement.classList.add('color-scheme-dark');
|
document.documentElement.classList.add('color-scheme-dark');
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('night', 'false');
|
|
||||||
// 组件配色方案
|
|
||||||
document.documentElement.classList.add('color-scheme-light');
|
document.documentElement.classList.add('color-scheme-light');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user