audio improvements
This commit is contained in:
parent
20d062329b
commit
83a6c30d0e
@ -70,6 +70,25 @@ window.yomichan = new class {
|
|||||||
fields = this.options.anki.terms.fields;
|
fields = this.options.anki.terms.fields;
|
||||||
note.deckName = this.options.anki.terms.deck;
|
note.deckName = this.options.anki.terms.deck;
|
||||||
note.modelName = this.options.anki.terms.model;
|
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) {
|
for (const name in fields) {
|
||||||
@ -102,7 +121,7 @@ window.yomichan = new class {
|
|||||||
|
|
||||||
definitionAdd(definition, mode) {
|
definitionAdd(definition, mode) {
|
||||||
let promise = Promise.resolve();
|
let promise = Promise.resolve();
|
||||||
if (this.options.general.audioPlayback && mode !== 'kanji') {
|
if (mode !== 'kanji') {
|
||||||
promise = audioInject(definition, this.options.anki.terms.fields);
|
promise = audioInject(definition, this.options.anki.terms.fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,25 +85,20 @@ function audioInject(definition, fields) {
|
|||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const audio = {
|
let usesAudio = false;
|
||||||
filename,
|
|
||||||
skipHash: '7e2c2f954ef6051373ba916f000168dc',
|
|
||||||
fields: []
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const name in fields) {
|
for (const name in fields) {
|
||||||
if (fields[name].includes('{audio}')) {
|
if (fields[name].includes('{audio}')) {
|
||||||
audio.fields.push(name);
|
usesAudio = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio.fields.length === 0) {
|
if (!usesAudio) {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioBuildUrl(definition).then(url => {
|
return audioBuildUrl(definition).then(url => {
|
||||||
audio.url = url;
|
definition.audio = {url, filename};
|
||||||
note.audio = audio;
|
|
||||||
return true;
|
return true;
|
||||||
}).catch(() => false);
|
}).catch(() => false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user