summaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-17 17:36:15 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-17 17:36:15 -0700
commitbcd34149ab120f4bd0b823fbd6ae4efadfb02e90 (patch)
treeac41a95b60d8fabe04c0999e514aaaa5db3e7c6e /ext/fg
parentbe43981e259bc833a92b3289246c9c75189b1c45 (diff)
Plumbing
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/client.js20
1 files changed, 18 insertions, 2 deletions
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();