fix anki network error dialog on search page, cleanup template
workaround
This commit is contained in:
parent
922d2cd468
commit
30fe3d2506
@ -66,22 +66,29 @@ async function apiDefinitionAdd(definition, mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function apiDefinitionsAddable(definitions, modes) {
|
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 results = await utilBackend().anki.canAddNotes(notes);
|
|
||||||
const states = [];
|
const states = [];
|
||||||
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
|
|
||||||
const state = {};
|
try {
|
||||||
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
|
const notes = [];
|
||||||
state[modes[modeOffset]] = results[resultBase + modeOffset];
|
for (const definition of definitions) {
|
||||||
|
for (const mode of modes) {
|
||||||
|
notes.push(dictNoteFormat(definition, mode, utilBackend().options));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states.push(state);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return states;
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
}
|
}
|
||||||
|
|
||||||
return states;
|
return states;
|
||||||
|
@ -223,10 +223,7 @@ function dictFieldFormat(field, definition, mode, options) {
|
|||||||
modeKanji: mode === 'kanji'
|
modeKanji: mode === 'kanji'
|
||||||
};
|
};
|
||||||
|
|
||||||
field = field.replace(
|
field = field.replace(`{${marker}}`, handlebarsRender('fields.html', data));
|
||||||
`{${marker}}`,
|
|
||||||
handlebarsRender('fields.html', data).trim()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return field;
|
return field;
|
||||||
|
@ -51,5 +51,5 @@ function handlebarsRender(template, data) {
|
|||||||
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
|
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Handlebars.templates[template](data);
|
return Handlebars.templates[template](data).trim();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user