feat: new config APPEARANCE_DARK_TIME

Add an option APPEARANCE_DARK_TIME to determine the time period during which dark mode will be
automatically activated.
This commit is contained in:
Ray
2023-04-16 19:48:23 +08:00
parent a496e342a4
commit 8345579937
2 changed files with 115 additions and 46 deletions

View File

@@ -51,7 +51,7 @@ export function isPreferDark() {
// 系统深色模式或时间是夜间时,强行置为夜间模式
const date = new Date()
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
return prefersDarkMode || (date.getHours() >= 18 || date.getHours() < 6)
return prefersDarkMode || (BLOG.APPEARANCE_DARK_TIME && (date.getHours() >= BLOG.APPEARANCE_DARK_TIME[0] || date.getHours() < BLOG.APPEARANCE_DARK_TIME[1]))
}
return false
}