aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-08-23 20:53:11 -0700
committerAlex Yatskov <alex@foosoft.net>2016-08-23 20:53:11 -0700
commit6366d9bd8e5758d631e5bba14b2c892e0b27c474 (patch)
tree33d09a8912011ee3c23820302be4bc8ee9a6cf30 /ext/bg/js/translator.js
parentf106b64876c975237e8c8bb51518ab53d2a9d2fc (diff)
WIP
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index f9ac1d56..8af0e31b 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -31,11 +31,11 @@ class Translator {
return;
}
- Translator.loadData('bg/data/rules.json').then((response) => {
- this.deinflector.setRules(JSON.parse(response));
- return Translator.loadData('bg/data/tags.json');
- }).then((response) => {
- this.tagMeta = JSON.parse(response);
+ Translator.loadJson('bg/data/rules.json').then((rules) => {
+ this.deinflector.setRules(rules);
+ return Translator.loadJson('bg/data/tags.json');
+ }).then((tagMeta) => {
+ this.tagMeta = tagMeta;
return this.dictionary.existsDb();
}).then((exists) => {
if (exists) {
@@ -48,12 +48,12 @@ class Translator {
]);
}
}).then(() => {
- this.loaded = true;
- callback();
-
this.dictionary.findTerm('猫').then((result) => {
console.log(result);
});
+
+ this.loaded = true;
+ callback();
});
}
@@ -246,10 +246,10 @@ class Translator {
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
}
- static loadData(url) {
+ static loadJson(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
- xhr.addEventListener('load', () => resolve(xhr.responseText));
+ xhr.addEventListener('load', () => resolve(JSON.parse(xhr.responseText)));
xhr.open('GET', chrome.extension.getURL(url), true);
xhr.send();
});