/* * Copyright (C) 2016 Alex Yatskov * Author: Alex Yatskov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ function yomichan() { return chrome.extension.getBackgroundPage().yomichan; } function optionsToForm(opts) { $('#scan-length').val(opts.scanLength); $('#activate-on-startup').prop('checked', opts.activateOnStartup); $('#load-enamdict').prop('checked', opts.loadEnamDict); $('#select-matched-text').prop('checked', opts.selectMatchedText); $('#enable-anki-connect').prop('checked', opts.enableAnkiConnect); $('#anki-vocab-deck').val(opts.ankiVocabDeck); $('#anki-vocab-model').val(opts.ankiVocabModel); $('#anki-kanji-deck').val(opts.ankiKanjiDeck); $('#anki-kanji-model').val(opts.ankiKanjiModel); } function formToOptions() { return sanitizeOptions({ scanLength: $('#scan-length').val(), activateOnStartup: $('#activate-on-startup').prop('checked'), loadEnamDict: $('#load-enamdict').prop('checked'), selectMatchedText: $('#select-matched-text').prop('checked'), enableAnkiConnect: $('#enable-anki-connect').prop('checked'), ankiVocabDeck: $('#anki-vocab-deck').val(), ankiVocabModel: $('#anki-vocab-model').val(), ankiKanjiDeck: $('#anki-kanji-deck').val(), ankiKanjiModel: $('#anki-kanji-model').val() }); } function updateAnkiFormVis(opts) { if (opts.enableAnkiConnect) { populateAnkiDeckAndModel(); $('.options-anki').fadeIn(); } else { $('.options-anki').fadeOut(); } } function populateAnkiDeckAndModel() { const yomi = yomichan(); const ankiDeck = $('.anki-deck'); ankiDeck.find('option').remove(); yomi.api_getDeckNames({callback: (names) => { if (names !== null) { names.forEach((name) => ankiDeck.append($('