diff --git a/_locales/en/messages.json b/_locales/en/messages.json index b018fb0c..f3cb29de 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1086,11 +1086,8 @@ "optionsAdvancedNewStyleAsUsercss": { "message": "Write new style as usercss" }, - "optionsAdvancedAutoSwitchScheme": { - "message": "Toggle Light/Dark Mode styles automatically" - }, "optionsAdvancedAutoSwitchSchemeNever": { - "message": "Never" + "message": "Disabled. The dark/light setting in styles is ignored." }, "optionsAdvancedAutoSwitchSchemeBySystem": { "message": "By system preference" @@ -1312,26 +1309,20 @@ "description": "Label for the checkbox controlling section order in the popup." }, "preferScheme": { - "message": "Dark/Light mode preference:" + "message": "Dark/Light mode preference" + }, + "preferSchemeAlways": { + "message": "Currently ignored (the style always applies) because the global Dark/Light mode is disabled" }, "preferSchemeDark": { "message": "Dark" }, - "preferSchemeDarkOnly": { - "message": "Dark (strict)" - }, "preferSchemeLight": { "message": "Light" }, - "preferSchemeLightOnly": { - "message": "Light (strict)" - }, "preferSchemeNone": { "message": "None (always applied)" }, - "preferSchemeTip": { - "message": "The style will be applied in a matching Dark/Light global mode. For strict options, the mode being active is mandatory, so the style doesn't apply when the mode is 'Never'. For non-strict options, the style also applies when the user doesn't care i.e. the global mode is 'Never'." - }, "prefShowBadge": { "message": "Number of styles active for the current site", "description": "Label for the checkbox controlling toolbar badge text." diff --git a/background/color-scheme.js b/background/color-scheme.js index 300322c2..1c389623 100644 --- a/background/color-scheme.js +++ b/background/color-scheme.js @@ -8,11 +8,17 @@ const colorScheme = (() => { const kSTATE = 'schemeSwitcher.enabled'; const kSTART = 'schemeSwitcher.nightStart'; const kEND = 'schemeSwitcher.nightEnd'; - const SCHEMES = ['dark', 'light', 'dark!', 'light!']; // ! = only if schemeSwitcher is enabled - const isDark = {never: null, system: false, time: false}; + const SCHEMES = ['dark', 'light']; + const isDark = { + never: null, + dark: true, + light: false, + system: false, + time: false, + }; let isDarkNow = false; - prefs.subscribe(kSTATE, () => emitChange()); + prefs.subscribe(kSTATE, () => update()); prefs.subscribe([kSTART, kEND], (key, value) => { updateTimePreferDark(); createAlarm(key, value); @@ -28,17 +34,25 @@ const colorScheme = (() => { onChange(listener) { changeListeners.add(listener); }, - shouldIncludeStyle({preferScheme: val}) { - return !SCHEMES.includes(val) || - !val.endsWith('!') && prefs.get(kSTATE) === 'never' || - val.startsWith('dark') === isDarkNow; + /** @param {StyleObj | 'darkUI'} val - the string is used by the built-in dark themer */ + shouldIncludeStyle(val) { + return val === 'darkUI' + ? isDarkNow + : prefs.get(kSTATE) === 'never' || + !SCHEMES.includes(val = val.preferScheme) || + isDarkNow === (val === 'dark'); }, updateSystemPreferDark(val) { - emitChange('system', val); + update('system', val); return true; }, }; + function calcTime(key) { + const [h, m] = prefs.get(key).split(':'); + return (h * 3600 + m * 60) * 1000; + } + function createAlarm(key, value) { const date = new Date(); const [h, m] = value.split(':'); @@ -59,22 +73,20 @@ const colorScheme = (() => { const val = start > end ? now >= start || now < end : now >= start && now < end; - emitChange('time', val); + update('time', val); } - function calcTime(key) { - const [h, m] = prefs.get(key).split(':'); - return (h * 3600 + m * 60) * 1000; - } - - function emitChange(type, val) { + function update(type, val) { if (type) { if (isDark[type] === val) return; isDark[type] = val; } - isDarkNow = isDark[prefs.get(kSTATE)]; - for (const listener of changeListeners) { - listener(isDarkNow); + val = isDark[prefs.get(kSTATE)]; + if (isDarkNow !== val) { + isDarkNow = val; + for (const listener of changeListeners) { + listener(isDarkNow); + } } } })(); diff --git a/edit/codemirror-default.css b/edit/codemirror-default.css index 0fdf0791..191b9813 100644 --- a/edit/codemirror-default.css +++ b/edit/codemirror-default.css @@ -85,7 +85,7 @@ background: linear-gradient(0deg, hsla(180, 100%, 30%, .75) 2px, hsla(180, 100%, 30%, .2) 2px); } -@media not screen, dark { +@media (prefers-color-scheme: dark) { .CodeMirror-dialog { background-color: #333; } @@ -127,7 +127,7 @@ .cm-s-default .cm-operator { color: #d2c057 } .cm-s-default .cm-string { color: #f28b54 } .cm-s-default .cm-variable { color: #d9d9d9 } - .cm-s-default .cm-variable-2 { color: #05a } + .cm-s-default .cm-variable-2 { color: #72b9ff } .cm-s-default .cm-variable-3 { color: #9bbbdc } @keyframes highlight { diff --git a/edit/settings.html b/edit/settings.html index 83495186..a83a958f 100644 --- a/edit/settings.html +++ b/edit/settings.html @@ -8,9 +8,7 @@
- - - +