From bcd34149ab120f4bd0b823fbd6ae4efadfb02e90 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Apr 2016 17:36:15 -0700 Subject: Plumbing --- ext/bg/js/templates.js | 8 +++++--- ext/fg/js/client.js | 20 ++++++++++++++++++-- ext/manifest.json | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 0b7d83e7..3388ec9b 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -7,13 +7,15 @@ templates['defs.html'] = template({"1":function(container,depth0,helpers,partial + ((stack1 = container.invokePartial(partials["term.html"],depth0,{"name":"term.html","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "") + " \n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { - var stack1, helper, alias1=depth0 != null ? depth0 : {}; + var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return "\n\n \n \n \n \n \n \n
\n \n
\n\n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + " \n\n"; + + "\n \n \n\n"; },"usePartial":true,"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; diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 8739fa2d..b757123c 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -31,7 +31,8 @@ class Client { this.popup.addEventListener('scroll', (e) => e.stopPropagation()); document.body.appendChild(this.popup); - chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); + chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this)); + window.addEventListener('message', this.onFrameMessage.bind(this)); window.addEventListener('mousedown', this.onMouseDown.bind(this)); window.addEventListener('mousemove', this.onMouseMove.bind(this)); window.addEventListener('keydown', this.onKeyDown.bind(this)); @@ -39,6 +40,7 @@ class Client { window.addEventListener('resize', (e) => this.hidePopup()); getOptions((opts) => { + this.setDict('edict'); this.setOptions(opts); getState((state) => this.setEnabled(state === 'enabled')); }); @@ -66,7 +68,7 @@ class Client { } } - onMessage({name, value}, sender, callback) { + onBgMessage({name, value}, sender, callback) { switch (name) { case 'state': this.setEnabled(value === 'enabled'); @@ -79,6 +81,15 @@ class Client { callback(); } + onFrameMessage(e) { + const {action, data} = e.data; + switch (action) { + case 'selectDict': + this.setDict(data); + break; + } + } + searchAtPoint(point) { const range = getRangeAtPoint(point, this.options.scanLength); if (range === null) { @@ -156,6 +167,11 @@ class Client { setOptions(opts) { this.options = opts; } + + setDict(dict) { + this.dict = dict; + alert(dict); + } } window.yomiClient = new Client(); diff --git a/ext/manifest.json b/ext/manifest.json index e5b21268..18b37b91 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -20,7 +20,7 @@ "background": {"page": "bg/background.html"}, "options_page": "bg/options.html", "permissions": ["storage"], - "web_accessible_resources": ["fg/css/popup.css"], + "web_accessible_resources": ["fg/css/popup.css", "fg/js/popup.js"], "content_scripts": [{ "matches": ["*://*/*"], -- cgit v1.2.3