aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-07-10 15:00:38 -0700
committerAlex Yatskov <alex@foosoft.net>2017-07-10 15:00:38 -0700
commit28bc1449d1b2260df2970318982385b0d8456c54 (patch)
tree063156eb4b3191bdd0a0703e3302fa672f907a6f /ext/bg/js
parentf694026827ab2ce3a884206f7494b98335137709 (diff)
cleanup
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/translator.js22
-rw-r--r--ext/bg/js/util.js26
2 files changed, 21 insertions, 27 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 84a6e1d7..dfe54623 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -30,7 +30,8 @@ class Translator {
}
if (!this.deinflector) {
- const reasons = await jsonLoadInt('/bg/lang/deinflect.json');
+ const url = chrome.extension.getURL('/bg/lang/deinflect.json');
+ const reasons = await Translator.loadRules(url);
this.deinflector = new Deinflector(reasons);
}
}
@@ -127,4 +128,23 @@ 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');
+ }
+ });
+ }
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 1954e83b..b8a60217 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -430,32 +430,6 @@ function dictFieldFormat(field, definition, mode, options) {
/*
- * Json
- */
-
-function jsonLoad(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');
- }
- });
-}
-
-function jsonLoadInt(url) {
- return jsonLoad(chrome.extension.getURL(url));
-}
-
-/*
* Helpers
*/