This commit is contained in:
Alex Yatskov 2016-08-08 20:02:58 -07:00
parent b080e30b14
commit dcce58fc2e
2 changed files with 27 additions and 28 deletions

View File

@ -40,21 +40,21 @@ function formToOptions(section, callback) {
switch (section) { switch (section) {
case 'general': case 'general':
optsNew.scanLength = parseInt($('#scan-length').val()); optsNew.scanLength = parseInt($('#scan-length').val(), 10);
optsNew.activateOnStartup = $('#activate-on-startup').prop('checked'); optsNew.activateOnStartup = $('#activate-on-startup').prop('checked');
optsNew.loadEnamDict = $('#load-enamdict').prop('checked'); optsNew.loadEnamDict = $('#load-enamdict').prop('checked');
optsNew.selectMatchedText = $('#select-matched-text').prop('checked'); optsNew.selectMatchedText = $('#select-matched-text').prop('checked');
optsNew.enableAudioPlayback = $('#enable-audio-playback').prop('checked'); optsNew.enableAudioPlayback = $('#enable-audio-playback').prop('checked');
optsNew.enableAnkiConnect = $('#enable-anki-connect').prop('checked'); optsNew.enableAnkiConnect = $('#enable-anki-connect').prop('checked');
break; break;
case 'anki': case 'anki':
optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/); optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/);
optsNew.sentenceExtent = parseInt($('#sentence-extent').val()); optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10);
optsNew.ankiVocabDeck = $('#anki-vocab-deck').val(); optsNew.ankiVocabDeck = $('#anki-vocab-deck').val();
optsNew.ankiVocabModel = $('#anki-vocab-model').val(); optsNew.ankiVocabModel = $('#anki-vocab-model').val();
optsNew.ankiVocabFields = fieldsToDict($('#vocab .anki-field-value')); optsNew.ankiVocabFields = fieldsToDict($('#vocab .anki-field-value'));
optsNew.ankiKanjiDeck = $('#anki-kanji-deck').val(); optsNew.ankiKanjiDeck = $('#anki-kanji-deck').val();
optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); optsNew.ankiKanjiModel = $('#anki-kanji-model').val();
optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value')); optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value'));
break; break;
} }
@ -91,6 +91,7 @@ function populateAnkiDeckAndModel(opts) {
function updateAnkiStatus() { function updateAnkiStatus() {
$('.error-dlg').hide(); $('.error-dlg').hide();
yomichan().api_getVersion({callback: (version) => { yomichan().api_getVersion({callback: (version) => {
if (version === null) { if (version === null) {
$('.error-dlg-connection').show(); $('.error-dlg-connection').show();

View File

@ -19,30 +19,28 @@
function sanitizeOptions(options) { function sanitizeOptions(options) {
const defaults = { const defaults = {
scanLength: 20, scanLength: 20,
activateOnStartup: false, activateOnStartup: false,
selectMatchedText: true, selectMatchedText: true,
loadEnamDict: false, loadEnamDict: false,
enableAudioPlayback: true, enableAudioPlayback: true,
enableAnkiConnect: false, enableAnkiConnect: false,
ankiCardTags: ['yomichan'], ankiCardTags: ['yomichan'],
sentenceExtent: 200, sentenceExtent: 200,
ankiVocabDeck: '', ankiVocabDeck: '',
ankiVocabModel: '', ankiVocabModel: '',
ankiVocabFields: {}, ankiVocabFields: {},
ankiKanjiDeck: '', ankiKanjiDeck: '',
ankiKanjiModel: '', ankiKanjiModel: '',
ankiKanjiFields: {} ankiKanjiFields: {}
}; };
for (let key in defaults) { for (const key in defaults) {
if (!options.hasOwnProperty(key)) { if (!(key in options)) {
options[key] = defaults[key]; options[key] = defaults[key];
} }
} }
options.scanLength = parseInt(options.scanLength);
return options; return options;
} }