Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google docs fixes #455

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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';
Expand Down Expand Up @@ -964,27 +963,16 @@ export class Frontend {
_prepareSiteSpecific() {
switch (location.hostname.toLowerCase()) {
case 'docs.google.com':
this._prepareGoogleDocsWrapper();
this._prepareGoogleDocs();
break;
}
}

/**
* @returns {Promise<void>}
*/
async _prepareGoogleDocsWrapper() {
if (typeof GoogleDocsUtil !== 'undefined') { return; }
await yomitan.api.loadExtensionScripts([
'/js/accessibility/google-docs-util.js'
]);
this._prepareGoogleDocs();
}

/**
* @returns {Promise<void>}
*/
async _prepareGoogleDocs() {
if (typeof GoogleDocsUtil === 'undefined') { return; }
const {GoogleDocsUtil} = await import('../accessibility/google-docs-util.js');
DocumentUtil.registerGetRangeFromPointHandler(GoogleDocsUtil.getRangeFromPoint.bind(GoogleDocsUtil));
}
}
12 changes: 0 additions & 12 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions ext/js/comm/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,6 @@ export class API {
return this._invoke('findAnkiNotes', {query});
}

/**
* @param {import('api').ApiParam<'loadExtensionScripts', 'files'>} files
* @returns {Promise<import('api').ApiReturn<'loadExtensionScripts'>>}
*/
loadExtensionScripts(files) {
return this._invoke('loadExtensionScripts', {files});
}

/**
* @param {import('api').ApiParam<'openCrossFramePort', 'targetTabId'>} targetTabId
* @param {import('api').ApiParam<'openCrossFramePort', 'targetFrameId'>} targetFrameId
Expand Down
6 changes: 0 additions & 6 deletions types/ext/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ type ApiSurface = {
};
return: Anki.NoteId[];
};
loadExtensionScripts: {
params: {
files: string[];
};
return: void;
};
openCrossFramePort: {
params: {
targetTabId: number;
Expand Down