Work with new dictionary format
This commit is contained in:
parent
036639aeaf
commit
a6fda6c943
@ -60,7 +60,7 @@ class Dictionary {
|
|||||||
storeIndex(indices, term, index) {
|
storeIndex(indices, term, index) {
|
||||||
if (term.length > 0) {
|
if (term.length > 0) {
|
||||||
const indices = this.termIndices[term] || [];
|
const indices = this.termIndices[term] || [];
|
||||||
indices.push(term);
|
indices.push(index);
|
||||||
this.termIndices[term] = indices;
|
this.termIndices[term] = indices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class Translator {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.dictionary = new Dictionary();
|
this.dictionary = new Dictionary();
|
||||||
this.deinflector = new Deinflector();
|
this.deinflector = new Deinflector();
|
||||||
this.pendingLoads = [];
|
this.initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData(paths, callback) {
|
loadData(paths, callback) {
|
||||||
@ -30,8 +30,9 @@ class Translator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pendingLoads = [];
|
||||||
for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
|
for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) {
|
||||||
this.pendingLoads.push(key);
|
pendingLoads.push(key);
|
||||||
Translator.loadData(paths[key], (response) => {
|
Translator.loadData(paths[key], (response) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'rules':
|
case 'rules':
|
||||||
@ -46,9 +47,9 @@ class Translator {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = this.pendingLoads.indexOf(key);
|
pendingLoads.splice(pendingLoads.indexOf(key), 1);
|
||||||
this.pendingLoads = this.pendingLoads.splice(index, 1);
|
if (pendingLoads.length === 0) {
|
||||||
if (this.pendingLoads.length === 0) {
|
this.initialized = true;
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -160,8 +161,10 @@ class Translator {
|
|||||||
static parseCsv(data) {
|
static parseCsv(data) {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (const row of data.split('\n')) {
|
for (const row of data.split('\n')) {
|
||||||
|
if (row.length > 0) {
|
||||||
result.push(row.split('\t'));
|
result.push(row.split('\t'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,7 @@ class Client {
|
|||||||
this.popup.classList.add('yomichan-popup');
|
this.popup.classList.add('yomichan-popup');
|
||||||
this.popup.addEventListener('mousedown', (e) => e.stopPropagation());
|
this.popup.addEventListener('mousedown', (e) => e.stopPropagation());
|
||||||
this.popup.addEventListener('scroll', (e) => e.stopPropagation());
|
this.popup.addEventListener('scroll', (e) => e.stopPropagation());
|
||||||
|
document.body.appendChild(this.popup);
|
||||||
const base = document.body.appendChild('div');
|
|
||||||
base.createShadowRoot().appendChild(this.popup);
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
||||||
window.addEventListener('mousedown', this.onMouseDown.bind(this));
|
window.addEventListener('mousedown', this.onMouseDown.bind(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user