summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-12-14 22:39:03 -0500
committerGitHub <noreply@github.com>2020-12-14 22:39:03 -0500
commite29c7527938ab37fa90668d5ad9537e4f4a31e67 (patch)
treeca036c14d40cd826022cedca46478a6cf397ddb3 /ext
parentcd82fe8aac88c03e85e01a267de976337412d338 (diff)
Simplify URL normalization (#1112)
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/audio-downloader.js22
1 files changed, 4 insertions, 18 deletions
diff --git a/ext/bg/js/audio-downloader.js b/ext/bg/js/audio-downloader.js
index 1a3428e1..77cd7294 100644
--- a/ext/bg/js/audio-downloader.js
+++ b/ext/bg/js/audio-downloader.js
@@ -67,22 +67,8 @@ class AudioDownloader {
// Private
- _normalizeUrl(url, baseUrl, basePath) {
- if (url) {
- if (url[0] === '/') {
- if (url.length >= 2 && url[1] === '/') {
- // Begins with "//"
- url = baseUrl.substring(0, baseUrl.indexOf(':') + 1) + url;
- } else {
- // Begins with "/"
- url = baseUrl + url;
- }
- } else if (!/^[a-z][a-z0-9\-+.]*:/i.test(url)) {
- // No URI scheme => relative path
- url = baseUrl + basePath + url;
- }
- }
- return url;
+ _normalizeUrl(url, base) {
+ return new URL(url, base).href;
}
async _getInfoJpod101(expression, reading) {
@@ -140,7 +126,7 @@ class AudioDownloader {
const htmlReading = dom.getTextContent(htmlReadings[0]);
if (htmlReading && (!reading || reading === htmlReading)) {
- url = this._normalizeUrl(url, 'https://www.japanesepod101.com', '/learningcenter/reference/');
+ url = this._normalizeUrl(url, response.url);
return {type: 'url', details: {url}};
}
} catch (e) {
@@ -171,7 +157,7 @@ class AudioDownloader {
if (source !== null) {
let url = dom.getAttribute(source, 'src');
if (url !== null) {
- url = this._normalizeUrl(url, 'https://jisho.org', '/search/');
+ url = this._normalizeUrl(url, response.url);
return {type: 'url', details: {url}};
}
}