diff options
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r-- | ext/js/background/backend.js | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 99aa0c5d..d62c852b 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -331,7 +331,7 @@ export class Backend { text = text.substring(0, maximumSearchLength); } try { - const {tab, created} = await this._getOrCreateSearchPopup(); + const {tab, created} = await this._getOrCreateSearchPopupWrapper(); const {id} = tab; if (typeof id !== 'number') { throw new Error('Tab does not have an id'); @@ -799,7 +799,7 @@ export class Backend { /** @type {import('api').Handler<import('api').GetOrCreateSearchPopupDetails, import('api').GetOrCreateSearchPopupResult>} */ async _onApiGetOrCreateSearchPopup({focus = false, text}) { - const {tab, created} = await this._getOrCreateSearchPopup(); + const {tab, created} = await this._getOrCreateSearchPopupWrapper(); if (focus === true || (focus === 'ifCreated' && created)) { await this._focusTab(tab); } @@ -960,18 +960,18 @@ export class Backend { const queryParams = {}; if (query.length > 0) { queryParams.query = query; } const queryString = new URLSearchParams(queryParams).toString(); - let url = baseUrl; + let queryUrl = baseUrl; if (queryString.length > 0) { - url += `?${queryString}`; + queryUrl += `?${queryString}`; } /** @type {import('backend').FindTabsPredicate} */ - const predicate = ({url: url2}) => { - if (url2 === null || !url2.startsWith(baseUrl)) { return false; } - const parsedUrl = new URL(url2); - const baseUrl2 = `${parsedUrl.origin}${parsedUrl.pathname}`; - const mode2 = parsedUrl.searchParams.get('mode'); - return baseUrl2 === baseUrl && (mode2 === mode || (!mode2 && mode === 'existingOrNewTab')); + const predicate = ({url}) => { + if (url === null || !url.startsWith(baseUrl)) { return false; } + const parsedUrl = new URL(url); + const parsedBaseUrl = `${parsedUrl.origin}${parsedUrl.pathname}`; + const parsedMode = parsedUrl.searchParams.get('mode'); + return parsedBaseUrl === baseUrl && (parsedMode === mode || (!parsedMode && mode === 'existingOrNewTab')); }; const openInTab = async () => { @@ -997,10 +997,10 @@ export class Backend { } catch (e) { // NOP } - await this._createTab(url); + await this._createTab(queryUrl); return; case 'newTab': - await this._createTab(url); + await this._createTab(queryUrl); return; } } @@ -1072,9 +1072,9 @@ export class Backend { /** * @returns {Promise<{tab: chrome.tabs.Tab, created: boolean}>} */ - _getOrCreateSearchPopup() { + _getOrCreateSearchPopupWrapper() { if (this._searchPopupTabCreatePromise === null) { - const promise = this._getOrCreateSearchPopup2(); + const promise = this._getOrCreateSearchPopup(); this._searchPopupTabCreatePromise = promise; promise.then(() => { this._searchPopupTabCreatePromise = null; }); } @@ -1084,7 +1084,7 @@ export class Backend { /** * @returns {Promise<{tab: chrome.tabs.Tab, created: boolean}>} */ - async _getOrCreateSearchPopup2() { + async _getOrCreateSearchPopup() { // Use existing tab const baseUrl = chrome.runtime.getURL('/search.html'); /** @@ -2418,13 +2418,13 @@ export class Backend { if (error instanceof ExtensionError && typeof error.data === 'object' && error.data !== null) { const {errors} = /** @type {import('core').SerializableObject} */ (error.data); if (Array.isArray(errors)) { - for (const error2 of errors) { - if (!(error2 instanceof Error)) { continue; } - if (error2.name === 'AbortError') { + for (const errorDetail of errors) { + if (!(errorDetail instanceof Error)) { continue; } + if (errorDetail.name === 'AbortError') { return this._createAudioDownloadError('Audio download was cancelled due to an idle timeout', 'audio-download-idle-timeout', errors); } - if (!(error2 instanceof ExtensionError)) { continue; } - const {data} = error2; + if (!(errorDetail instanceof ExtensionError)) { continue; } + const {data} = errorDetail; if (!(typeof data === 'object' && data !== null)) { continue; } const {details} = /** @type {import('core').SerializableObject} */ (data); if (!(typeof details === 'object' && details !== null)) { continue; } |