summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-04-02 12:08:15 -0700
committerAlex Yatskov <alex@foosoft.net>2017-04-02 12:08:15 -0700
commit9ac55fb5d11e5037e808939598591d55d1368b43 (patch)
tree8cd4d6452f83c279f1ecb23a1fce9039f40a09ef /ext/bg/js
parent4eb3e2f06cd83ef0721557f8559fc0a6d70ad4f5 (diff)
support for multiple audio sources, version bump1.1.11
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/options.js4
-rw-r--r--ext/bg/js/util.js90
-rw-r--r--ext/bg/js/yomichan.js2
3 files changed, 12 insertions, 84 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 75f39d24..ad8d83d8 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -25,7 +25,7 @@ function formRead() {
return optionsLoad().then(optionsOld => {
const optionsNew = $.extend(true, {}, optionsOld);
- optionsNew.general.audioPlayback = $('#audio-playback-buttons').prop('checked');
+ optionsNew.general.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = $('#audio-playback-volume').val();
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.softKatakana = $('#soft-katakana-search').prop('checked');
@@ -111,7 +111,7 @@ $(document).ready(() => {
handlebarsRegister();
optionsLoad().then(options => {
- $('#audio-playback-buttons').prop('checked', options.general.audioPlayback);
+ $('#audio-playback-source').val(options.general.audioSource);
$('#audio-playback-volume').val(options.general.audioVolume);
$('#group-terms-results').prop('checked', options.general.groupResults);
$('#soft-katakana-search').prop('checked', options.general.softKatakana);
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 78258c97..05c7ff27 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -25,9 +25,6 @@ function promiseCallback(promise, callback) {
return promise.then(result => {
callback({result});
}).catch(error => {
- /* eslint-disable */
- console.log(error);
- /* eslint-enable */
callback({error});
});
}
@@ -84,7 +81,7 @@ function optionsSetDefaults(options) {
const defaults = {
general: {
enable: true,
- audioPlayback: true,
+ audioSource: 'jpod101',
audioVolume: 100,
groupResults: true,
softKatakana: true,
@@ -137,84 +134,15 @@ function optionsSetDefaults(options) {
function optionsVersion(options) {
const fixups = [
+ () => { },
+ () => { },
+ () => { },
+ () => { },
() => {
- const copy = (targetDict, targetKey, sourceDict, sourceKey) => {
- targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey];
- };
-
- copy(options.general, 'autoStart', options, 'activateOnStartup');
- copy(options.general, 'audioPlayback', options, 'enableAudioPlayback');
- copy(options.general, 'softKatakana', options, 'enableSoftKatakanaSearch');
- copy(options.general, 'groupResults', options, 'groupTermResults');
- copy(options.general, 'showAdvanced', options, 'showAdvancedOptions');
-
- copy(options.scanning, 'requireShift', options, 'holdShiftToScan');
- copy(options.scanning, 'selectText', options, 'selectMatchedText');
- copy(options.scanning, 'delay', options, 'scanDelay');
- copy(options.scanning, 'length', options, 'scanLength');
-
- options.anki.enable = options.ankiMethod === 'ankiconnect';
-
- copy(options.anki, 'tags', options, 'ankiCardTags');
- copy(options.anki, 'sentenceExt', options, 'sentenceExtent');
- copy(options.anki.terms, 'deck', options, 'ankiTermDeck');
- copy(options.anki.terms, 'model', options, 'ankiTermModel');
- copy(options.anki.terms, 'fields', options, 'ankiTermFields');
- copy(options.anki.kanji, 'deck', options, 'ankiKanjiDeck');
- copy(options.anki.kanji, 'model', options, 'ankiKanjiModel');
- copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
-
- for (const title in options.dictionaries) {
- const dictionary = options.dictionaries[title];
- dictionary.enabled = dictionary.enableTerms || dictionary.enableKanji;
- dictionary.priority = 0;
- }
- },
- () => {
- const fixupFields = fields => {
- const fixups = {
- '{expression-furigana}': '{furigana}',
- '{glossary-list}': '{glossary}'
- };
-
- for (const name in fields) {
- for (const fixup in fixups) {
- fields[name] = fields[name].replace(fixup, fixups[fixup]);
- }
- }
- };
-
- fixupFields(options.anki.terms.fields);
- fixupFields(options.anki.kanji.fields);
- },
- () => {
- let hasEnabledDict = false;
- for (const title in options.dictionaries) {
- if (options.dictionaries[title].enabled) {
- hasEnabledDict = true;
- break;
- }
- }
-
- if (!hasEnabledDict) {
- for (const title in options.dictionaries) {
- options.dictionaries[title].enabled = true;
- }
- }
- },
- () => {
- let hasEnabledDict = false;
- for (const title in options.dictionaries) {
- if (options.dictionaries[title].enabled) {
- hasEnabledDict = true;
- break;
- }
- }
-
- if (!hasEnabledDict) {
- for (const title in options.dictionaries) {
- options.dictionaries[title].enabled = true;
- }
+ if (options.general.audioPlayback) {
+ options.general.audioSource = 'jpod101';
+ } else {
+ options.general.audioSource = 'disabled';
}
}
];
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 7a26d6c7..feb74b6e 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -121,7 +121,7 @@ window.yomichan = new class {
definitionAdd(definition, mode) {
let promise = Promise.resolve();
if (mode !== 'kanji') {
- promise = audioInject(definition, this.options.anki.terms.fields);
+ promise = audioInject(definition, this.options.anki.terms.fields, this.options.general.audioSource);
}
return promise.then(() => {