File tree 1 file changed +23
-11
lines changed
1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -343,17 +343,23 @@ function setTheme(theme, store) {
343
343
let enableNight = false ;
344
344
let enableAyu = false ;
345
345
346
- if ( theme == "ayu" ) {
347
- enableAyu = true ;
348
- } else if ( theme == "coal" || theme == "navy" ) {
349
- enableNight = true ;
350
- } else if ( theme == "rust" ) {
351
- enableHighlight = true ;
352
- } else {
353
- enableHighlight = true ;
354
- // this makes sure that an unknown theme request gets set to a known one
355
- theme = "light" ;
346
+ switch ( theme ) {
347
+ case "ayu" :
348
+ enableAyu = true ;
349
+ break ;
350
+ case "coal" :
351
+ case "navy" :
352
+ enableNight = true ;
353
+ break ;
354
+ case "rust" :
355
+ enableHighlight = true ;
356
+ break ;
357
+ default :
358
+ enableHighlight = true ;
359
+ theme = "light" ;
360
+ break ;
356
361
}
362
+
357
363
document . getElementsByTagName ( "body" ) [ 0 ] . className = theme ;
358
364
359
365
document . getElementById ( "styleHighlight" ) . disabled = ! enableHighlight ;
@@ -368,4 +374,10 @@ function setTheme(theme, store) {
368
374
}
369
375
370
376
// loading the theme after the initial load
371
- setTheme ( localStorage . getItem ( 'clippy-lint-list-theme' ) , false ) ;
377
+ const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
378
+ const theme = localStorage . getItem ( 'clippy-lint-list-theme' ) ;
379
+ if ( prefersDark . matches && ! theme ) {
380
+ setTheme ( "coal" , false ) ;
381
+ } else {
382
+ setTheme ( theme , false ) ;
383
+ }
You can’t perform that action at this time.
0 commit comments