From 7cc20964b5ae69967945a802c4137be9052ea93b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 27 Dec 2023 00:59:33 -0500 Subject: Google docs fixes (#455) * Simplify GoogleDocsUtil deferred import * Remove loadExtensionScripts --- ext/js/app/frontend.js | 16 ++-------------- ext/js/background/backend.js | 12 ------------ ext/js/comm/api.js | 8 -------- types/ext/api.d.ts | 6 ------ 4 files changed, 2 insertions(+), 40 deletions(-) diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index c8b63813..b68b55f3 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -import {GoogleDocsUtil} from '../accessibility/google-docs-util.js'; import {EventListenerCollection, invokeMessageHandler, log, promiseAnimationFrame} from '../core.js'; import {DocumentUtil} from '../dom/document-util.js'; import {TextSourceElement} from '../dom/text-source-element.js'; @@ -964,27 +963,16 @@ export class Frontend { _prepareSiteSpecific() { switch (location.hostname.toLowerCase()) { case 'docs.google.com': - this._prepareGoogleDocsWrapper(); + this._prepareGoogleDocs(); break; } } - /** - * @returns {Promise} - */ - async _prepareGoogleDocsWrapper() { - if (typeof GoogleDocsUtil !== 'undefined') { return; } - await yomitan.api.loadExtensionScripts([ - '/js/accessibility/google-docs-util.js' - ]); - this._prepareGoogleDocs(); - } - /** * @returns {Promise} */ async _prepareGoogleDocs() { - if (typeof GoogleDocsUtil === 'undefined') { return; } + const {GoogleDocsUtil} = await import('../accessibility/google-docs-util.js'); DocumentUtil.registerGetRangeFromPointHandler(GoogleDocsUtil.getRangeFromPoint.bind(GoogleDocsUtil)); } } diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index a4cf6949..765d17d9 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -189,7 +189,6 @@ export class Backend { ['textHasJapaneseCharacters', this._onApiTextHasJapaneseCharacters.bind(this)], ['getTermFrequencies', this._onApiGetTermFrequencies.bind(this)], ['findAnkiNotes', this._onApiFindAnkiNotes.bind(this)], - ['loadExtensionScripts', this._onApiLoadExtensionScripts.bind(this)], ['openCrossFramePort', this._onApiOpenCrossFramePort.bind(this)] ]); /* eslint-enable no-multi-spaces */ @@ -846,17 +845,6 @@ export class Backend { return await this._anki.findNotes(query); } - /** @type {import('api').ApiHandler<'loadExtensionScripts'>} */ - async _onApiLoadExtensionScripts({files}, sender) { - if (!sender || !sender.tab) { throw new Error('Invalid sender'); } - const tabId = sender.tab.id; - if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); } - const {frameId} = sender; - for (const file of files) { - await this._scriptManager.injectScript(file, tabId, frameId, false); - } - } - /** @type {import('api').ApiHandler<'openCrossFramePort'>} */ _onApiOpenCrossFramePort({targetTabId, targetFrameId}, sender) { const sourceTabId = (sender && sender.tab ? sender.tab.id : null); diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index f2d4d545..c0cfae16 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -354,14 +354,6 @@ export class API { return this._invoke('findAnkiNotes', {query}); } - /** - * @param {import('api').ApiParam<'loadExtensionScripts', 'files'>} files - * @returns {Promise>} - */ - loadExtensionScripts(files) { - return this._invoke('loadExtensionScripts', {files}); - } - /** * @param {import('api').ApiParam<'openCrossFramePort', 'targetTabId'>} targetTabId * @param {import('api').ApiParam<'openCrossFramePort', 'targetFrameId'>} targetFrameId diff --git a/types/ext/api.d.ts b/types/ext/api.d.ts index 4e01de02..2d23040c 100644 --- a/types/ext/api.d.ts +++ b/types/ext/api.d.ts @@ -363,12 +363,6 @@ type ApiSurface = { }; return: Anki.NoteId[]; }; - loadExtensionScripts: { - params: { - files: string[]; - }; - return: void; - }; openCrossFramePort: { params: { targetTabId: number; -- cgit v1.2.3