diff options
| -rw-r--r-- | ext/bg/js/dictionary.js | 18 | ||||
| -rw-r--r-- | ext/bg/js/options-form.js | 14 | 
2 files changed, 28 insertions, 4 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index fe0284c9..f3de36f4 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -131,7 +131,7 @@ class Dictionary {          });      } -    getInfo() { +    getDictionaries() {          if (this.db === null) {              return Promise.reject('database not initialized');          } @@ -139,6 +139,22 @@ class Dictionary {          return this.db.dictionaries.toArray();      } +    deleteDictionary(title) { +        if (this.db === null) { +            return Promise.reject('database not initialized'); +        } + +        const tasks = [ +            this.db.terms.where('dictionary').equals(title).delete(), +            this.db.kanji.where('dictionary').equals(title).delete(), +            this.db.entities.where('dictionary').equals(title).delete() +        ]; + +        return Promise.all(tasks).then(() => { +            return this.db.dictionaries.where('title').equals(title).delete(); +        }); +    } +      importDb(indexUrl, callback) {          if (this.db === null) {              return Promise.reject('database not initialized'); diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 63e2d2f5..ea318092 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -166,7 +166,7 @@ function populateDictionaries(opts) {      const container = $('.dicts');      container.empty(); -    yomichan().translator.dictionary.getInfo().then(rows => { +    yomichan().translator.dictionary.getDictionaries().then(rows => {          rows.forEach(row => {              const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false};              const html = Handlebars.templates['dictionary.html']({ @@ -181,6 +181,13 @@ function populateDictionaries(opts) {              container.append($(html));          }); +        const dictDelete = $('.dict-delete'); +        dictDelete.click(() => { +            const dict = dictDelete.closest('.dict'); +            const title = dict.data('title'); +            yomichan().translator.dictionary.deleteDictionary(title).then(() => dict.slideUp()); +        }); +          container.find('.dict input').change(onOptionsChanged);      });  } @@ -301,8 +308,9 @@ $(document).ready(() => {              control.trigger('input');          }); -        $('#dict-import-url').on('input', () => { -            const disable = $('#dict-import-url').val().trim().length === 0; +        const dictImportUrl = $('#dict-import-url'); +        dictImportUrl.on('input', () => { +            const disable = dictImportUrl.val().trim().length === 0;              $('#dict-import-start').prop('disabled', disable);          });  |