WIP
This commit is contained in:
parent
eae885b9aa
commit
e8840465f0
@ -65,7 +65,7 @@ class Database {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTerm(term, dictionaries) {
|
findTerms(term, dictionaries) {
|
||||||
if (this.db === null) {
|
if (this.db === null) {
|
||||||
return Promise.reject('database not initialized');
|
return Promise.reject('database not initialized');
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ class Translator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTerm(text, dictionaries, softKatakana) {
|
findTerms(text, dictionaries, softKatakana) {
|
||||||
const cache = {};
|
const cache = {};
|
||||||
return this.findTermDeinflections(text, dictionaries, cache).then(deinfLiteral => {
|
return this.findTermsDeinflected(text, dictionaries, cache).then(deinfLiteral => {
|
||||||
const textHiragana = wanakana._katakanaToHiragana(text);
|
const textHiragana = wanakana._katakanaToHiragana(text);
|
||||||
if (text !== textHiragana && softKatakana) {
|
if (text !== textHiragana && softKatakana) {
|
||||||
return this.findTermDeinflections(textHiragana, dictionaries, cache).then(deinfHiragana => deinfLiteral.concat(deinfHiragana));
|
return this.findTermsDeinflected(textHiragana, dictionaries, cache).then(deinfHiragana => deinfLiteral.concat(deinfHiragana));
|
||||||
} else {
|
} else {
|
||||||
return deinfLiteral;
|
return deinfLiteral;
|
||||||
}
|
}
|
||||||
@ -82,8 +82,8 @@ class Translator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTermGrouped(text, dictionaries, softKatakana) {
|
findTermsGrouped(text, dictionaries, softKatakana) {
|
||||||
return this.findTerm(text, dictionaries, softKatakana).then(({length, definitions}) => {
|
return this.findTerms(text, dictionaries, softKatakana).then(({length, definitions}) => {
|
||||||
return {length, definitions: groupTermDefs(definitions)};
|
return {length, definitions: groupTermDefs(definitions)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -109,13 +109,13 @@ class Translator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTermDeinflections(text, dictionaries, cache) {
|
findTermsDeinflected(text, dictionaries, cache) {
|
||||||
const definer = term => {
|
const definer = term => {
|
||||||
if (cache.hasOwnProperty(term)) {
|
if (cache.hasOwnProperty(term)) {
|
||||||
return Promise.resolve(cache[term]);
|
return Promise.resolve(cache[term]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.database.findTerm(term, dictionaries).then(definitions => cache[term] = definitions);
|
return this.database.findTerms(term, dictionaries).then(definitions => cache[term] = definitions);
|
||||||
};
|
};
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
@ -106,15 +106,11 @@ class Yomichan {
|
|||||||
tabInvokeAll(action, params) {
|
tabInvokeAll(action, params) {
|
||||||
chrome.tabs.query({}, tabs => {
|
chrome.tabs.query({}, tabs => {
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
this.tabInvoke(tab.id, action, params);
|
chrome.tabs.sendMessage(tab.id, {action, params}, () => null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
tabInvoke(tabId, action, params) {
|
|
||||||
chrome.tabs.sendMessage(tabId, {action, params}, () => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
formatNote(definition, mode) {
|
formatNote(definition, mode) {
|
||||||
const note = {fields: {}, tags: this.options.anki.tags};
|
const note = {fields: {}, tags: this.options.anki.tags};
|
||||||
|
|
||||||
@ -174,7 +170,7 @@ class Yomichan {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_findTerm({text, callback}) {
|
api_findTerms({text, callback}) {
|
||||||
const dictionaries = [];
|
const dictionaries = [];
|
||||||
for (const title in this.options.dictionaries) {
|
for (const title in this.options.dictionaries) {
|
||||||
if (this.options.dictionaries[title].enableTerms) {
|
if (this.options.dictionaries[title].enableTerms) {
|
||||||
@ -183,7 +179,7 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
promiseCallback(
|
promiseCallback(
|
||||||
this.translator.findTerm(
|
this.translator.findTerms(
|
||||||
text,
|
text,
|
||||||
dictionaries,
|
dictionaries,
|
||||||
this.options.general.softKatakana
|
this.options.general.softKatakana
|
||||||
@ -192,7 +188,7 @@ class Yomichan {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
api_findTermGrouped({text, callback}) {
|
api_findTermsGrouped({text, callback}) {
|
||||||
const dictionaries = [];
|
const dictionaries = [];
|
||||||
for (const title in this.options.dictionaries) {
|
for (const title in this.options.dictionaries) {
|
||||||
if (this.options.dictionaries[title].enableTerms) {
|
if (this.options.dictionaries[title].enableTerms) {
|
||||||
@ -201,7 +197,7 @@ class Yomichan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
promiseCallback(
|
promiseCallback(
|
||||||
this.translator.findTermGrouped(
|
this.translator.findTermsGrouped(
|
||||||
text,
|
text,
|
||||||
dictionaries,
|
dictionaries,
|
||||||
this.options.general.softKatakana
|
this.options.general.softKatakana
|
||||||
|
@ -146,7 +146,7 @@ class Driver {
|
|||||||
searchTerms(textSource) {
|
searchTerms(textSource) {
|
||||||
textSource.setEndOffset(this.options.scanning.length);
|
textSource.setEndOffset(this.options.scanning.length);
|
||||||
|
|
||||||
const findFunc = this.options.general.groupResults ? findTermGrouped : findTerm;
|
const findFunc = this.options.general.groupResults ? findTermsGrouped : findTerms;
|
||||||
return findFunc(textSource.text()).then(({definitions, length}) => {
|
return findFunc(textSource.text()).then(({definitions, length}) => {
|
||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -37,12 +37,12 @@ function getOptions() {
|
|||||||
return invokeBgApi('getOptions', {});
|
return invokeBgApi('getOptions', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTerm(text) {
|
function findTerms(text) {
|
||||||
return invokeBgApi('findTerm', {text});
|
return invokeBgApi('findTerms', {text});
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTermGrouped(text) {
|
function findTermsGrouped(text) {
|
||||||
return invokeBgApi('findTermGrouped', {text});
|
return invokeBgApi('findTermsGrouped', {text});
|
||||||
}
|
}
|
||||||
|
|
||||||
function findKanji(text) {
|
function findKanji(text) {
|
||||||
|
Loading…
Reference in New Issue
Block a user