summaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-07-10 16:24:31 -0700
committerAlex Yatskov <alex@foosoft.net>2017-07-10 16:24:31 -0700
commitb0cdf59bd8dae8f44362b14bdf19b243514e31d3 (patch)
treebaff7b58c86d207bddc707fbfc68f2f5b83aa000 /ext/bg/js/translator.js
parentefb5ed2af8c0bcf1c0dbfdbeef7c89dad2a106b9 (diff)
move anki to async
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js20
1 files changed, 1 insertions, 19 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index aa11ea63..9232e529 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -31,7 +31,7 @@ class Translator {
if (!this.deinflector) {
const url = chrome.extension.getURL('/bg/lang/deinflect.json');
- const reasons = await Translator.loadRules(url);
+ const reasons = await jsonRequest(url, 'GET');
this.deinflector = new Deinflector(reasons);
}
}
@@ -124,22 +124,4 @@ class Translator {
return definitions;
}
-
- static loadRules(url) {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.overrideMimeType('application/json');
- xhr.addEventListener('load', () => resolve(xhr.responseText));
- xhr.addEventListener('error', () => reject('failed to execute network request'));
- xhr.open('GET', url);
- xhr.send();
- }).then(responseText => {
- try {
- return JSON.parse(responseText);
- }
- catch (e) {
- return Promise.reject('invalid JSON response');
- }
- });
- }
}