summaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/popup-preview-frame.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-16 19:55:02 -0500
committerGitHub <noreply@github.com>2023-12-17 00:55:02 +0000
commit95ad1ae1ef4a53802c12eab4c9b1545af0333aa1 (patch)
treec08016ccb3265a5931baf413cd9d78fcbf600ae9 /ext/js/pages/settings/popup-preview-frame.js
parent77d27113d347b4724302f1c72de1f238e04aeead (diff)
Safer query selector (#364)
* Add querySelectorNotNull helper function * Use querySelectorNotNull * Updates * Update settings * Remove unused * Update * Update function calls * More updates * Update types * Remove obsolete code
Diffstat (limited to 'ext/js/pages/settings/popup-preview-frame.js')
-rw-r--r--ext/js/pages/settings/popup-preview-frame.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js
index 60d264fa..e5cc6580 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 {querySelectorNotNull} from '../../dom/query-selector.js';
import {TextSourceRange} from '../../dom/text-source-range.js';
import {yomitan} from '../../yomitan.js';
@@ -49,10 +50,10 @@ export class PopupPreviewFrame {
this._textSource = null;
/** @type {?import('settings').OptionsContext} */
this._optionsContext = null;
- /** @type {?HTMLElement} */
- this._exampleText = null;
- /** @type {?HTMLInputElement} */
- this._exampleTextInput = null;
+ /** @type {HTMLElement} */
+ this._exampleText = querySelectorNotNull(document, '#example-text');
+ /** @type {HTMLInputElement} */
+ this._exampleTextInput = querySelectorNotNull(document, '#example-text-input');
/** @type {string} */
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
@@ -67,9 +68,6 @@ export class PopupPreviewFrame {
/** */
async prepare() {
- this._exampleText = /** @type {HTMLElement} */ (document.querySelector('#example-text'));
- this._exampleTextInput = /** @type {HTMLInputElement} */ (document.querySelector('#example-text-input'));
-
if (this._exampleTextInput !== null && typeof wanakana !== 'undefined') {
wanakana.bind(this._exampleTextInput);
}
@@ -77,7 +75,8 @@ export class PopupPreviewFrame {
window.addEventListener('message', this._onMessage.bind(this), false);
// Setup events
- const darkThemeCheckbox = /** @type {HTMLInputElement} */ (document.querySelector('#theme-dark-checkbox'));
+ /** @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);