aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/api.js31
-rw-r--r--ext/bg/js/dictionary.js5
-rw-r--r--ext/bg/js/handlebars.js2
3 files changed, 21 insertions, 17 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 2afe82a0..4676e2dc 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -66,22 +66,29 @@ async function apiDefinitionAdd(definition, mode) {
}
async function apiDefinitionsAddable(definitions, modes) {
- const notes = [];
- for (const definition of definitions) {
- for (const mode of modes) {
- notes.push(dictNoteFormat(definition, mode, utilBackend().options));
+ const states = [];
+
+ try {
+ const notes = [];
+ for (const definition of definitions) {
+ for (const mode of modes) {
+ notes.push(dictNoteFormat(definition, mode, utilBackend().options));
+ }
}
- }
- const results = await utilBackend().anki.canAddNotes(notes);
- const states = [];
- for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
- const state = {};
- for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
- state[modes[modeOffset]] = results[resultBase + modeOffset];
+ const results = await utilBackend().anki.canAddNotes(notes);
+ for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
+ const state = {};
+ for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
+ state[modes[modeOffset]] = results[resultBase + modeOffset];
+ }
+
+ states.push(state);
}
- states.push(state);
+ return states;
+ } catch (e) {
+ // NOP
}
return states;
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index fc479e85..2a80e2d0 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -223,10 +223,7 @@ function dictFieldFormat(field, definition, mode, options) {
modeKanji: mode === 'kanji'
};
- field = field.replace(
- `{${marker}}`,
- handlebarsRender('fields.html', data).trim()
- );
+ field = field.replace(`{${marker}}`, handlebarsRender('fields.html', data));
}
return field;
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js
index debb0690..a13de153 100644
--- a/ext/bg/js/handlebars.js
+++ b/ext/bg/js/handlebars.js
@@ -51,5 +51,5 @@ function handlebarsRender(template, data) {
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}
- return Handlebars.templates[template](data);
+ return Handlebars.templates[template](data).trim();
}