Improve the theme detection logic

This commit is contained in:
Sumner Evans 2020-04-08 00:42:06 -06:00
parent 6816d4800b
commit 5955f45a30
No known key found for this signature in database
GPG key ID: 8904527AB50022FD

View file

@ -16,8 +16,8 @@
const darkSchemeWatch = window.matchMedia('(prefers-color-scheme: dark)'); const darkSchemeWatch = window.matchMedia('(prefers-color-scheme: dark)');
function detectThemeAndSwitchStyle() { function detectThemeAndSwitchStyle() {
let theme = localStorage.getItem('themeOverride') || 'browser'; let theme = localStorage.getItem('themeOverride');
if (theme === 'browser') { if (theme !== 'light' && theme !== 'dark') {
theme = darkSchemeWatch.matches ? 'dark' : 'light'; theme = darkSchemeWatch.matches ? 'dark' : 'light';
} }
console.log(`Switching theme to ${theme}.`) console.log(`Switching theme to ${theme}.`)