diff options
author | Cashew <52880648+Scrub1492@users.noreply.github.com> | 2023-12-20 21:36:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 12:36:27 +0000 |
commit | 229f04ba358b3485fa7952088e03dad9e651bb23 (patch) | |
tree | dfb4a0431368e2067d7e6f5d9ce08bf88e1730cd /ext/js/background | |
parent | 8b943cc97fab890085448122e7c13dd035d0e238 (diff) |
rename variables (#409)
* rename variables
* add comment to ambiguous variable
* rename variables
* add comments
* rename functions
Diffstat (limited to 'ext/js/background')
-rw-r--r-- | ext/js/background/backend.js | 40 | ||||
-rw-r--r-- | ext/js/background/offscreen-proxy.js | 12 |
2 files changed, 26 insertions, 26 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; } diff --git a/ext/js/background/offscreen-proxy.js b/ext/js/background/offscreen-proxy.js index 63f619fa..dfd342b4 100644 --- a/ext/js/background/offscreen-proxy.js +++ b/ext/js/background/offscreen-proxy.js @@ -95,16 +95,16 @@ export class OffscreenProxy { * @throws {Error} */ _getMessageResponseResult(response) { - const error = chrome.runtime.lastError; - if (error) { - throw new Error(error.message); + const runtimeError = chrome.runtime.lastError; + if (typeof runtimeError !== 'undefined') { + throw new Error(runtimeError.message); } if (!isObject(response)) { throw new Error('Offscreen document did not respond'); } - const error2 = response.error; - if (error2) { - throw ExtensionError.deserialize(error2); + const responseError = response.error; + if (responseError) { + throw ExtensionError.deserialize(responseError); } return response.result; } |