summaryrefslogtreecommitdiff
path: root/ext/mixed/js/audio.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js/audio.js')
-rw-r--r--ext/mixed/js/audio.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js
index cf8b8d24..35f283a4 100644
--- a/ext/mixed/js/audio.js
+++ b/ext/mixed/js/audio.js
@@ -68,14 +68,14 @@ class TextToSpeechAudio {
}
static createFromUri(ttsUri) {
- const m = /^tts:[^#\?]*\?([^#]*)/.exec(ttsUri);
+ const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri);
if (m === null) { return null; }
const searchParameters = {};
for (const group of m[1].split('&')) {
const sep = group.indexOf('=');
if (sep < 0) { continue; }
- searchParameters[decodeURIComponent(group.substr(0, sep))] = decodeURIComponent(group.substr(sep + 1));
+ searchParameters[decodeURIComponent(group.substring(0, sep))] = decodeURIComponent(group.substring(sep + 1));
}
if (!searchParameters.text) { return null; }
@@ -88,19 +88,15 @@ class TextToSpeechAudio {
}
-function audioGetFromUrl(url, download) {
+function audioGetFromUrl(url, willDownload) {
const tts = TextToSpeechAudio.createFromUri(url);
if (tts !== null) {
- if (download) {
- throw new Error('Download not supported for text-to-speech');
+ if (willDownload) {
+ throw new Error('AnkiConnect does not support downloading text-to-speech audio.');
}
return Promise.resolve(tts);
}
- if (download) {
- return Promise.resolve(null);
- }
-
return new Promise((resolve, reject) => {
const audio = new Audio(url);
audio.addEventListener('loadeddata', () => {
@@ -115,9 +111,9 @@ function audioGetFromUrl(url, download) {
});
}
-async function audioGetFromSources(expression, sources, optionsContext, download, cache=null) {
+async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) {
const key = `${expression.expression}:${expression.reading}`;
- if (cache !== null && cache.hasOwnProperty(expression)) {
+ if (cache !== null && hasOwn(cache, expression)) {
return cache[key];
}
@@ -129,7 +125,11 @@ async function audioGetFromSources(expression, sources, optionsContext, download
}
try {
- const audio = await audioGetFromUrl(url, download);
+ let audio = await audioGetFromUrl(url, willDownload);
+ if (willDownload) {
+ // AnkiConnect handles downloading URLs into cards
+ audio = null;
+ }
const result = {audio, url, source};
if (cache !== null) {
cache[key] = result;