Add api.injectAnkiNoteMedia (#803)

This commit is contained in:
toasted-nutbread 2020-09-10 16:18:36 -04:00 committed by GitHub
parent 892f7ed3b8
commit 9ce682272c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -93,6 +93,7 @@ class Backend {
['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}], ['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}],
['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}], ['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}],
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.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)}], ['definitionAdd', {async: true, contentScript: true, handler: this._onApiDefinitionAdd.bind(this)}],
['definitionsAddable', {async: true, contentScript: true, handler: this._onApiDefinitionsAddable.bind(this)}], ['definitionsAddable', {async: true, contentScript: true, handler: this._onApiDefinitionsAddable.bind(this)}],
['noteView', {async: true, contentScript: true, handler: this._onApiNoteView.bind(this)}], ['noteView', {async: true, contentScript: true, handler: this._onApiNoteView.bind(this)}],
@ -472,6 +473,18 @@ class Backend {
return results; 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) { async _onApiDefinitionAdd({definition, mode, context, ownerFrameId, optionsContext}, sender) {
const options = this.getOptions(optionsContext); const options = this.getOptions(optionsContext);
const templates = this._getTemplates(options); const templates = this._getTemplates(options);
@ -1599,15 +1612,14 @@ class Backend {
const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, customSourceUrl} : null); 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 screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {windowId, tabId, ownerFrameId, format, quality} : null);
const clipboardImage = (this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image')); const clipboardImage = (this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'));
const {screenshotFileName, clipboardImageFileName, audioFileName} = await this._injectAnkNoteMedia( const {screenshotFileName, clipboardImageFileName, audioFileName} = await this._onApiInjectAnkiNoteMedia({
this._anki,
expression, expression,
reading, reading,
timestamp, timestamp,
audioDetails, audioDetails,
screenshotDetails, screenshotDetails,
clipboardImage clipboardImage
); });
if (screenshotFileName !== null) { definition.screenshotFileName = screenshotFileName; } if (screenshotFileName !== null) { definition.screenshotFileName = screenshotFileName; }
if (clipboardImageFileName !== null) { definition.clipboardImageFileName = clipboardImageFileName; } if (clipboardImageFileName !== null) { definition.clipboardImageFileName = clipboardImageFileName; }
if (audioFileName !== null) { definition.audioFileName = audioFileName; } if (audioFileName !== null) { definition.audioFileName = audioFileName; }

View File

@ -85,6 +85,10 @@ const api = (() => {
return this._invoke('getAnkiNoteInfo', {notes, duplicateScope}); 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) { definitionAdd(definition, mode, context, ownerFrameId, optionsContext) {
return this._invoke('definitionAdd', {definition, mode, context, ownerFrameId, optionsContext}); return this._invoke('definitionAdd', {definition, mode, context, ownerFrameId, optionsContext});
} }