aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/display-anki.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/display/display-anki.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/display/display-anki.js')
-rw-r--r--ext/js/display/display-anki.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js
index 574e90ee..81791285 100644
--- a/ext/js/display/display-anki.js
+++ b/ext/js/display/display-anki.js
@@ -20,6 +20,7 @@ import {EventListenerCollection, deferPromise} from '../core.js';
import {AnkiNoteBuilder} from '../data/anki-note-builder.js';
import {AnkiUtil} from '../data/anki-util.js';
import {PopupMenu} from '../dom/popup-menu.js';
+import {querySelectorNotNull} from '../dom/query-selector.js';
import {yomitan} from '../yomitan.js';
export class DisplayAnki {
@@ -91,7 +92,7 @@ export class DisplayAnki {
['term', ['term-kanji', 'term-kana']]
]);
/** @type {HTMLElement} */
- this._menuContainer = /** @type {HTMLElement} */ (document.querySelector('#popup-menus'));
+ this._menuContainer = querySelectorNotNull(document, '#popup-menus');
/** @type {(event: MouseEvent) => void} */
this._onShowTagsBind = this._onShowTags.bind(this);
/** @type {(event: MouseEvent) => void} */
@@ -827,7 +828,8 @@ export class DisplayAnki {
button.hidden = disabled;
button.dataset.noteIds = allNoteIds.join(' ');
- const badge = /** @type {?HTMLElement} */ (button.querySelector('.action-button-badge'));
+ /** @type {?HTMLElement} */
+ const badge = button.querySelector('.action-button-badge');
if (badge !== null) {
const badgeData = badge.dataset;
if (allNoteIds.length > 1) {
@@ -866,13 +868,17 @@ export class DisplayAnki {
const noteIds = this._getNodeNoteIds(node);
if (noteIds.length === 0) { return; }
- const menuContainerNode = /** @type {HTMLElement} */ (this._display.displayGenerator.instantiateTemplate('view-note-button-popup-menu'));
- const menuBodyNode = /** @type {HTMLElement} */ (menuContainerNode.querySelector('.popup-menu-body'));
+ /** @type {HTMLElement} */
+ const menuContainerNode = this._display.displayGenerator.instantiateTemplate('view-note-button-popup-menu');
+ /** @type {HTMLElement} */
+ const menuBodyNode = querySelectorNotNull(menuContainerNode, '.popup-menu-body');
for (let i = 0, ii = noteIds.length; i < ii; ++i) {
const noteId = noteIds[i];
- const item = /** @type {HTMLElement} */ (this._display.displayGenerator.instantiateTemplate('view-note-button-popup-menu-item'));
- const label = /** @type {Element} */ (item.querySelector('.popup-menu-item-label'));
+ /** @type {HTMLElement} */
+ const item = this._display.displayGenerator.instantiateTemplate('view-note-button-popup-menu-item');
+ /** @type {Element} */
+ const label = querySelectorNotNull(item, '.popup-menu-item-label');
label.textContent = `Note ${i + 1}: ${noteId}`;
item.dataset.menuAction = 'viewNote';
item.dataset.noteIds = `${noteId}`;