@@ -53,10 +53,9 @@ function removeClass(elem, className) {
5353 * @param {boolean } [reversed] - Whether to iterate in reverse
5454 */
5555function onEach ( arr , func , reversed ) {
56- if ( arr && arr . length > 0 && func ) {
56+ if ( arr && arr . length > 0 ) {
5757 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 ) {
6059 if ( func ( arr [ i ] ) ) {
6160 return true ;
6261 }
@@ -150,26 +149,19 @@ const updateTheme = (function() {
150149 * … dictates that it should be.
151150 */
152151 function updateTheme ( ) {
153- const use = ( theme , saveTheme ) => {
154- switchTheme ( theme , saveTheme ) ;
155- } ;
156-
157152 // maybe the user has disabled the setting in the meantime!
158153 if ( getSettingValue ( "use-system-theme" ) !== "false" ) {
159154 const lightTheme = getSettingValue ( "preferred-light-theme" ) || "light" ;
160155 const darkTheme = getSettingValue ( "preferred-dark-theme" ) || "dark" ;
156+ updateLocalStorage ( "use-system-theme" , "true" ) ;
161157
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 ) ;
168160 // note: we save the theme so that it doesn't suddenly change when
169161 // the user disables "use-system-theme" and reloads the page or
170162 // navigates to another page
171163 } else {
172- use ( getSettingValue ( "theme" ) , false ) ;
164+ switchTheme ( getSettingValue ( "theme" ) , false ) ;
173165 }
174166 }
175167
0 commit comments