summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js')
-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();