File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -11,19 +11,23 @@ WebFont.load({
11
11
const light : HTMLLinkElement = document . querySelector ( '#light' ) ;
12
12
const dark : HTMLLinkElement = document . querySelector ( '#dark' ) ;
13
13
14
- const theme : string = localStorage . getItem ( 'theme' ) ;
15
14
const body : HTMLElement = document . body ;
16
- const defaultTheme : string = 'dark' ;
17
-
18
- body . classList . add ( ! theme ? defaultTheme : theme ) ;
19
15
20
- dark . onclick = e => {
16
+ const usedDarkTheme = _ => {
21
17
body . classList . remove ( 'light' ) ;
22
18
body . classList . add ( 'dark' ) ;
23
19
localStorage . setItem ( 'theme' , 'dark' ) ;
24
20
} ;
25
21
26
- light . onclick = e => {
22
+ const useLightTheme = _ => {
27
23
body . classList . replace ( 'dark' , 'light' ) ;
28
24
localStorage . setItem ( 'theme' , 'light' ) ;
29
25
} ;
26
+
27
+ const theme : string = localStorage . getItem ( 'theme' ) ;
28
+
29
+ if ( ! theme && ! body . classList . contains ( theme ) )
30
+ body . classList . add ( theme ) ;
31
+
32
+ dark . onclick = usedDarkTheme ;
33
+ light . onclick = useLightTheme ;
You can’t perform that action at this time.
0 commit comments