aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-09-24 16:41:21 -0400
committerGitHub <noreply@github.com>2022-09-24 16:41:21 -0400
commit115c3ce3d74188bb33d73f33f7546d05d6acbee8 (patch)
tree9cadc8d975b04d62d5909524655fa63beaa964ef /ext/js/background/backend.js
parent1e91bf151f43ad05138e862ba4a03abad6929e5f (diff)
API loadExtensionScripts (#2233)
* Inject MV3 scripts immediately * Add api.loadExtensionScripts
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index a3694dd3..20402539 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -130,7 +130,8 @@ class Backend {
['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}],
['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}],
['getTermFrequencies', {async: true, contentScript: true, handler: this._onApiGetTermFrequencies.bind(this)}],
- ['findAnkiNotes', {async: true, contentScript: true, handler: this._onApiFindAnkiNotes.bind(this)}]
+ ['findAnkiNotes', {async: true, contentScript: true, handler: this._onApiFindAnkiNotes.bind(this)}],
+ ['loadExtensionScripts', {async: true, contentScript: true, handler: this._onApiLoadExtensionScripts.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
]);
@@ -771,6 +772,16 @@ class Backend {
return await this._anki.findNotes(query);
}
+ 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, true, 'document_start');
+ }
+ }
+
// Command handlers
async _onCommandOpenSearchPage(params) {