From c24e179b10d31c445ab6393fe1a39b570887a3aa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 5 Nov 2016 18:24:45 -0700 Subject: WIP --- ext/bg/js/dictionary.js | 12 ++++++++++-- ext/bg/js/options-form.js | 11 +++++++++++ ext/bg/options.html | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 37a799a6..aa5f0b47 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -20,7 +20,7 @@ class Dictionary { constructor() { this.db = null; - this.dbVer = 5; + this.dbVer = 4; this.entities = null; } @@ -131,6 +131,14 @@ class Dictionary { }); } + getDictionaries() { + if (this.db === null) { + return Promise.reject('database not initialized'); + } + + return this.db.dictionaries.toArray(); + } + importTermDict(indexUrl, callback) { if (this.db === null) { return Promise.reject('database not initialized'); @@ -204,6 +212,6 @@ class Dictionary { }); }; - return importJsonDb(indexUrl, null, entriesLoaded); + return importJsonDb(indexUrl, indexLoaded, entriesLoaded); } } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index eb562142..589d92b1 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -154,6 +154,16 @@ function populateAnkiDeckAndModel(opts) { }); } +function populateDictionaries() { + const dictionaries = $('.dictionaries'); + yomichan().translator.dictionary.getDictionaries().then(rows => { + for (const row of rows) { + const dictionary = $('

').text(row.dictionary); + dictionaries.append(dictionary); + } + }); +} + function populateAnkiFields(element, opts) { const table = element.closest('.tab-pane').find('.anki-fields'); table.find('tbody').remove(); @@ -274,6 +284,7 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + populateDictionaries(); populateAnkiDeckAndModel(opts); updateVisibility(opts); }); diff --git a/ext/bg/options.html b/ext/bg/options.html index 458174bb..77d7edf1 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -65,7 +65,7 @@

Dictionaries

-
+
-- cgit v1.2.3