@@ -6,10 +6,9 @@ let toggleTheme = (theme) => {
6
6
} else {
7
7
setTheme ( "dark" ) ;
8
8
}
9
- }
10
-
9
+ } ;
11
10
12
- let setTheme = ( theme ) => {
11
+ let setTheme = ( theme ) => {
13
12
transTheme ( ) ;
14
13
setHighlight ( theme ) ;
15
14
setGiscusTheme ( theme ) ;
@@ -18,12 +17,12 @@ let setTheme = (theme) => {
18
17
document . documentElement . setAttribute ( "data-theme" , theme ) ;
19
18
20
19
// Add class to tables.
21
- let tables = document . getElementsByTagName ( ' table' ) ;
22
- for ( let i = 0 ; i < tables . length ; i ++ ) {
20
+ let tables = document . getElementsByTagName ( " table" ) ;
21
+ for ( let i = 0 ; i < tables . length ; i ++ ) {
23
22
if ( theme == "dark" ) {
24
- tables [ i ] . classList . add ( ' table-dark' ) ;
23
+ tables [ i ] . classList . add ( " table-dark" ) ;
25
24
} else {
26
- tables [ i ] . classList . remove ( ' table-dark' ) ;
25
+ tables [ i ] . classList . remove ( " table-dark" ) ;
27
26
}
28
27
}
29
28
} else {
@@ -32,15 +31,16 @@ let setTheme = (theme) => {
32
31
localStorage . setItem ( "theme" , theme ) ;
33
32
34
33
// Updates the background of medium-zoom overlay.
35
- if ( typeof medium_zoom !== ' undefined' ) {
34
+ if ( typeof medium_zoom !== " undefined" ) {
36
35
medium_zoom . update ( {
37
- background : getComputedStyle ( document . documentElement )
38
- . getPropertyValue ( '--global-bg-color' ) + 'ee' , // + 'ee' for trasparency.
39
- } )
36
+ background :
37
+ getComputedStyle ( document . documentElement ) . getPropertyValue (
38
+ "--global-bg-color"
39
+ ) + "ee" , // + 'ee' for trasparency.
40
+ } ) ;
40
41
}
41
42
} ;
42
43
43
-
44
44
let setHighlight = ( theme ) => {
45
45
if ( theme == "dark" ) {
46
46
document . getElementById ( "highlight_theme_light" ) . media = "none" ;
@@ -49,44 +49,38 @@ let setHighlight = (theme) => {
49
49
document . getElementById ( "highlight_theme_dark" ) . media = "none" ;
50
50
document . getElementById ( "highlight_theme_light" ) . media = "" ;
51
51
}
52
- }
53
-
52
+ } ;
54
53
55
54
let setGiscusTheme = ( theme ) => {
56
-
57
55
function sendMessage ( message ) {
58
- const iframe = document . querySelector ( ' iframe.giscus-frame' ) ;
56
+ const iframe = document . querySelector ( " iframe.giscus-frame" ) ;
59
57
if ( ! iframe ) return ;
60
- iframe . contentWindow . postMessage ( { giscus : message } , ' https://giscus.app' ) ;
58
+ iframe . contentWindow . postMessage ( { giscus : message } , " https://giscus.app" ) ;
61
59
}
62
60
63
61
sendMessage ( {
64
62
setConfig : {
65
- theme : theme
66
- }
63
+ theme : theme ,
64
+ } ,
67
65
} ) ;
68
-
69
- }
70
-
66
+ } ;
71
67
72
68
let transTheme = ( ) => {
73
69
document . documentElement . classList . add ( "transition" ) ;
74
70
window . setTimeout ( ( ) => {
75
71
document . documentElement . classList . remove ( "transition" ) ;
76
- } , 500 )
77
- }
78
-
72
+ } , 500 ) ;
73
+ } ;
79
74
80
75
let initTheme = ( theme ) => {
81
- if ( theme == null || theme == ' null' ) {
76
+ if ( theme == null || theme == " null" ) {
82
77
const userPref = window . matchMedia ;
83
- if ( userPref && userPref ( ' (prefers-color-scheme: dark)' ) . matches ) {
84
- theme = ' dark' ;
78
+ if ( userPref && userPref ( " (prefers-color-scheme: dark)" ) . matches ) {
79
+ theme = " dark" ;
85
80
}
86
81
}
87
82
88
83
setTheme ( theme ) ;
89
- }
90
-
84
+ } ;
91
85
92
86
initTheme ( localStorage . getItem ( "theme" ) ) ;
0 commit comments