Basic kanji output
This commit is contained in:
parent
a192a8d8b5
commit
cac6fc1427
@ -74,11 +74,16 @@ class Dictionary {
|
|||||||
findKanji(kanji) {
|
findKanji(kanji) {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (const name in this.termDicts) {
|
for (const name in this.kanjiDicts) {
|
||||||
const def = this.termDicts[name][kanji];
|
const def = this.kanjiDicts[name][kanji];
|
||||||
if (def) {
|
if (def) {
|
||||||
const [c, k, o, g] = def;
|
const [k, o, g] = def;
|
||||||
results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
|
results.push({
|
||||||
|
character: kanji,
|
||||||
|
kunyomi: k.split(' '),
|
||||||
|
onyomi: o.split(' '),
|
||||||
|
glossary: g
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,19 @@ templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":functi
|
|||||||
+ container.escapeExpression(((helper = (helper = helpers.kanji || (depth0 != null ? depth0.kanji : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"kanji","hash":{},"data":data}) : helper)))
|
+ container.escapeExpression(((helper = (helper = helpers.kanji || (depth0 != null ? depth0.kanji : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"kanji","hash":{},"data":data}) : helper)))
|
||||||
+ "</a>\n";
|
+ "</a>\n";
|
||||||
},"useData":true});
|
},"useData":true});
|
||||||
|
templates['kanji-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
|
||||||
|
var stack1;
|
||||||
|
|
||||||
|
return "<div class=\"definition\">\n"
|
||||||
|
+ ((stack1 = container.invokePartial(partials["kanji.html"],depth0,{"name":"kanji.html","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
||||||
|
+ "</div>\n";
|
||||||
|
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
|
||||||
|
var stack1;
|
||||||
|
|
||||||
|
return ((stack1 = container.invokePartial(partials["header.html"],depth0,{"name":"header.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
|
||||||
|
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||||
|
+ ((stack1 = container.invokePartial(partials["footer.html"],depth0,{"name":"footer.html","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||||
|
},"usePartial":true,"useData":true});
|
||||||
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
|
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
|
||||||
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
|
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
|
||||||
"<div class=\"term\"><ruby>";
|
"<div class=\"term\"><ruby>";
|
||||||
|
@ -131,11 +131,11 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findKanji(text) {
|
findKanji(text) {
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
||||||
const processed = {};
|
const processed = {};
|
||||||
|
|
||||||
for (const c of text) {
|
for (const c of text) {
|
||||||
if (!processed.has(c)) {
|
if (!processed[c]) {
|
||||||
results = results.concat(this.dictionary.findKanji(c));
|
results = results.concat(this.dictionary.findKanji(c));
|
||||||
processed[c] = true;
|
processed[c] = true;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class Yomichan {
|
|||||||
|
|
||||||
onMessage(request, sender, callback) {
|
onMessage(request, sender, callback) {
|
||||||
const {action, data} = request, handlers = {
|
const {action, data} = request, handlers = {
|
||||||
findKanji: ({text}) => this.translator.onFindKanji(text),
|
findKanji: ({text}) => this.translator.findKanji(text),
|
||||||
findTerm: ({text}) => this.translator.findTerm(text),
|
findTerm: ({text}) => this.translator.findTerm(text),
|
||||||
getState: () => this.state,
|
getState: () => this.state,
|
||||||
getOptions: () => this.options,
|
getOptions: () => this.options,
|
||||||
|
@ -26,6 +26,7 @@ class Client {
|
|||||||
this.activateBtn = 2;
|
this.activateBtn = 2;
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
this.fgRoot = chrome.extension.getURL('fg');
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
|
||||||
window.addEventListener('message', this.onFrameMessage.bind(this));
|
window.addEventListener('message', this.onFrameMessage.bind(this));
|
||||||
@ -101,14 +102,8 @@ class Client {
|
|||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
} else {
|
} else {
|
||||||
range.setLength(length);
|
range.setLength(length);
|
||||||
|
|
||||||
const params = {
|
|
||||||
defs: results,
|
|
||||||
root: chrome.extension.getURL('fg')
|
|
||||||
};
|
|
||||||
|
|
||||||
renderText(
|
renderText(
|
||||||
params,
|
{defs: results, root: this.fgRoot},
|
||||||
'term-list.html',
|
'term-list.html',
|
||||||
(content) => this.showPopup(range, content)
|
(content) => this.showPopup(range, content)
|
||||||
);
|
);
|
||||||
@ -116,6 +111,16 @@ class Client {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayKanji(kanji) {
|
||||||
|
findKanji(kanji, (results) => {
|
||||||
|
renderText(
|
||||||
|
{defs: results, root: this.fgRoot},
|
||||||
|
'kanji-list.html',
|
||||||
|
(content) => this.popup.setContent(content)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
showPopup(range, content) {
|
showPopup(range, content) {
|
||||||
this.popup.showNextTo(range.getRect(), content);
|
this.popup.showNextTo(range.getRect(), content);
|
||||||
|
|
||||||
@ -136,10 +141,6 @@ class Client {
|
|||||||
this.lastRange = null;
|
this.lastRange = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayKanji(kanji) {
|
|
||||||
this.popup.setContent(kanji);
|
|
||||||
}
|
|
||||||
|
|
||||||
setEnabled(enabled) {
|
setEnabled(enabled) {
|
||||||
if (!(this.enabled = enabled)) {
|
if (!(this.enabled = enabled)) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
|
Loading…
Reference in New Issue
Block a user