From 5ecca4627e4edd54b8af606c69aa51e4b659deef Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 2 Mar 2017 20:23:56 -0800 Subject: [PATCH] enable and disable via toggle switch --- ext/bg/js/options-form.js | 32 +++++++++----------------------- ext/bg/js/options.js | 12 ++++++++++++ ext/bg/js/popup.js | 11 ++++++++++- ext/bg/js/util.js | 38 +++++++++++++++++++------------------- ext/bg/js/yomichan.js | 10 +++++----- ext/bg/options.html | 5 +---- ext/bg/popup.html | 10 ++++++---- 7 files changed, 62 insertions(+), 56 deletions(-) diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index ae0491a2..c53c0c5e 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -20,15 +20,10 @@ // General // -function yomichan() { - return chrome.extension.getBackgroundPage().yomichan; -} - function getFormData() { return optionsLoad().then(optionsOld => { const optionsNew = $.extend(true, {}, optionsOld); - optionsNew.general.enable = $('#enable-search').prop('checked'); optionsNew.general.audioPlayback = $('#audio-playback-buttons').prop('checked'); optionsNew.general.groupResults = $('#group-terms-results').prop('checked'); optionsNew.general.softKatakana = $('#soft-katakana-search').prop('checked'); @@ -87,7 +82,6 @@ $(document).ready(() => { Handlebars.partials = Handlebars.templates; optionsLoad().then(options => { - $('#enable-search').prop('checked', options.general.enable); $('#audio-playback-buttons').prop('checked', options.general.audioPlayback); $('#group-terms-results').prop('checked', options.general.groupResults); $('#soft-katakana-search').prop('checked', options.general.softKatakana); @@ -123,10 +117,6 @@ $(document).ready(() => { // Dictionary // -function database() { - return yomichan().translator.database; -} - function showDictionaryError(error) { const dialog = $('#dict-error'); if (error) { @@ -153,7 +143,7 @@ function populateDictionaries(options) { const dictWarning = $('#dict-warning').hide(); let dictCount = 0; - return database().getDictionaries().then(rows => { + return getDatabase().getDictionaries().then(rows => { rows.forEach(row => { const dictOptions = options.dictionaries[row.title] || {enableTerms: false, enableKanji: false, priority: 0}; const html = Handlebars.templates['dictionary.html']({ @@ -188,7 +178,7 @@ function onDictionaryPurge(e) { const dictControls = $('#dict-importer, #dict-groups').hide(); const dictProgress = $('#dict-purge-progress').show(); - return database().purge().catch(showDictionaryError).then(() => { + return getDatabase().purge().catch(showDictionaryError).then(() => { showDictionarySpinner(false); dictControls.show(); dictProgress.hide(); @@ -197,7 +187,7 @@ function onDictionaryPurge(e) { options.dictionaries = {}; return optionsSave(options).then(() => { populateDictionaries(options); - yomichan().setOptions(options); + getYomichan().setOptions(options); }); }); } @@ -214,9 +204,9 @@ function onDictionaryImport() { setProgress(0.0); optionsLoad().then(options => { - database().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { + getDatabase().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { options.dictionaries[summary.title] = {enabled: true, priority: 0}; - return optionsSave(options).then(() => yomichan().setOptions(options)); + return optionsSave(options).then(() => getYomichan().setOptions(options)); }).then(() => populateDictionaries(options)).catch(showDictionaryError).then(() => { showDictionarySpinner(false); dictProgress.hide(); @@ -249,10 +239,6 @@ function onDictionaryUpdateUrl() { // Anki // -function anki() { - return yomichan().anki; -} - function showAnkiSpinner(show) { const spinner = $('#anki-spinner'); if (show) { @@ -286,7 +272,7 @@ function populateAnkiDeckAndModel(options) { showAnkiSpinner(true); const ankiFormat = $('#anki-format').hide(); - return Promise.all([anki().getDeckNames(), anki().getModelNames()]).then(([deckNames, modelNames]) => { + return Promise.all([getAnki().getDeckNames(), getAnki().getModelNames()]).then(([deckNames, modelNames]) => { const ankiDeck = $('.anki-deck'); ankiDeck.find('option').remove(); deckNames.sort().forEach(name => ankiDeck.append($('