/* * 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) { $('#activate-on-startup').prop('checked', opts.activateOnStartup); $('#enable-anki-connect').prop('checked', opts.enableAnkiConnect); $('#load-enamdict').prop('checked', opts.loadEnamDict); $('#scan-length').val(opts.scanLength); $('#select-matched-text').prop('checked', opts.selectMatchedText); } function formToOptions() { return sanitizeOptions({ activateOnStartup: $('#activate-on-startup').prop('checked'), enableAnkiConnect: $('#enable-anki-connect').prop('checked'), loadEnamDict: $('#load-enamdict').prop('checked'), scanLength: $('#scan-length').val(), selectMatchedText: $('#select-matched-text').prop('checked') }); } 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($('