diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-08-08 20:02:58 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-08-08 20:02:58 -0700 |
commit | dcce58fc2eab1f3b23abb90f5ce30536d7dbf1c1 (patch) | |
tree | 0a72a840c357e5cab3f16b1427dd627258c63fbd | |
parent | b080e30b14c70ab450ea77e93bce45f93662b7ed (diff) |
Cleanup
-rw-r--r-- | ext/bg/js/options-form.js | 23 | ||||
-rw-r--r-- | ext/bg/js/options.js | 32 |
2 files changed, 27 insertions, 28 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index c72508c6..a3250ab3 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -40,21 +40,21 @@ function formToOptions(section, callback) { switch (section) { case 'general': - optsNew.scanLength = parseInt($('#scan-length').val()); - optsNew.activateOnStartup = $('#activate-on-startup').prop('checked'); - optsNew.loadEnamDict = $('#load-enamdict').prop('checked'); - optsNew.selectMatchedText = $('#select-matched-text').prop('checked'); + optsNew.scanLength = parseInt($('#scan-length').val(), 10); + optsNew.activateOnStartup = $('#activate-on-startup').prop('checked'); + optsNew.loadEnamDict = $('#load-enamdict').prop('checked'); + optsNew.selectMatchedText = $('#select-matched-text').prop('checked'); optsNew.enableAudioPlayback = $('#enable-audio-playback').prop('checked'); - optsNew.enableAnkiConnect = $('#enable-anki-connect').prop('checked'); + optsNew.enableAnkiConnect = $('#enable-anki-connect').prop('checked'); break; case 'anki': - optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/); - optsNew.sentenceExtent = parseInt($('#sentence-extent').val()); - optsNew.ankiVocabDeck = $('#anki-vocab-deck').val(); - optsNew.ankiVocabModel = $('#anki-vocab-model').val(); + optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/); + optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10); + optsNew.ankiVocabDeck = $('#anki-vocab-deck').val(); + optsNew.ankiVocabModel = $('#anki-vocab-model').val(); optsNew.ankiVocabFields = fieldsToDict($('#vocab .anki-field-value')); - optsNew.ankiKanjiDeck = $('#anki-kanji-deck').val(); - optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); + optsNew.ankiKanjiDeck = $('#anki-kanji-deck').val(); + optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value')); break; } @@ -91,6 +91,7 @@ function populateAnkiDeckAndModel(opts) { function updateAnkiStatus() { $('.error-dlg').hide(); + yomichan().api_getVersion({callback: (version) => { if (version === null) { $('.error-dlg-connection').show(); diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 44236e68..3f31aff8 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -19,30 +19,28 @@ function sanitizeOptions(options) { const defaults = { - scanLength: 20, - activateOnStartup: false, - selectMatchedText: true, - loadEnamDict: false, + scanLength: 20, + activateOnStartup: false, + selectMatchedText: true, + loadEnamDict: false, enableAudioPlayback: true, - enableAnkiConnect: false, - ankiCardTags: ['yomichan'], - sentenceExtent: 200, - ankiVocabDeck: '', - ankiVocabModel: '', - ankiVocabFields: {}, - ankiKanjiDeck: '', - ankiKanjiModel: '', - ankiKanjiFields: {} + enableAnkiConnect: false, + ankiCardTags: ['yomichan'], + sentenceExtent: 200, + ankiVocabDeck: '', + ankiVocabModel: '', + ankiVocabFields: {}, + ankiKanjiDeck: '', + ankiKanjiModel: '', + ankiKanjiFields: {} }; - for (let key in defaults) { - if (!options.hasOwnProperty(key)) { + for (const key in defaults) { + if (!(key in options)) { options[key] = defaults[key]; } } - options.scanLength = parseInt(options.scanLength); - return options; } |