aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/popup-preview-controller.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-controller.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-controller.js')
-rw-r--r--ext/js/pages/settings/popup-preview-controller.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/ext/js/pages/settings/popup-preview-controller.js b/ext/js/pages/settings/popup-preview-controller.js
index 7239ca17..d8bc9850 100644
--- a/ext/js/pages/settings/popup-preview-controller.js
+++ b/ext/js/pages/settings/popup-preview-controller.js
@@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {querySelectorNotNull} from '../../dom/query-selector.js';
+
export class PopupPreviewController {
/**
* @param {import('./settings-controller.js').SettingsController} settingsController
@@ -25,25 +27,20 @@ export class PopupPreviewController {
this._settingsController = settingsController;
/** @type {string} */
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
- /** @type {?HTMLIFrameElement} */
- this._frame = null;
- /** @type {?HTMLTextAreaElement} */
- this._customCss = null;
- /** @type {?HTMLTextAreaElement} */
- this._customOuterCss = null;
- /** @type {?HTMLElement} */
- this._previewFrameContainer = null;
+ /** @type {HTMLIFrameElement} */
+ this._frame = querySelectorNotNull(document, '#popup-preview-frame');
+ /** @type {HTMLTextAreaElement} */
+ this._customCss = querySelectorNotNull(document, '#custom-popup-css');
+ /** @type {HTMLTextAreaElement} */
+ this._customOuterCss = querySelectorNotNull(document, '#custom-popup-outer-css');
+ /** @type {HTMLElement} */
+ this._previewFrameContainer = querySelectorNotNull(document, '.preview-frame-container');
}
/** */
async prepare() {
if (new URLSearchParams(location.search).get('popup-preview') === 'false') { return; }
- this._frame = /** @type {HTMLIFrameElement} */ (document.querySelector('#popup-preview-frame'));
- this._customCss = /** @type {HTMLTextAreaElement} */ (document.querySelector('#custom-popup-css'));
- this._customOuterCss = /** @type {HTMLTextAreaElement} */ (document.querySelector('#custom-popup-outer-css'));
- this._previewFrameContainer = /** @type {HTMLElement} */ (document.querySelector('.preview-frame-container'));
-
this._customCss.addEventListener('input', this._onCustomCssChange.bind(this), false);
this._customCss.addEventListener('settingChanged', this._onCustomCssChange.bind(this), false);
this._customOuterCss.addEventListener('input', this._onCustomOuterCssChange.bind(this), false);