Work with new dictionary format
This commit is contained in:
parent
036639aeaf
commit
a6fda6c943
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class Translator {
|
||||
constructor() {
|
||||
this.dictionary = new Dictionary();
|
||||
this.deinflector = new Deinflector();
|
||||
this.pendingLoads = [];
|
||||
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,8 +161,10 @@ class Translator {
|
||||
static parseCsv(data) {
|
||||
const result = [];
|
||||
for (const row of data.split('\n')) {
|
||||
if (row.length > 0) {
|
||||
result.push(row.split('\t'));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user