summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-08-05 14:57:33 -0700
committerAlex Yatskov <alex@foosoft.net>2017-08-05 14:57:33 -0700
commit257c864bb5ca5ef9afb4d92b9d29a7f479bc50b4 (patch)
tree70a32bf1215ecea2d6cbf8b4febadc7f293cfba1 /ext/bg/js/dictionary.js
parentb2003a0a560a9bd469e23e860c39dc5b21412021 (diff)
fix anki
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 73efe7d1..6f9b30e4 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -231,3 +231,43 @@ function dictFieldFormat(field, definition, mode, options) {
return field;
}
+
+function dictNoteFormat(definition, mode, options) {
+ const note = {fields: {}, tags: options.anki.tags};
+ let fields = [];
+
+ if (mode === 'kanji') {
+ fields = options.anki.kanji.fields;
+ note.deckName = options.anki.kanji.deck;
+ note.modelName = options.anki.kanji.model;
+ } else {
+ fields = options.anki.terms.fields;
+ note.deckName = options.anki.terms.deck;
+ note.modelName = options.anki.terms.model;
+
+ if (definition.audio) {
+ const audio = {
+ url: definition.audio.url,
+ filename: definition.audio.filename,
+ skipHash: '7e2c2f954ef6051373ba916f000168dc',
+ fields: []
+ };
+
+ for (const name in fields) {
+ if (fields[name].includes('{audio}')) {
+ audio.fields.push(name);
+ }
+ }
+
+ if (audio.fields.length > 0) {
+ note.audio = audio;
+ }
+ }
+ }
+
+ for (const name in fields) {
+ note.fields[name] = dictFieldFormat(fields[name], definition, mode, options);
+ }
+
+ return note;
+}