summaryrefslogtreecommitdiff
path: root/ext/js/media/audio-downloader.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-06 18:26:16 -0500
committerGitHub <noreply@github.com>2021-03-06 18:26:16 -0500
commit49bf56269032b568772d8446b039d85309de98f5 (patch)
tree5578269f3fbd64be1a8f1c400fb5a8aa8f6621d0 /ext/js/media/audio-downloader.js
parent16217728afe0f9ff7dcbb7c7b7ead454ccc8705f (diff)
Update audio downloader (#1499)
* Update _getInfoJpod101's empty reading check * Use URLSearchParams instead of a string
Diffstat (limited to 'ext/js/media/audio-downloader.js')
-rw-r--r--ext/js/media/audio-downloader.js28
1 files changed, 15 insertions, 13 deletions
diff --git a/ext/js/media/audio-downloader.js b/ext/js/media/audio-downloader.js
index 68e03d39..8fd6d3f5 100644
--- a/ext/js/media/audio-downloader.js
+++ b/ext/js/media/audio-downloader.js
@@ -78,29 +78,31 @@ class AudioDownloader {
}
async _getInfoJpod101(expression, reading) {
- let kana = reading;
- let kanji = expression;
-
- if (!kana && this._japaneseUtil.isStringEntirelyKana(kanji)) {
- kana = kanji;
- kanji = null;
+ if (reading === expression && this._japaneseUtil.isStringEntirelyKana(expression)) {
+ reading = expression;
+ expression = null;
}
- const params = [];
- if (kanji) {
- params.push(`kanji=${encodeURIComponent(kanji)}`);
+ const params = new URLSearchParams();
+ if (expression) {
+ params.set('kanji', expression);
}
- if (kana) {
- params.push(`kana=${encodeURIComponent(kana)}`);
+ if (reading) {
+ params.set('kana', reading);
}
- const url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.join('&')}`;
+ const url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.toString()}`;
return [{type: 'url', url}];
}
async _getInfoJpod101Alternate(expression, reading) {
const fetchUrl = 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post';
- const data = `post=dictionary_reference&match_type=exact&search_query=${encodeURIComponent(expression)}&vulgar=true`;
+ const data = new URLSearchParams({
+ post: 'dictionary_reference',
+ match_type: 'exact',
+ search_query: expression,
+ vulgar: 'true'
+ });
const response = await this._requestBuilder.fetchAnonymous(fetchUrl, {
method: 'POST',
mode: 'cors',