aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/popup-preview-frame.js
diff options
context:
space:
mode:
authorKuuuube <61125188+Kuuuube@users.noreply.github.com>2024-06-18 14:00:52 -0400
committerGitHub <noreply@github.com>2024-06-18 18:00:52 +0000
commitebd911201df0e6fce95b408935fb35580851170e (patch)
tree1955088b5c5157a02b1d75d8994e20114199830c /ext/js/pages/settings/popup-preview-frame.js
parent129be78c9bf1b9d378050c6ca6ec722ef456c4ee (diff)
Add full dark mode support (#1079)
* Add full dark mode support * Fix welcome, permissions, and quick start scrollbars * Fix action popup dark mode on mobile * Add theme to info page * Reduce flashbang * Move position of settingsDisplayController to not break things * Fix dictionary import drag drop theming * Make dark shadow color less bad * Prepare themeController to avoid not being able to set browser theme
Diffstat (limited to 'ext/js/pages/settings/popup-preview-frame.js')
-rw-r--r--ext/js/pages/settings/popup-preview-frame.js28
1 files changed, 8 insertions, 20 deletions
diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js
index 37aca898..7abcfe2a 100644
--- a/ext/js/pages/settings/popup-preview-frame.js
+++ b/ext/js/pages/settings/popup-preview-frame.js
@@ -18,6 +18,7 @@
import * as wanakana from '../../../lib/wanakana.js';
import {Frontend} from '../../app/frontend.js';
+import {ThemeController} from '../../app/theme-controller.js';
import {createApiMap, invokeApiMapHandler} from '../../core/api-map.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {TextSourceRange} from '../../dom/text-source-range.js';
@@ -57,6 +58,8 @@ export class PopupPreviewFrame {
this._languageSummaries = [];
/** @type {boolean} */
this._wanakanaBound = false;
+ /** @type {ThemeController} */
+ this._themeController = new ThemeController(document.documentElement);
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {import('popup-preview-frame').ApiMap} */
@@ -74,10 +77,10 @@ export class PopupPreviewFrame {
async prepare() {
window.addEventListener('message', this._onMessage.bind(this), false);
+ this._themeController.siteTheme = 'light';
+ this._themeController.prepare();
+
// Setup events
- /** @type {HTMLInputElement} */
- const darkThemeCheckbox = querySelectorNotNull(document, '#theme-dark-checkbox');
- darkThemeCheckbox.addEventListener('change', this._onThemeDarkCheckboxChanged.bind(this), false);
this._exampleText.addEventListener('click', this._onExampleTextClick.bind(this), false);
this._exampleTextInput.addEventListener('blur', this._onExampleTextInputBlur.bind(this), false);
this._exampleTextInput.addEventListener('input', this._onExampleTextInputInput.bind(this), false);
@@ -137,6 +140,8 @@ export class PopupPreviewFrame {
options.general.popupHorizontalTextPosition = 'below';
options.general.popupVerticalTextPosition = 'before';
options.scanning.selectText = false;
+ this._themeController.theme = options.general.popupTheme;
+ this._themeController.updateTheme();
return options;
}
@@ -165,23 +170,6 @@ export class PopupPreviewFrame {
invokeApiMapHandler(this._windowMessageHandlers, action, params, [], callback);
}
- /**
- * @param {Event} e
- */
- _onThemeDarkCheckboxChanged(e) {
- const element = /** @type {HTMLInputElement} */ (e.currentTarget);
- document.documentElement.classList.toggle('dark', element.checked);
- if (this._themeChangeTimeout !== null) {
- clearTimeout(this._themeChangeTimeout);
- }
- this._themeChangeTimeout = setTimeout(() => {
- this._themeChangeTimeout = null;
- const popup = /** @type {Frontend} */ (this._frontend).popup;
- if (popup === null) { return; }
- void popup.updateTheme();
- }, 300);
- }
-
/** */
_onExampleTextClick() {
if (this._exampleTextInput === null) { return; }