File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change 21
21
22
22
const localStorage = window . localStorage ;
23
23
const htmlElement = document . documentElement ;
24
+ const prefersDarkColorScheme = window . matchMedia (
25
+ "(prefers-color-scheme: dark)"
26
+ ) ;
24
27
25
28
swithInitialTheme ( ) ;
26
29
window . addEventListener ( "load" , onWindowLoad ) ;
43
46
}
44
47
45
48
function isInitialThemeDark ( ) {
46
- const prefersDarkColorScheme = window . matchMedia (
47
- "(prefers-color-scheme: dark)"
48
- ) ;
49
- const savedColorScheme = loadTheme ( ) ;
50
- switch ( savedColorScheme ) {
51
- case "dark" :
52
- return true ;
53
- case "light" :
54
- return false ;
55
- default :
56
- return prefersDarkColorScheme . matches ;
57
- }
49
+ const theme = loadTheme ( ) ;
50
+ return theme ? theme === "dark" : prefersDarkColorScheme . matches ;
58
51
}
59
52
60
53
function onThemeChange ( ) {
You can’t perform that action at this time.
0 commit comments