summaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/profile-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/profile-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/profile-controller.js')
-rw-r--r--ext/js/pages/settings/profile-controller.js56
1 files changed, 24 insertions, 32 deletions
diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js
index c82223b8..6e0710a8 100644
--- a/ext/js/pages/settings/profile-controller.js
+++ b/ext/js/pages/settings/profile-controller.js
@@ -17,6 +17,7 @@
*/
import {clone, EventListenerCollection} from '../../core.js';
+import {querySelectorNotNull} from '../../dom/query-selector.js';
import {yomitan} from '../../yomitan.js';
import {ProfileConditionsUI} from './profile-conditions-ui.js';
@@ -34,24 +35,24 @@ export class ProfileController {
this._profileConditionsUI = new ProfileConditionsUI(settingsController);
/** @type {?number} */
this._profileConditionsIndex = null;
- /** @type {?HTMLSelectElement} */
- this._profileActiveSelect = null;
- /** @type {?HTMLSelectElement} */
- this._profileTargetSelect = null;
- /** @type {?HTMLSelectElement} */
- this._profileCopySourceSelect = null;
- /** @type {?HTMLElement} */
- this._removeProfileNameElement = null;
- /** @type {?HTMLButtonElement} */
- this._profileAddButton = null;
- /** @type {?HTMLButtonElement} */
- this._profileRemoveConfirmButton = null;
- /** @type {?HTMLButtonElement} */
- this._profileCopyConfirmButton = null;
- /** @type {?HTMLElement} */
- this._profileEntryListContainer = null;
- /** @type {?HTMLElement} */
- this._profileConditionsProfileName = null;
+ /** @type {HTMLSelectElement} */
+ this._profileActiveSelect = querySelectorNotNull(document, '#profile-active-select');
+ /** @type {HTMLSelectElement} */
+ this._profileTargetSelect = querySelectorNotNull(document, '#profile-target-select');
+ /** @type {HTMLSelectElement} */
+ this._profileCopySourceSelect = querySelectorNotNull(document, '#profile-copy-source-select');
+ /** @type {HTMLElement} */
+ this._removeProfileNameElement = querySelectorNotNull(document, '#profile-remove-name');
+ /** @type {HTMLButtonElement} */
+ this._profileAddButton = querySelectorNotNull(document, '#profile-add-button');
+ /** @type {HTMLButtonElement} */
+ this._profileRemoveConfirmButton = querySelectorNotNull(document, '#profile-remove-confirm-button');
+ /** @type {HTMLButtonElement} */
+ this._profileCopyConfirmButton = querySelectorNotNull(document, '#profile-copy-confirm-button');
+ /** @type {HTMLElement} */
+ this._profileEntryListContainer = querySelectorNotNull(document, '#profile-entry-list');
+ /** @type {HTMLElement} */
+ this._profileConditionsProfileName = querySelectorNotNull(document, '#profile-conditions-profile-name');
/** @type {?import('./modal.js').Modal} */
this._profileRemoveModal = null;
/** @type {?import('./modal.js').Modal} */
@@ -83,15 +84,6 @@ export class ProfileController {
const {platform: {os}} = await yomitan.api.getEnvironmentInfo();
this._profileConditionsUI.os = os;
- this._profileActiveSelect = /** @type {HTMLSelectElement} */ (document.querySelector('#profile-active-select'));
- this._profileTargetSelect = /** @type {HTMLSelectElement} */ (document.querySelector('#profile-target-select'));
- this._profileCopySourceSelect = /** @type {HTMLSelectElement} */ (document.querySelector('#profile-copy-source-select'));
- this._removeProfileNameElement = /** @type {HTMLElement} */ (document.querySelector('#profile-remove-name'));
- this._profileAddButton = /** @type {HTMLButtonElement} */ (document.querySelector('#profile-add-button'));
- this._profileRemoveConfirmButton = /** @type {HTMLButtonElement} */ (document.querySelector('#profile-remove-confirm-button'));
- this._profileCopyConfirmButton = /** @type {HTMLButtonElement} */ (document.querySelector('#profile-copy-confirm-button'));
- this._profileEntryListContainer = /** @type {HTMLElement} */ (document.querySelector('#profile-entry-list'));
- this._profileConditionsProfileName = /** @type {HTMLElement} */ (document.querySelector('#profile-conditions-profile-name'));
this._profileRemoveModal = this._modalController.getModal('profile-remove');
this._profileCopyModal = this._modalController.getModal('profile-copy');
this._profileConditionsModal = this._modalController.getModal('profile-conditions');
@@ -662,15 +654,15 @@ class ProfileEntry {
/** @type {number} */
this._index = index;
/** @type {HTMLInputElement} */
- this._isDefaultRadio = /** @type {HTMLInputElement} */ (node.querySelector('.profile-entry-is-default-radio'));
+ this._isDefaultRadio = querySelectorNotNull(node, '.profile-entry-is-default-radio');
/** @type {HTMLInputElement} */
- this._nameInput = /** @type {HTMLInputElement} */ (node.querySelector('.profile-entry-name-input'));
+ this._nameInput = querySelectorNotNull(node, '.profile-entry-name-input');
/** @type {HTMLElement} */
- this._countLink = /** @type {HTMLElement} */ (node.querySelector('.profile-entry-condition-count-link'));
+ this._countLink = querySelectorNotNull(node, '.profile-entry-condition-count-link');
/** @type {HTMLElement} */
- this._countText = /** @type {HTMLElement} */ (node.querySelector('.profile-entry-condition-count'));
+ this._countText = querySelectorNotNull(node, '.profile-entry-condition-count');
/** @type {HTMLButtonElement} */
- this._menuButton = /** @type {HTMLButtonElement} */ (node.querySelector('.profile-entry-menu-button'));
+ this._menuButton = querySelectorNotNull(node, '.profile-entry-menu-button');
/** @type {EventListenerCollection} */
this._eventListeners = new EventListenerCollection();
}