aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/display-anki.js1
-rw-r--r--ext/js/display/display-history.js10
-rw-r--r--ext/js/display/display.js31
3 files changed, 33 insertions, 9 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js
index fb7bd85f..9a6b96c7 100644
--- a/ext/js/display/display-anki.js
+++ b/ext/js/display/display-anki.js
@@ -376,6 +376,7 @@ export class DisplayAnki {
_updateAdderButtons(dictionaryEntryDetails) {
const displayTags = this._displayTags;
for (let i = 0, ii = dictionaryEntryDetails.length; i < ii; ++i) {
+ /** @type {?Set<number>} */
let allNoteIds = null;
for (const {mode, canAdd, noteIds, noteInfos, ankiError} of dictionaryEntryDetails[i].modeMap.values()) {
const button = this._adderButtonFind(i, mode);
diff --git a/ext/js/display/display-history.js b/ext/js/display/display-history.js
index 67690219..bc4f1539 100644
--- a/ext/js/display/display-history.js
+++ b/ext/js/display/display-history.js
@@ -37,9 +37,15 @@ export class DisplayHistory extends EventDispatcher {
this._historyMap = new Map();
const historyState = history.state;
- const {id, state} = isObject(historyState) ? historyState : {id: null, state: null};
+ const {id, state} = (
+ typeof historyState === 'object' && historyState !== null ?
+ historyState :
+ {id: null, state: null}
+ );
+ /** @type {?import('display-history').EntryState} */
+ const stateObject = typeof state === 'object' || state === null ? state : null;
/** @type {import('display-history').Entry} */
- this._current = this._createHistoryEntry(id, location.href, state, null, null);
+ this._current = this._createHistoryEntry(id, location.href, stateObject, null, null);
}
/** @type {?import('display-history').EntryState} */
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index 750e0d69..f6efb5ac 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -1934,20 +1934,28 @@ export class Display extends EventDispatcher {
this._hotkeyHandler.setHotkeys(this._pageType, options.inputs.hotkeys);
}
- /** */
- async _closeTab() {
- const tab = await new Promise((resolve, reject) => {
+ /**
+ * @returns {Promise<?chrome.tabs.Tab>}
+ */
+ _getCurrentTab() {
+ return new Promise((resolve, reject) => {
chrome.tabs.getCurrent((result) => {
const e = chrome.runtime.lastError;
if (e) {
reject(new Error(e.message));
} else {
- resolve(result);
+ resolve(typeof result !== 'undefined' ? result : null);
}
});
});
- const tabId = tab.id;
- await /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
+ }
+
+ /**
+ * @param {number} tabId
+ * @returns {Promise<void>}
+ */
+ _removeTab(tabId) {
+ return new Promise((resolve, reject) => {
chrome.tabs.remove(tabId, () => {
const e = chrome.runtime.lastError;
if (e) {
@@ -1956,7 +1964,16 @@ export class Display extends EventDispatcher {
resolve();
}
});
- }));
+ });
+ }
+
+ /** */
+ async _closeTab() {
+ const tab = await this._getCurrentTab();
+ if (tab === null) { return; }
+ const tabId = tab.id;
+ if (typeof tabId === 'undefined') { return; }
+ await this._removeTab(tabId);
}
/** */