Add api.injectAnkiNoteMedia (#803)
This commit is contained in:
parent
892f7ed3b8
commit
9ce682272c
@ -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; }
|
||||||
|
@ -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});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user