summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js49
1 files changed, 16 insertions, 33 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 47e68072..df979c6f 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -58,7 +58,6 @@ class Backend {
useCache: false
});
this._ankiNoteBuilder = new AnkiNoteBuilder({
- anki: this._anki,
audioSystem: this._audioSystem,
renderTemplate: this._renderTemplate.bind(this),
getClipboardImage: this._onApiClipboardImageGet.bind(this),
@@ -446,33 +445,8 @@ class Backend {
async _onApiDefinitionAdd({definition, mode, context, ownerFrameId, optionsContext}, sender) {
const options = this.getOptions(optionsContext);
const templates = this._getTemplates(options);
- const fields = (
- mode === 'kanji' ?
- options.anki.kanji.fields :
- options.anki.terms.fields
- );
-
- if (mode !== 'kanji') {
- const {customSourceUrl} = options.audio;
- await this._ankiNoteBuilder.injectAudio(
- definition,
- fields,
- options.audio.sources,
- customSourceUrl
- );
- }
-
- await this._ankiNoteBuilder.injectClipboardImage(definition, fields);
-
const {id: tabId, windowId} = (sender && sender.tab ? sender.tab : {});
- const {format, quality} = options.anki.screenshot;
- await this._ankiNoteBuilder.injectScreenshot(
- definition,
- fields,
- {windowId, tabId, ownerFrameId, format, quality}
- );
-
- const note = await this._createNote(definition, mode, context, options, templates);
+ const note = await this._createNote(definition, mode, context, options, templates, true, {windowId, tabId, ownerFrameId});
return this._anki.addNote(note);
}
@@ -485,7 +459,7 @@ class Backend {
const notePromises = [];
for (const definition of definitions) {
for (const mode of modes) {
- const notePromise = this._createNote(definition, mode, context, options, templates);
+ const notePromise = this._createNote(definition, mode, context, options, templates, false, null);
notePromises.push(notePromise);
}
}
@@ -1611,11 +1585,17 @@ class Backend {
});
}
- async _createNote(definition, mode, context, options, templates) {
- const {general: {resultOutputMode, compactGlossaries}, anki: ankiOptions} = options;
- const {tags, duplicateScope} = ankiOptions;
- const modeOptions = (mode === 'kanji') ? ankiOptions.kanji : ankiOptions.terms;
+ async _createNote(definition, mode, context, options, templates, injectMedia, screenshotTarget) {
+ const {
+ general: {resultOutputMode, compactGlossaries},
+ anki: {tags, duplicateScope, kanji, terms, screenshot: {format, quality}},
+ audio: {sources, customSourceUrl}
+ } = options;
+ const modeOptions = (mode === 'kanji') ? kanji : terms;
+ const {windowId, tabId, ownerFrameId} = (isObject(screenshotTarget) ? screenshotTarget : {});
+
return await this._ankiNoteBuilder.createNote({
+ anki: injectMedia ? this._anki : null,
definition,
mode,
context,
@@ -1624,7 +1604,10 @@ class Backend {
duplicateScope,
resultOutputMode,
compactGlossaries,
- modeOptions
+ modeOptions,
+ audioDetails: {sources, customSourceUrl},
+ screenshotDetails: {windowId, tabId, ownerFrameId, format, quality},
+ clipboardImage: true
});
}