summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-10 16:18:36 -0400
committerGitHub <noreply@github.com>2020-09-10 16:18:36 -0400
commit9ce682272c5d665bbbe9cbd1380416c3d22f9b04 (patch)
tree6f3dc44b0f90e49116bd6ca72c41df591ab46c6e
parent892f7ed3b8d4a97dd7fd8086a404c5e8ea1355fb (diff)
Add api.injectAnkiNoteMedia (#803)
-rw-r--r--ext/bg/js/backend.js18
-rw-r--r--ext/mixed/js/api.js4
2 files changed, 19 insertions, 3 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index e3ef1e88..3d1b1544 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -93,6 +93,7 @@ class Backend {
['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}],
['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}],
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}],
+ ['injectAnkiNoteMedia', {async: true, contentScript: true, handler: this._onApiInjectAnkiNoteMedia.bind(this)}],
['definitionAdd', {async: true, contentScript: true, handler: this._onApiDefinitionAdd.bind(this)}],
['definitionsAddable', {async: true, contentScript: true, handler: this._onApiDefinitionsAddable.bind(this)}],
['noteView', {async: true, contentScript: true, handler: this._onApiNoteView.bind(this)}],
@@ -472,6 +473,18 @@ class Backend {
return results;
}
+ async _onApiInjectAnkiNoteMedia({expression, reading, timestamp, audioDetails, screenshotDetails, clipboardImage}) {
+ return await this._injectAnkNoteMedia(
+ this._anki,
+ expression,
+ reading,
+ timestamp,
+ audioDetails,
+ screenshotDetails,
+ clipboardImage
+ );
+ }
+
async _onApiDefinitionAdd({definition, mode, context, ownerFrameId, optionsContext}, sender) {
const options = this.getOptions(optionsContext);
const templates = this._getTemplates(options);
@@ -1599,15 +1612,14 @@ class Backend {
const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, customSourceUrl} : null);
const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {windowId, tabId, ownerFrameId, format, quality} : null);
const clipboardImage = (this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'));
- const {screenshotFileName, clipboardImageFileName, audioFileName} = await this._injectAnkNoteMedia(
- this._anki,
+ const {screenshotFileName, clipboardImageFileName, audioFileName} = await this._onApiInjectAnkiNoteMedia({
expression,
reading,
timestamp,
audioDetails,
screenshotDetails,
clipboardImage
- );
+ });
if (screenshotFileName !== null) { definition.screenshotFileName = screenshotFileName; }
if (clipboardImageFileName !== null) { definition.clipboardImageFileName = clipboardImageFileName; }
if (audioFileName !== null) { definition.audioFileName = audioFileName; }
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index d9569187..4a1b0c11 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -85,6 +85,10 @@ const api = (() => {
return this._invoke('getAnkiNoteInfo', {notes, duplicateScope});
}
+ injectAnkiNoteMedia(expression, reading, timestamp, audioDetails, screenshotDetails, clipboardImage) {
+ return this._invoke('injectAnkiNoteMedia', {expression, reading, timestamp, audioDetails, screenshotDetails, clipboardImage});
+ }
+
definitionAdd(definition, mode, context, ownerFrameId, optionsContext) {
return this._invoke('definitionAdd', {definition, mode, context, ownerFrameId, optionsContext});
}