summaryrefslogtreecommitdiff
path: root/ext/bg/js/options.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-06-26 20:23:53 -0700
committerAlex Yatskov <alex@foosoft.net>2017-06-26 20:23:53 -0700
commitc23298dbb2f3f26ff96da80f69d70051cc14f733 (patch)
treeda544b095a4665655013bccd115b9efad5c8a7e1 /ext/bg/js/options.js
parent16baf9a400ac11a1c4f53ba6665db03a900511e0 (diff)
parent21b29ff135269fe33f5ae064abc74cfde6f2a5f5 (diff)
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/bg/js/options.js')
-rw-r--r--ext/bg/js/options.js43
1 files changed, 11 insertions, 32 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index c3321012..5aa18366 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -140,9 +140,7 @@ $(document).ready(() => {
$('#scan-modifier-key').val(options.scanning.modifier);
$('#dict-purge').click(onDictionaryPurge);
- $('#dict-importer a').click(onDictionarySetUrl);
- $('#dict-import').click(onDictionaryImport);
- $('#dict-url').on('input', onDictionaryUpdateUrl);
+ $('#dict-file').change(onDictionaryImport);
$('#anki-enable').prop('checked', options.anki.enable);
$('#card-tags').val(options.anki.tags.join(' '));
@@ -252,50 +250,31 @@ function onDictionaryPurge(e) {
});
}
-function onDictionaryImport() {
+function onDictionaryImport(e) {
dictionaryErrorShow(null);
dictionarySpinnerShow(true);
- const dictUrl = $('#dict-url');
+ const dictFile = $('#dict-file');
const dictImporter = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
+ const updateProgress = (total, current) => setProgress(current / total * 100.0);
setProgress(0.0);
optionsLoad().then(options => {
- instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => {
+ return instDb().importDictionary(e.target.files[0], updateProgress).then(summary => {
options.dictionaries[summary.title] = {enabled: true, priority: 0};
return optionsSave(options);
- }).then(() => dictionaryGroupsPopulate(options)).catch(dictionaryErrorShow).then(() => {
- dictionarySpinnerShow(false);
- dictProgress.hide();
- dictImporter.show();
- dictUrl.val('');
- dictUrl.trigger('input');
- });
+ }).then(() => dictionaryGroupsPopulate(options));
+ }).catch(dictionaryErrorShow).then(() => {
+ dictFile.val('');
+ dictionarySpinnerShow(false);
+ dictProgress.hide();
+ dictImporter.show();
});
}
-function onDictionarySetUrl(e) {
- e.preventDefault();
-
- const dictUrl = $('#dict-url');
- const url = $(this).data('url');
- if (url.includes('/')) {
- dictUrl.val(url);
- } else {
- dictUrl.val(chrome.extension.getURL(`bg/lang/dict/${url}/index.json`));
- }
-
- dictUrl.trigger('input');
-}
-
-function onDictionaryUpdateUrl() {
- $('#dict-import').prop('disabled', $(this).val().length === 0);
-}
-
-
/*
* Anki
*/