diff options
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/api.js | 4 | ||||
-rw-r--r-- | ext/fg/js/client.js | 38 | ||||
-rw-r--r-- | ext/fg/js/popup.js | 22 |
3 files changed, 21 insertions, 43 deletions
diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index 7997a73f..c65b1702 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -21,8 +21,8 @@ function sendMessage(action, data, callback) { chrome.runtime.sendMessage({action: action, data: data}, callback); } -function findTerm(text, dict, callback) { - sendMessage('findTerm', {text: text, dict: dict}, callback); +function findTerm(text, callback) { + sendMessage('findTerm', {text: text}, callback); } function findKanji(text, callback) { diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index aae051fa..271caa58 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -19,12 +19,11 @@ class Client { constructor() { - this.popupMousePos = null; - this.popupQuery = ''; - this.popupOffset = 10; - this.enabled = false; - this.options = {}; - this.activeDict = ''; + this.lastMosePos = null; + this.popupQuery = ''; + this.popupOffset = 10; + this.enabled = false; + this.options = null; this.popup = document.createElement('iframe'); this.popup.classList.add('yomichan-popup'); @@ -41,29 +40,29 @@ class Client { window.addEventListener('resize', (e) => this.hidePopup()); getOptions((opts) => { - this.setActiveDict('edict'); + this.setDict('edict'); this.setOptions(opts); getState((state) => this.setEnabled(state === 'enabled')); }); } onKeyDown(e) { - if (this.enabled && this.popupMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) { - this.searchAtPoint(this.popupMousePos); + if (this.enabled && this.lastMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) { + this.searchAtPoint(this.lastMousePos); } } onMouseMove(e) { - this.popupMousePos = {x: e.clientX, y: e.clientY}; + this.lastMousePos = {x: e.clientX, y: e.clientY}; if (this.enabled && (e.shiftKey || e.which === 2)) { - this.searchAtPoint(this.popupMousePos); + this.searchAtPoint(this.lastMousePos); } } onMouseDown(e) { - this.popupMousePos = {x: e.clientX, y: e.clientY}; + this.lastMousePos = {x: e.clientX, y: e.clientY}; if (this.enabled && (e.shiftKey || e.which === 2)) { - this.searchAtPoint(this.popupMousePos); + this.searchAtPoint(this.lastMousePos); } else { this.hidePopup(); } @@ -85,8 +84,8 @@ class Client { onFrameMessage(e) { const {action, data} = e.data; switch (action) { - case 'setActiveDict': - this.setActiveDict(data); + case 'selectDict': + this.setDict(data); break; } } @@ -114,11 +113,11 @@ class Client { return; } - findTerm(popupQuery, this.activeDict, ({results, length}) => { + findTerm(popupQuery, ({results, length}) => { if (length === 0) { this.hidePopup(); } else { - const params = {defs: results, root: chrome.extension.getURL('fg'), activeDict: this.activeDict}; + const params = {defs: results, root: chrome.extension.getURL('fg')}; renderText(params, 'term-list.html', (html) => this.showPopup(range, html, popupQuery, length)); } }); @@ -169,8 +168,9 @@ class Client { this.options = opts; } - setActiveDict(activeDict) { - this.activeDict = activeDict; + setDict(dict) { + this.dict = dict; + alert(dict); } } diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js deleted file mode 100644 index 2753a863..00000000 --- a/ext/fg/js/popup.js +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net> - * Author: Alex Yatskov <alex@foosoft.net> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -function setActiveDict(dict) { - parent.postMessage({action: 'setActiveDict', data: dict}, '*'); -} |