summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki-note-builder.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-06-27 19:04:19 -0700
committerAlex Yatskov <alex@foosoft.net>2020-06-27 19:04:19 -0700
commit88af95d20bfdbeb59d44bf0f0d46e772a329f839 (patch)
treed1dfa7268f274fed32061221c0f030e3647f9ae2 /ext/bg/js/anki-note-builder.js
parent19197a9a5d6a1f54a179d894577dfac513b97401 (diff)
parent0a6c08d0f53090a4ad48663bc5846ddae5723d52 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r--ext/bg/js/anki-note-builder.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 76199db7..7fe8962a 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -28,8 +28,9 @@ class AnkiNoteBuilder {
const modeOptions = isKanji ? options.anki.kanji : options.anki.terms;
const modeOptionsFieldEntries = Object.entries(modeOptions.fields);
+ const fields = {};
const note = {
- fields: {},
+ fields,
tags,
deckName: modeOptions.deck,
modelName: modeOptions.model,
@@ -38,8 +39,17 @@ class AnkiNoteBuilder {
}
};
- for (const [fieldName, fieldValue] of modeOptionsFieldEntries) {
- note.fields[fieldName] = await this.formatField(fieldValue, definition, mode, context, options, templates, null);
+ const formattedFieldValuePromises = [];
+ for (const [, fieldValue] of modeOptionsFieldEntries) {
+ const formattedFieldValuePromise = this.formatField(fieldValue, definition, mode, context, options, templates, null);
+ formattedFieldValuePromises.push(formattedFieldValuePromise);
+ }
+
+ const formattedFieldValues = await Promise.all(formattedFieldValuePromises);
+ for (let i = 0, ii = modeOptionsFieldEntries.length; i < ii; ++i) {
+ const fieldName = modeOptionsFieldEntries[i][0];
+ const formattedFieldValue = formattedFieldValues[i];
+ fields[fieldName] = formattedFieldValue;
}
return note;
@@ -155,7 +165,7 @@ class AnkiNoteBuilder {
}
static arrayBufferToBase64(arrayBuffer) {
- return window.btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
+ return btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
}
static stringReplaceAsync(str, regex, replacer) {