File tree 1 file changed +18
-3
lines changed
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -160,18 +160,33 @@ class OptionsWaiter {
160
160
161
161
// Update theme selection
162
162
const themeSelect = document . getElementById ( "theme" ) ;
163
- themeSelect . selectedIndex = themeSelect . querySelector ( `option[value="${ theme } "` ) . index ;
163
+ let themeOption = themeSelect . querySelector ( `option[value="${ theme } "]` ) ;
164
+
165
+ if ( ! themeOption ) {
166
+ const preferredColorScheme = this . getPreferredColorScheme ( ) ;
167
+ document . querySelector ( ":root" ) . className = preferredColorScheme ;
168
+ themeOption = themeSelect . querySelector ( `option[value="${ preferredColorScheme } "]` ) ;
169
+ }
170
+
171
+ themeSelect . selectedIndex = themeOption . index ;
164
172
}
165
173
166
174
/**
167
175
* Applies the user's preferred color scheme using the `prefers-color-scheme` media query.
168
176
*/
169
177
applyPreferredColorScheme ( ) {
170
- const prefersDarkScheme = window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ;
171
- const theme = prefersDarkScheme ? "dark" : "classic" ;
178
+ const theme = this . getPreferredColorScheme ( ) ;
172
179
this . changeTheme ( theme ) ;
173
180
}
174
181
182
+ /**
183
+ * Get the user's preferred color scheme using the `prefers-color-scheme` media query.
184
+ */
185
+ getPreferredColorScheme ( ) {
186
+ const prefersDarkScheme = window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ;
187
+ return prefersDarkScheme ? "dark" : "classic" ;
188
+ }
189
+
175
190
/**
176
191
* Changes the console logging level.
177
192
*
You can’t perform that action at this time.
0 commit comments