diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-04-02 12:56:47 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-04-02 12:56:47 -0700 |
commit | a6fda6c94340c570442fbd20db2ab99a8bbcf289 (patch) | |
tree | b02cda4bd584ae1a70130f9c16ba9848f6dbe0a2 | |
parent | 036639aeafccfa20db0edd4780abbd391da74922 (diff) |
Work with new dictionary format
-rw-r--r-- | ext/bg/dictionary.js | 2 | ||||
-rw-r--r-- | ext/bg/translator.js | 19 | ||||
-rw-r--r-- | ext/client.js | 4 |
3 files changed, 13 insertions, 12 deletions
diff --git a/ext/bg/dictionary.js b/ext/bg/dictionary.js index 1264263a..a68c2daf 100644 --- a/ext/bg/dictionary.js +++ b/ext/bg/dictionary.js @@ -60,7 +60,7 @@ class Dictionary { storeIndex(indices, term, index) { if (term.length > 0) { const indices = this.termIndices[term] || []; - indices.push(term); + indices.push(index); this.termIndices[term] = indices; } } diff --git a/ext/bg/translator.js b/ext/bg/translator.js index e76a1b07..23d5d964 100644 --- a/ext/bg/translator.js +++ b/ext/bg/translator.js @@ -19,9 +19,9 @@ class Translator { constructor() { - this.dictionary = new Dictionary(); - this.deinflector = new Deinflector(); - this.pendingLoads = []; + this.dictionary = new Dictionary(); + this.deinflector = new Deinflector(); + this.initialized = false; } loadData(paths, callback) { @@ -30,8 +30,9 @@ class Translator { return; } + const pendingLoads = []; for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) { - this.pendingLoads.push(key); + pendingLoads.push(key); Translator.loadData(paths[key], (response) => { switch (key) { case 'rules': @@ -46,9 +47,9 @@ class Translator { break; } - const index = this.pendingLoads.indexOf(key); - this.pendingLoads = this.pendingLoads.splice(index, 1); - if (this.pendingLoads.length === 0) { + pendingLoads.splice(pendingLoads.indexOf(key), 1); + if (pendingLoads.length === 0) { + this.initialized = true; callback(); } }); @@ -160,7 +161,9 @@ class Translator { static parseCsv(data) { const result = []; for (const row of data.split('\n')) { - result.push(row.split('\t')); + if (row.length > 0) { + result.push(row.split('\t')); + } } return result; diff --git a/ext/client.js b/ext/client.js index 1c8c0a9f..2d9a470f 100644 --- a/ext/client.js +++ b/ext/client.js @@ -27,9 +27,7 @@ class Client { this.popup.classList.add('yomichan-popup'); this.popup.addEventListener('mousedown', (e) => e.stopPropagation()); this.popup.addEventListener('scroll', (e) => e.stopPropagation()); - - const base = document.body.appendChild('div'); - base.createShadowRoot().appendChild(this.popup); + document.body.appendChild(this.popup); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); window.addEventListener('mousedown', this.onMouseDown.bind(this)); |