Work with new dictionary format

This commit is contained in:
Alex Yatskov 2016-04-02 12:56:47 -07:00
parent 036639aeaf
commit a6fda6c943
3 changed files with 13 additions and 12 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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));