@@ -53,10 +53,9 @@ function removeClass(elem, className) {
53
53
* @param {boolean } [reversed] - Whether to iterate in reverse
54
54
*/
55
55
function onEach ( arr , func , reversed ) {
56
- if ( arr && arr . length > 0 && func ) {
56
+ if ( arr && arr . length > 0 ) {
57
57
if ( reversed ) {
58
- const length = arr . length ;
59
- for ( let i = length - 1 ; i >= 0 ; -- i ) {
58
+ for ( let i = arr . length - 1 ; i >= 0 ; -- i ) {
60
59
if ( func ( arr [ i ] ) ) {
61
60
return true ;
62
61
}
@@ -150,26 +149,19 @@ const updateTheme = (function() {
150
149
* … dictates that it should be.
151
150
*/
152
151
function updateTheme ( ) {
153
- const use = ( theme , saveTheme ) => {
154
- switchTheme ( theme , saveTheme ) ;
155
- } ;
156
-
157
152
// maybe the user has disabled the setting in the meantime!
158
153
if ( getSettingValue ( "use-system-theme" ) !== "false" ) {
159
154
const lightTheme = getSettingValue ( "preferred-light-theme" ) || "light" ;
160
155
const darkTheme = getSettingValue ( "preferred-dark-theme" ) || "dark" ;
156
+ updateLocalStorage ( "use-system-theme" , "true" ) ;
161
157
162
- if ( mql . matches ) {
163
- use ( darkTheme , true ) ;
164
- } else {
165
- // prefers a light theme, or has no preference
166
- use ( lightTheme , true ) ;
167
- }
158
+ // use light theme if user prefers it, or has no preference
159
+ switchTheme ( mql . matches ? darkTheme : lightTheme , true ) ;
168
160
// note: we save the theme so that it doesn't suddenly change when
169
161
// the user disables "use-system-theme" and reloads the page or
170
162
// navigates to another page
171
163
} else {
172
- use ( getSettingValue ( "theme" ) , false ) ;
164
+ switchTheme ( getSettingValue ( "theme" ) , false ) ;
173
165
}
174
166
}
175
167
0 commit comments