aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-24 18:59:29 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-24 18:59:29 -0700
commitcac6fc1427106420b28777d94907bf27ab1995a3 (patch)
treee8ab59bed16d7e2ba1ed887ffb2b9ccee510f9a9 /ext
parenta192a8d8b549d5979a427d86c51f94bb5f4be907 (diff)
Basic kanji output
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/dictionary.js13
-rw-r--r--ext/bg/js/templates.js13
-rw-r--r--ext/bg/js/translator.js6
-rw-r--r--ext/bg/js/yomichan.js2
-rw-r--r--ext/fg/js/client.js23
5 files changed, 38 insertions, 19 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 90a40ee5..cc7b507c 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -74,11 +74,16 @@ class Dictionary {
findKanji(kanji) {
const results = [];
- for (const name in this.termDicts) {
- const def = this.termDicts[name][kanji];
+ for (const name in this.kanjiDicts) {
+ const def = this.kanjiDicts[name][kanji];
if (def) {
- const [c, k, o, g] = def;
- results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
+ const [k, o, g] = def;
+ results.push({
+ character: kanji,
+ kunyomi: k.split(' '),
+ onyomi: o.split(' '),
+ glossary: g
+ });
}
}
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 1c14e569..1133e41a 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -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)))
+ "</a>\n";
},"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) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
"<div class=\"term\"><ruby>";
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 6be80581..606f6ec5 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -131,11 +131,11 @@ class Translator {
}
findKanji(text) {
- let results = [];
-
+ let results = [];
const processed = {};
+
for (const c of text) {
- if (!processed.has(c)) {
+ if (!processed[c]) {
results = results.concat(this.dictionary.findKanji(c));
processed[c] = true;
}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 7c802675..ac02f882 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -50,7 +50,7 @@ class Yomichan {
onMessage(request, sender, callback) {
const {action, data} = request, handlers = {
- findKanji: ({text}) => this.translator.onFindKanji(text),
+ findKanji: ({text}) => this.translator.findKanji(text),
findTerm: ({text}) => this.translator.findTerm(text),
getState: () => this.state,
getOptions: () => this.options,
diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js
index 7f07d918..2355cf81 100644
--- a/ext/fg/js/client.js
+++ b/ext/fg/js/client.js
@@ -26,6 +26,7 @@ class Client {
this.activateBtn = 2;
this.enabled = false;
this.options = {};
+ this.fgRoot = chrome.extension.getURL('fg');
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
window.addEventListener('message', this.onFrameMessage.bind(this));
@@ -101,14 +102,8 @@ class Client {
this.hidePopup();
} else {
range.setLength(length);
-
- const params = {
- defs: results,
- root: chrome.extension.getURL('fg')
- };
-
renderText(
- params,
+ {defs: results, root: this.fgRoot},
'term-list.html',
(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) {
this.popup.showNextTo(range.getRect(), content);
@@ -136,10 +141,6 @@ class Client {
this.lastRange = null;
}
- displayKanji(kanji) {
- this.popup.setContent(kanji);
- }
-
setEnabled(enabled) {
if (!(this.enabled = enabled)) {
this.hidePopup();