Use URLSearchParams

This commit is contained in:
toasted-nutbread 2020-02-15 13:36:32 -05:00
parent 163211ade3
commit 7afc23427e

View File

@ -72,19 +72,15 @@ class TextToSpeechAudio {
const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri); const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri);
if (m === null) { return null; } if (m === null) { return null; }
const searchParameters = {}; const searchParameters = new URLSearchParams(m[1]);
for (const group of m[1].split('&')) { const text = searchParameters.get('text');
const sep = group.indexOf('='); let voice = searchParameters.get('voice');
if (sep < 0) { continue; } if (text === null || voice === null) { return null; }
searchParameters[decodeURIComponent(group.substring(0, sep))] = decodeURIComponent(group.substring(sep + 1));
}
if (!searchParameters.text) { return null; } voice = audioGetTextToSpeechVoice(voice);
const voice = audioGetTextToSpeechVoice(searchParameters.voice);
if (voice === null) { return null; } if (voice === null) { return null; }
return new TextToSpeechAudio(searchParameters.text, voice); return new TextToSpeechAudio(text, voice);
} }
} }