diff options
Diffstat (limited to 'ext/js/background')
-rw-r--r-- | ext/js/background/backend.js | 78 | ||||
-rw-r--r-- | ext/js/background/offscreen-proxy.js | 12 | ||||
-rw-r--r-- | ext/js/background/offscreen.js | 8 | ||||
-rw-r--r-- | ext/js/background/profile-conditions-util.js | 76 | ||||
-rw-r--r-- | ext/js/background/request-builder.js | 18 | ||||
-rw-r--r-- | ext/js/background/script-manager.js | 4 |
6 files changed, 98 insertions, 98 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 41989db3..a04566c9 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -75,7 +75,7 @@ export class Backend { // eslint-disable-next-line no-undef (typeof document === 'object' && document !== null ? document : null), '#clipboard-paste-target', - '#clipboard-rich-content-paste-target' + '#clipboard-rich-content-paste-target', ); } else { /** @type {?OffscreenProxy} */ @@ -185,7 +185,7 @@ export class Backend { ['getTermFrequencies', this._onApiGetTermFrequencies.bind(this)], ['findAnkiNotes', this._onApiFindAnkiNotes.bind(this)], ['openCrossFramePort', this._onApiOpenCrossFramePort.bind(this)], - ['getLanguageSummaries', this._onApiGetLanguageSummaries.bind(this)] + ['getLanguageSummaries', this._onApiGetLanguageSummaries.bind(this)], ]); /* eslint-enable @stylistic/no-multi-spaces */ @@ -195,7 +195,7 @@ export class Backend { ['openInfoPage', this._onCommandOpenInfoPage.bind(this)], ['openSettingsPage', this._onCommandOpenSettingsPage.bind(this)], ['openSearchPage', this._onCommandOpenSearchPage.bind(this)], - ['openPopupWindow', this._onCommandOpenPopupWindow.bind(this)] + ['openPopupWindow', this._onCommandOpenPopupWindow.bind(this)], ])); } @@ -214,7 +214,7 @@ export class Backend { (error) => { this._prepareError = true; this._prepareCompleteReject(error); - } + }, ); void promise.finally(() => this._updateBadge()); this._preparePromise = promise; @@ -319,7 +319,7 @@ export class Backend { const { general: {language}, - clipboard: {maximumSearchLength} + clipboard: {maximumSearchLength}, } = this._getProfileOptions({current: true}, false); if (!isTextLookupWorthy(text, language)) { return; } if (text.length > maximumSearchLength) { @@ -372,7 +372,7 @@ export class Backend { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument handler(...args); }, - () => {} // NOP + () => {}, // NOP ); }); } @@ -385,7 +385,7 @@ export class Backend { this._prepareCompletePromise.then( () => { this._onMessage(message, sender, sendResponse); }, - () => { sendResponse(); } + () => { sendResponse(); }, ); return true; } @@ -499,7 +499,7 @@ export class Backend { async _onApiParseText({text, optionsContext, scanLength, useInternalParser, useMecabParser}) { const [internalResults, mecabResults] = await Promise.all([ (useInternalParser ? this._textParseScanning(text, scanLength, optionsContext) : null), - (useMecabParser ? this._textParseMecab(text) : null) + (useMecabParser ? this._textParseMecab(text) : null), ]); /** @type {import('api').ParseTextResultItem[]} */ @@ -510,7 +510,7 @@ export class Backend { id: 'scan', source: 'scanning-parser', dictionary: null, - content: internalResults + content: internalResults, }); } @@ -520,7 +520,7 @@ export class Backend { id: `mecab-${dictionary}`, source: 'mecab', dictionary, - content + content, }); } } @@ -619,7 +619,7 @@ export class Backend { canAdd: valid, valid, noteIds: noteIds, - noteInfos: noteInfos + noteInfos: noteInfos, }; results.push(info); @@ -637,7 +637,7 @@ export class Backend { audioDetails, screenshotDetails, clipboardDetails, - dictionaryMediaDetails + dictionaryMediaDetails, ); } @@ -715,7 +715,7 @@ export class Backend { const frameId = sender.frameId; return { tabId: typeof tabId === 'number' ? tabId : null, - frameId: typeof frameId === 'number' ? frameId : null + frameId: typeof frameId === 'number' ? frameId : null, }; } @@ -928,13 +928,13 @@ export class Backend { const sourceDetails = { name: 'cross-frame-communication-port', otherTabId: targetTabId, - otherFrameId: targetFrameId + otherFrameId: targetFrameId, }; /** @type {import('cross-frame-api').CrossFrameCommunicationPortDetails} */ const targetDetails = { name: 'cross-frame-communication-port', otherTabId: sourceTabId, - otherFrameId: sourceFrameId + otherFrameId: sourceFrameId, }; /** @type {?chrome.runtime.Port} */ let sourcePort = chrome.tabs.connect(sourceTabId, {frameId: sourceFrameId, name: JSON.stringify(sourceDetails)}); @@ -1067,7 +1067,7 @@ export class Backend { path: 'general.enable', value: !options.general.enable, scope: 'profile', - optionsContext: {current: true} + optionsContext: {current: true}, }; await this._modifySettings([modification], 'backend'); } @@ -1172,7 +1172,7 @@ export class Backend { await this._sendMessageTabPromise( id, {action: 'searchDisplayControllerSetMode', params: {mode: 'popup'}}, - {frameId: 0} + {frameId: 0}, ); this._searchPopupTabId = id; @@ -1192,7 +1192,7 @@ export class Backend { const mode = await this._sendMessageTabPromise( id, {action: 'searchDisplayControllerGetMode'}, - {frameId: 0} + {frameId: 0}, ); return mode === 'popup'; } catch (e) { @@ -1226,7 +1226,7 @@ export class Backend { left: useLeft ? left : void 0, top: useTop ? top : void 0, type: windowType, - state: 'normal' + state: 'normal', }; } @@ -1245,7 +1245,7 @@ export class Backend { } else { resolve(/** @type {chrome.windows.Window} */ (result)); } - } + }, ); }); } @@ -1267,7 +1267,7 @@ export class Backend { } else { resolve(result); } - } + }, ); }); } @@ -1282,7 +1282,7 @@ export class Backend { await this._sendMessageTabPromise( tabId, {action: 'searchDisplayControllerUpdateSearchQuery', params: {text, animate}}, - {frameId: 0} + {frameId: 0}, ); } @@ -1455,7 +1455,7 @@ export class Backend { const {dictionaryEntries, originalTextLength} = await this._translator.findTerms( mode, text.substring(i, i + scanLength), - findTermsOptions + findTermsOptions, ); const codePoint = /** @type {number} */ (text.codePointAt(i)); const character = String.fromCodePoint(codePoint); @@ -1509,7 +1509,7 @@ export class Backend { for (const {text: text2, reading: reading2} of distributeFuriganaInflected( term.length > 0 ? term : source, jpConvertKatakanaToHiragana(reading), - source + source, )) { termParts.push({text: text2, reading: reading2}); } @@ -1721,7 +1721,7 @@ export class Backend { const response = await this._sendMessageTabPromise( tabId, {action: 'applicationGetUrl'}, - {frameId: 0} + {frameId: 0}, ); const url = typeof response === 'object' && response !== null ? /** @type {import('core').SerializableObject} */ (response).url : void 0; if (typeof url === 'string') { @@ -1799,7 +1799,7 @@ export class Backend { const checkTabPromises = tabs.map((tab) => checkTab(tab, add)); await Promise.race([ Promise.all(checkTabPromises), - promiseTimeout(timeout) + promiseTimeout(timeout), ]); return results; } else { @@ -1819,7 +1819,7 @@ export class Backend { await Promise.race([ promise, Promise.all(checkTabPromises), - promiseTimeout(timeout) + promiseTimeout(timeout), ]); resolve(); return result; @@ -1919,7 +1919,7 @@ export class Backend { cleanup(); resolve(); }, - () => {} // NOP + () => {}, // NOP ); if (timeout !== null) { @@ -2136,7 +2136,7 @@ export class Backend { clipboardText, audioFileName, dictionaryMedia, - errors: errors + errors: errors, }; } @@ -2161,7 +2161,7 @@ export class Backend { preferredAudioIndex, term, reading, - idleTimeout + idleTimeout, )); } catch (e) { const error = this._getAudioDownloadError(e); @@ -2269,7 +2269,7 @@ export class Backend { fileName = this._generateAnkiNoteMediaFileName( `yomitan_dictionary_media_${i + 1}`, extension !== null ? extension : '', - timestamp + timestamp, ); try { fileName = await ankiConnect.storeMediaFile(fileName, content); @@ -2443,8 +2443,8 @@ export class Backend { scanning: {alphanumeric}, translation: { textReplacements: textReplacementsOptions, - searchResolution - } + searchResolution, + }, } = options; const textReplacements = this._getTranslatorTextReplacements(textReplacementsOptions); let excludeDictionaryDefinitions = null; @@ -2454,7 +2454,7 @@ export class Backend { priority: 0, allowSecondarySearches: false, partsOfSpeechFilter: true, - useDeinflections: true + useDeinflections: true, }); excludeDictionaryDefinitions = new Set(); excludeDictionaryDefinitions.add(mainDictionary); @@ -2470,7 +2470,7 @@ export class Backend { textReplacements, enabledDictionaryMap, excludeDictionaryDefinitions, - language + language, }; } @@ -2483,7 +2483,7 @@ export class Backend { const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options); return { enabledDictionaryMap, - removeNonJapaneseCharacters: !options.scanning.alphanumeric + removeNonJapaneseCharacters: !options.scanning.alphanumeric, }; } @@ -2501,7 +2501,7 @@ export class Backend { priority, allowSecondarySearches, partsOfSpeechFilter, - useDeinflections + useDeinflections, }); } return enabledDictionaryMap; @@ -2545,7 +2545,7 @@ export class Backend { if (!result.openedWelcomePage) { await Promise.all([ this._openWelcomeGuidePage(), - chrome.storage.session.set({openedWelcomePage: true}) + chrome.storage.session.set({openedWelcomePage: true}), ]); } } @@ -2625,7 +2625,7 @@ export class Backend { } else { resolve(result); } - } + }, ); }); } diff --git a/ext/js/background/offscreen-proxy.js b/ext/js/background/offscreen-proxy.js index 9e7b5b74..7150cc29 100644 --- a/ext/js/background/offscreen-proxy.js +++ b/ext/js/background/offscreen-proxy.js @@ -72,9 +72,9 @@ export class OffscreenProxy { this._creatingOffscreen = chrome.offscreen.createDocument({ url: 'offscreen.html', reasons: [ - /** @type {chrome.offscreen.Reason} */ ('CLIPBOARD') + /** @type {chrome.offscreen.Reason} */ ('CLIPBOARD'), ], - justification: 'Access to the clipboard' + justification: 'Access to the clipboard', }); await this._creatingOffscreen; this._creatingOffscreen = null; @@ -96,9 +96,9 @@ export class OffscreenProxy { const contexts = await chrome.runtime.getContexts({ contextTypes: [ - /** @type {chrome.runtime.ContextType} */ ('OFFSCREEN_DOCUMENT') + /** @type {chrome.runtime.ContextType} */ ('OFFSCREEN_DOCUMENT'), ], - documentUrls: [offscreenUrl] + documentUrls: [offscreenUrl], }); return contexts.length > 0; } @@ -199,7 +199,7 @@ export class TranslatorProxy { /** @type {import('offscreen').FindKanjiOptionsOffscreen} */ const modifiedOptions = { ...options, - enabledDictionaryMap: enabledDictionaryMapList + enabledDictionaryMap: enabledDictionaryMapList, }; return this._offscreen.sendMessagePromise({action: 'findKanjiOffscreen', params: {text, options: modifiedOptions}}); } @@ -222,7 +222,7 @@ export class TranslatorProxy { ...options, enabledDictionaryMap: enabledDictionaryMapList, excludeDictionaryDefinitions: excludeDictionaryDefinitionsList, - textReplacements: textReplacementsSerialized + textReplacements: textReplacementsSerialized, }; return this._offscreen.sendMessagePromise({action: 'findTermsOffscreen', params: {mode, text, options: modifiedOptions}}); } diff --git a/ext/js/background/offscreen.js b/ext/js/background/offscreen.js index bab4d0c9..5e901005 100644 --- a/ext/js/background/offscreen.js +++ b/ext/js/background/offscreen.js @@ -39,7 +39,7 @@ export class Offscreen { this._clipboardReader = new ClipboardReader( (typeof document === 'object' && document !== null ? document : null), '#clipboard-paste-target', - '#clipboard-rich-content-paste-target' + '#clipboard-rich-content-paste-target', ); @@ -57,7 +57,7 @@ export class Offscreen { ['findKanjiOffscreen', this._findKanjiHandler.bind(this)], ['findTermsOffscreen', this._findTermsHandler.bind(this)], ['getTermFrequenciesOffscreen', this._getTermFrequenciesHandler.bind(this)], - ['clearDatabaseCachesOffscreen', this._clearDatabaseCachesHandler.bind(this)] + ['clearDatabaseCachesOffscreen', this._clearDatabaseCachesHandler.bind(this)], ]); /* eslint-enable @stylistic/no-multi-spaces */ @@ -120,7 +120,7 @@ export class Offscreen { /** @type {import('translation').FindKanjiOptions} */ const modifiedOptions = { ...options, - enabledDictionaryMap: new Map(options.enabledDictionaryMap) + enabledDictionaryMap: new Map(options.enabledDictionaryMap), }; return await this._translator.findKanji(text, modifiedOptions); } @@ -147,7 +147,7 @@ export class Offscreen { ...options, enabledDictionaryMap, excludeDictionaryDefinitions, - textReplacements + textReplacements, }; return this._translator.findTerms(mode, text, modifiedOptions); } diff --git a/ext/js/background/profile-conditions-util.js b/ext/js/background/profile-conditions-util.js index 4e4e38d7..e7ee53f1 100644 --- a/ext/js/background/profile-conditions-util.js +++ b/ext/js/background/profile-conditions-util.js @@ -31,18 +31,18 @@ const descriptors = new Map([ ['lessThan', createSchemaPopupLevelLessThan.bind(this)], ['greaterThan', createSchemaPopupLevelGreaterThan.bind(this)], ['lessThanOrEqual', createSchemaPopupLevelLessThanOrEqual.bind(this)], - ['greaterThanOrEqual', createSchemaPopupLevelGreaterThanOrEqual.bind(this)] - ])) - } + ['greaterThanOrEqual', createSchemaPopupLevelGreaterThanOrEqual.bind(this)], + ])), + }, ], [ 'url', { operators: new Map(/** @type {import('profile-conditions-util').OperatorMapArray} */ ([ ['matchDomain', createSchemaUrlMatchDomain.bind(this)], - ['matchRegExp', createSchemaUrlMatchRegExp.bind(this)] - ])) - } + ['matchRegExp', createSchemaUrlMatchRegExp.bind(this)], + ])), + }, ], [ 'modifierKeys', @@ -51,9 +51,9 @@ const descriptors = new Map([ ['are', createSchemaModifierKeysAre.bind(this)], ['areNot', createSchemaModifierKeysAreNot.bind(this)], ['include', createSchemaModifierKeysInclude.bind(this)], - ['notInclude', createSchemaModifierKeysNotInclude.bind(this)] - ])) - } + ['notInclude', createSchemaModifierKeysNotInclude.bind(this)], + ])), + }, ], [ 'flags', @@ -62,10 +62,10 @@ const descriptors = new Map([ ['are', createSchemaFlagsAre.bind(this)], ['areNot', createSchemaFlagsAreNot.bind(this)], ['include', createSchemaFlagsInclude.bind(this)], - ['notInclude', createSchemaFlagsNotInclude.bind(this)] - ])) - } - ] + ['notInclude', createSchemaFlagsNotInclude.bind(this)], + ])), + }, + ], ]); /** @@ -156,8 +156,8 @@ function createSchemaPopupLevelEqual(value) { return { required: ['depth'], properties: { - depth: {const: number} - } + depth: {const: number}, + }, }; } @@ -168,8 +168,8 @@ function createSchemaPopupLevelEqual(value) { function createSchemaPopupLevelNotEqual(value) { return { not: { - anyOf: [createSchemaPopupLevelEqual(value)] - } + anyOf: [createSchemaPopupLevelEqual(value)], + }, }; } @@ -182,8 +182,8 @@ function createSchemaPopupLevelLessThan(value) { return { required: ['depth'], properties: { - depth: {type: 'number', exclusiveMaximum: number} - } + depth: {type: 'number', exclusiveMaximum: number}, + }, }; } @@ -196,8 +196,8 @@ function createSchemaPopupLevelGreaterThan(value) { return { required: ['depth'], properties: { - depth: {type: 'number', exclusiveMinimum: number} - } + depth: {type: 'number', exclusiveMinimum: number}, + }, }; } @@ -210,8 +210,8 @@ function createSchemaPopupLevelLessThanOrEqual(value) { return { required: ['depth'], properties: { - depth: {type: 'number', maximum: number} - } + depth: {type: 'number', maximum: number}, + }, }; } @@ -224,8 +224,8 @@ function createSchemaPopupLevelGreaterThanOrEqual(value) { return { required: ['depth'], properties: { - depth: {type: 'number', minimum: number} - } + depth: {type: 'number', minimum: number}, + }, }; } @@ -245,8 +245,8 @@ function createSchemaUrlMatchDomain(value) { return { required: ['domain'], properties: { - domain: {oneOf} - } + domain: {oneOf}, + }, }; } @@ -258,8 +258,8 @@ function createSchemaUrlMatchRegExp(value) { return { required: ['url'], properties: { - url: {type: 'string', pattern: value, patternFlags: 'i'} - } + url: {type: 'string', pattern: value, patternFlags: 'i'}, + }, }; } @@ -280,8 +280,8 @@ function createSchemaModifierKeysAre(value) { function createSchemaModifierKeysAreNot(value) { return { not: { - anyOf: [createSchemaArrayCheck('modifierKeys', value, true, false)] - } + anyOf: [createSchemaArrayCheck('modifierKeys', value, true, false)], + }, }; } @@ -318,8 +318,8 @@ function createSchemaFlagsAre(value) { function createSchemaFlagsAreNot(value) { return { not: { - anyOf: [createSchemaArrayCheck('flags', value, true, false)] - } + anyOf: [createSchemaArrayCheck('flags', value, true, false)], + }, }; } @@ -355,14 +355,14 @@ function createSchemaArrayCheck(key, value, exact, none) { if (item.length === 0) { continue; } containsList.push({ contains: { - const: item - } + const: item, + }, }); } const containsListCount = containsList.length; /** @type {import('ext/json-schema').Schema} */ const schema = { - type: 'array' + type: 'array', }; if (exact) { schema.maxItems = containsListCount; @@ -380,7 +380,7 @@ function createSchemaArrayCheck(key, value, exact, none) { return { required: [key], properties: { - [key]: schema - } + [key]: schema, + }, }; } diff --git a/ext/js/background/request-builder.js b/ext/js/background/request-builder.js index b23f16af..c2b83894 100644 --- a/ext/js/background/request-builder.js +++ b/ext/js/background/request-builder.js @@ -63,29 +63,29 @@ export class RequestBuilder { condition: { urlFilter: `|${this._escapeDnrUrl(url)}|`, resourceTypes: [ - /** @type {chrome.declarativeNetRequest.ResourceType} */ ('xmlhttprequest') - ] + /** @type {chrome.declarativeNetRequest.ResourceType} */ ('xmlhttprequest'), + ], }, action: { type: /** @type {chrome.declarativeNetRequest.RuleActionType} */ ('modifyHeaders'), requestHeaders: [ { operation: /** @type {chrome.declarativeNetRequest.HeaderOperation} */ ('remove'), - header: 'Cookie' + header: 'Cookie', }, { operation: /** @type {chrome.declarativeNetRequest.HeaderOperation} */ ('set'), header: 'Origin', - value: originUrl - } + value: originUrl, + }, ], responseHeaders: [ { operation: /** @type {chrome.declarativeNetRequest.HeaderOperation} */ ('remove'), - header: 'Set-Cookie' - } - ] - } + header: 'Set-Cookie', + }, + ], + }, }]; await this._updateSessionRules({addRules}); diff --git a/ext/js/background/script-manager.js b/ext/js/background/script-manager.js index ea1702e9..6c69a796 100644 --- a/ext/js/background/script-manager.js +++ b/ext/js/background/script-manager.js @@ -32,7 +32,7 @@ export function injectStylesheet(type, content, tabId, frameId, allFrames) { /** @type {chrome.scripting.InjectionTarget} */ const target = { tabId, - allFrames + allFrames, }; /** @type {chrome.scripting.CSSInjection} */ const details = ( @@ -124,7 +124,7 @@ function createContentScriptRegistrationOptions(details, id) { /** @type {chrome.scripting.RegisteredContentScript} */ const options = { id: id, - persistAcrossSessions: true + persistAcrossSessions: true, }; if (Array.isArray(css)) { options.css = [...css]; |