From a9fb56688434164e30f8f94868c652be7e7d69ad Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 13 Nov 2016 19:10:28 -0800 Subject: WIP --- ext/bg/guide.html | 3 ++- ext/bg/js/database.js | 12 ++++++++++++ ext/bg/js/options-form.js | 27 +++++++++++++++++++++------ ext/bg/options.html | 6 +++--- 4 files changed, 38 insertions(+), 10 deletions(-) (limited to 'ext') diff --git a/ext/bg/guide.html b/ext/bg/guide.html index e5ec59d7..d6809139 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -2,7 +2,7 @@ - Yomichan + Welcome to Yomichan! @@ -25,6 +25,7 @@
  1. Left-click on the icon to enable or disable Yomichan for the current browser instance.
  2. Right-click on the icon and select Options to open the Yomichan options page.
  3. +
  4. Import any dictionaries (bundled or custom) you wish to use for Kanji and term searches.
  5. Hold down Shift (or the middle mouse button) as you hover over text to see term definitions.
  6. Resize the definitions window by dragging the bottom-left corner inwards or outwards.
  7. Click on Kanji in the definition window to view additional information about that character.
  8. diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 5931e172..0621f1d6 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -39,6 +39,18 @@ class Database { return this.db.open(); } + purge() { + if (this.db === null) { + return Promise.reject('database not initialized'); + } + + this.db.close(); + return this.db.delete().then(() => { + this.db = null; + this.prepare(); + }); + } + findTerm(term, dictionaries) { 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 015c9a0a..68a18d8f 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -134,20 +134,19 @@ function onDictionaryDelete() { dictProgress.find('div').css('width', `${current / total * 100.0}%`); }; - database().deleteDictionary(dictGroup.data('title'), callback).then(() => { - dictGroup.slideUp(); - }).catch(error => { + database().deleteDictionary(dictGroup.data('title'), callback).catch(error => { dictError.show().find('span').text(error); }).then(() => { dictSpinner.hide(); dictProgress.hide(); dictControls.show(); + return loadOptions().then(opts => populateDictionaries(opts)); }); } function onDictionaryImport() { - const dictImport = $(this); - dictImport.prop('disabled', true); + const dictImporter = $('#dict-importer'); + dictImporter.hide(); const dictError = $('#dict-error'); dictError.hide(); @@ -174,7 +173,7 @@ function onDictionaryImport() { }).catch(error => { dictError.show().find('span').text(error); }).then(() => { - dictImport.prop('disabled', false); + dictImporter.show(); dictUrl.val(''); dictUrl.trigger('input'); dictProgress.hide(); @@ -313,6 +312,21 @@ function populateDictionaries(opts) { }); } +function onPurgeDb() { + const dictError = $('#dict-error'); + dictError.hide(); + + const dictSpinner = $('#dict-spinner'); + dictSpinner.show(); + + return database().purge().catch(error => { + dictError.show().find('span').text(error); + }).then(() => { + dictSpinner.hide(); + return loadOptions().then(opts => populateDictionaries(opts)); + }); +} + function onOptionsChanged(e) { if (!e.originalEvent && !e.isTrigger) { return; @@ -383,6 +397,7 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + $('#dict-purge').click(onPurgeDb); $('#dict-importer a').click(onDictionarySetUrl); $('#dict-import').click(onDictionaryImport); $('#dict-url').on('input', onDictionaryUpdateUrl); diff --git a/ext/bg/options.html b/ext/bg/options.html index 6d745b93..c3450c39 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -73,7 +73,7 @@

    Yomichan can import both bundled and custom (see the Yomichan Import page for details) dictionaries. Although it is also possible to delete unneeded dictionaries, this operation is extremely slow and it is often - easier to disable them or simply reset the database. Finally, please make sure to + easier to disable them or simply purge the database. Finally, please make sure to wait for import and delete operations to complete before closing this page.

    @@ -81,7 +81,7 @@
    No dictionaries found: - please use the dropdown below to install packaged and external dictionaries + please use the drop down below to install packaged and external dictionaries
    @@ -106,7 +106,7 @@
    -
    +
    -- cgit v1.2.3