diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-03-25 12:01:20 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-03-25 12:01:20 -0700 |
commit | 83a6c30d0e68496bc7592b3adfa91ae536a487e1 (patch) | |
tree | ee0104442db7467767d072b02383f84a2f262e3e /ext | |
parent | 20d062329bfcdc0d7c5fd07f48071ae6524f9566 (diff) |
audio improvements
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/yomichan.js | 21 | ||||
-rw-r--r-- | ext/mixed/js/util.js | 15 |
2 files changed, 25 insertions, 11 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 50a8a636..e2deb2cd 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -70,6 +70,25 @@ window.yomichan = new class { fields = this.options.anki.terms.fields; note.deckName = this.options.anki.terms.deck; note.modelName = this.options.anki.terms.model; + + if (definition.audio) { + const audio = { + url: definition.audio.url, + filename: definition.audio.filename, + skipHash: '7e2c2f954ef6051373ba916f000168dc', + fields: [] + }; + + for (const name in fields) { + if (fields[name].includes('{audio}')) { + audio.fields.push(name); + } + } + + if (audio.fields.length > 0) { + note.audio = audio; + } + } } for (const name in fields) { @@ -102,7 +121,7 @@ window.yomichan = new class { definitionAdd(definition, mode) { let promise = Promise.resolve(); - if (this.options.general.audioPlayback && mode !== 'kanji') { + if (mode !== 'kanji') { promise = audioInject(definition, this.options.anki.terms.fields); } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index 1289455c..4ce60e4f 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -85,25 +85,20 @@ function audioInject(definition, fields) { return Promise.resolve(true); } - const audio = { - filename, - skipHash: '7e2c2f954ef6051373ba916f000168dc', - fields: [] - }; - + let usesAudio = false; for (const name in fields) { if (fields[name].includes('{audio}')) { - audio.fields.push(name); + usesAudio = true; + break; } } - if (audio.fields.length === 0) { + if (!usesAudio) { return Promise.resolve(true); } return audioBuildUrl(definition).then(url => { - audio.url = url; - note.audio = audio; + definition.audio = {url, filename}; return true; }).catch(() => false); } |