summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-17 19:06:57 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-17 19:06:57 -0700
commitd5170414af9287143a9906fd81fde49318be4617 (patch)
tree27764bde977e1e17c36543f3f53d1b29b0584f74 /ext
parentde268e73a613b963ea982f34ca7439d57694facd (diff)
Adding kanji links
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/templates.js52
-rw-r--r--ext/bg/js/translator.js15
-rw-r--r--ext/bg/js/yomichan.js12
-rw-r--r--ext/fg/css/popup.css6
4 files changed, 62 insertions, 23 deletions
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index f571195d..75445786 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -28,59 +28,65 @@ templates['kanji.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(co
+ "\n</div>\n";
},"useData":true});
templates['term.html'] = template({"1":function(container,depth0,helpers,partials,data) {
- var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
-
- return "<div class=\"term\"><ruby>"
- + alias4(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"expression","hash":{},"data":data}) : helper)))
- + "<rt>"
- + alias4(((helper = (helper = helpers.reading || (depth0 != null ? depth0.reading : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"reading","hash":{},"data":data}) : helper)))
+ var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
+ "<div class=\"term\"><ruby>";
+ stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
+ if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "<rt>"
+ + container.escapeExpression(((helper = (helper = helpers.reading || (depth0 != null ? depth0.reading : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"reading","hash":{},"data":data}) : helper)))
+ "</rt></ruby></div>\n";
-},"3":function(container,depth0,helpers,partials,data) {
+},"2":function(container,depth0,helpers,partials,data) {
var helper;
- return "<div class=\"term\">"
- + container.escapeExpression(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"expression","hash":{},"data":data}) : helper)))
- + "</div>\n";
-},"5":function(container,depth0,helpers,partials,data) {
+ return container.escapeExpression(((helper = (helper = helpers.expression || (depth0 != null ? depth0.expression : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"expression","hash":{},"data":data}) : helper)));
+},"4":function(container,depth0,helpers,partials,data) {
+ var stack1, helper, options, buffer =
+ "<div class=\"term\">";
+ stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
+ if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
+ if (stack1 != null) { buffer += stack1; }
+ return buffer + "</div>\n";
+},"6":function(container,depth0,helpers,partials,data) {
var stack1;
return "<div class=\"rules\">\n"
- + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n";
-},"6":function(container,depth0,helpers,partials,data) {
+},"7":function(container,depth0,helpers,partials,data) {
var stack1;
return " <span class=\"rule\">"
+ container.escapeExpression(container.lambda(depth0, depth0))
+ "</span> "
- + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(8, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n";
-},"7":function(container,depth0,helpers,partials,data) {
+},"8":function(container,depth0,helpers,partials,data) {
return "&laquo;";
-},"9":function(container,depth0,helpers,partials,data) {
+},"10":function(container,depth0,helpers,partials,data) {
var stack1;
return "<div class=\"tags\">\n"
- + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n";
-},"10":function(container,depth0,helpers,partials,data) {
+},"11":function(container,depth0,helpers,partials,data) {
return " <span class=\"tag\">"
+ container.escapeExpression(container.lambda(depth0, depth0))
+ "</span>\n";
-},"12":function(container,depth0,helpers,partials,data) {
+},"13":function(container,depth0,helpers,partials,data) {
return " <li><span>"
+ container.escapeExpression(container.lambda(depth0, depth0))
+ "</span></li>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
- return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.program(3, data, 0),"data":data})) != null ? stack1 : "")
+ return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.program(4, data, 0),"data":data})) != null ? stack1 : "")
+ "\n"
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n"
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n<div class=\"glossary\">\n <ol>\n"
- + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ol>\n</div>\n";
},"useData":true});
templates['term-list.html'] = template({"1":function(container,depth0,helpers,partials,data) {
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 46d63ed0..1a024a40 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -166,6 +166,21 @@ class Translator {
}
}
+ static isHiragana(c) {
+ const code = c.charCodeAt(0);
+ return code >= 0x3040 && code < 0x30a0;
+ }
+
+ static isKatakana(c) {
+ const code = c.charCodeAt(0);
+ return code >= 0x30a0 && code < 0x3100;
+ }
+
+ static isKanji(c) {
+ const code = c.charCodeAt(0);
+ return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
+ }
+
static loadData(url, callback) {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', () => callback(xhr.responseText));
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index a66c1244..11d71ae1 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -20,6 +20,18 @@
class Yomichan {
constructor() {
Handlebars.partials = Handlebars.templates;
+ Handlebars.registerHelper('kanjiLinks', function(options) {
+ let result = '';
+ for (const c of options.fn(this)) {
+ if (Translator.isKanji(c)) {
+ result += `<a href="#">${c}</a>`;
+ } else {
+ result += c;
+ }
+ }
+
+ return result;
+ });
this.translator = new Translator();
this.updateState('disabled');
diff --git a/ext/fg/css/popup.css b/ext/fg/css/popup.css
index 250b64f8..2e694b42 100644
--- a/ext/fg/css/popup.css
+++ b/ext/fg/css/popup.css
@@ -31,6 +31,12 @@ body {
display: inline-block;
}
+.term a {
+ border-bottom: 1px #777 dashed;
+ color: #333;
+ text-decoration: none;
+}
+
.rules {
color: #777;
display: inline-block;