From 9261a70a564034badf2c2b8c6859c46b295adb3d Mon Sep 17 00:00:00 2001 From: Stefan Vuković Date: Mon, 1 Jul 2024 11:51:10 +0200 Subject: make non-ja audio work without configuration (#1152) * add audio source for wiktionary format filenames on commons * allow region codes * fix files being saved in anki as mp3 * wip * refactor _getAvailableAudioSourceTypes * update docs * wording * single line list * fix no anki audio --- ext/js/display/display-audio.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'ext/js/display') diff --git a/ext/js/display/display-audio.js b/ext/js/display/display-audio.js index bb30c944..4fcabf06 100644 --- a/ext/js/display/display-audio.js +++ b/ext/js/display/display-audio.js @@ -166,16 +166,15 @@ export class DisplayAudio { * @param {import('display').EventArgument<'optionsUpdated'>} details */ _onOptionsUpdated({options}) { - const {enabled, autoPlay, volume, sources} = options.audio; + const { + general: {language}, + audio: {enabled, autoPlay, volume, sources}, + } = options; this._autoPlay = enabled && autoPlay; this._playbackVolume = Number.isFinite(volume) ? Math.max(0, Math.min(1, volume / 100)) : 1; /** @type {Set} */ - const requiredAudioSources = new Set([ - 'jpod101', - 'jpod101-alternate', - 'jisho', - ]); + const requiredAudioSources = this._getRequiredAudioSources(language); /** @type {Map} */ const nameMap = new Map(); this._audioSources.length = 0; @@ -188,11 +187,28 @@ export class DisplayAudio { } const data = document.documentElement.dataset; - data.audioEnabled = `${enabled && sources.length > 0}`; + data.audioEnabled = enabled.toString(); this._cache.clear(); } + /** + * @param {string} language + * @returns {Set} + */ + _getRequiredAudioSources(language) { + return language === 'ja' ? + new Set([ + 'jpod101', + 'jpod101-alternate', + 'jisho', + ]) : + new Set([ + 'lingua-libre', + 'wiktionary', + ]); + } + /** */ _onContentClear() { this._entriesToken = {}; -- cgit v1.2.3