summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-02 13:30:55 -0400
committerGitHub <noreply@github.com>2020-08-02 13:30:55 -0400
commitb1b33f8beb26f97d91cb282682472c65f6eccae8 (patch)
tree1a7b5027a0f5208135f856759cb7935beac7911a /ext/bg/js/translator.js
parenta562a1149808b49f60346c82409f292290fbdd77 (diff)
Fix fetch requests (#708)
* Revert audio fetching functionality to use XMLHttpRequest * Replace requestJson * Replace requestJson * Replace requestJson * Replace requestJson and requestText * Fix tests * Include support for vulgar word searches * Remove request.js
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 3fd329d1..a1f30bd2 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -29,7 +29,6 @@
* dictTermsSort
* dictTermsUndupe
* jp
- * requestJson
*/
class Translator {
@@ -40,8 +39,7 @@ class Translator {
}
async prepare() {
- const url = chrome.runtime.getURL('/bg/lang/deinflect.json');
- const reasons = await requestJson(url, 'GET');
+ const reasons = await this._fetchJsonAsset('/bg/lang/deinflect.json');
this.deinflector = new Deinflector(reasons);
}
@@ -657,4 +655,19 @@ class Translator {
return text;
}
+
+ async _fetchJsonAsset(url) {
+ const response = await fetch(chrome.runtime.getURL(url), {
+ method: 'GET',
+ mode: 'no-cors',
+ cache: 'default',
+ credentials: 'omit',
+ redirect: 'follow',
+ referrerPolicy: 'no-referrer'
+ });
+ if (!response.ok) {
+ throw new Error(`Failed to fetch ${url}: ${response.status}`);
+ }
+ return await response.json();
+ }
}