summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-08 22:20:07 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-13 23:11:56 -0500
commit863e36e829e4e01a8c1e7b15384820ad7766d6a8 (patch)
tree56a8f4ec977c6fe0aea6d19e0b141d4443c420a6 /ext/fg/js
parente2c5c16da68bb982e59dc69f469b2d13faa2f0b3 (diff)
Update frontend message handlers
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/frontend.js52
1 files changed, 19 insertions, 33 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 54e78bf5..6c1dafe5 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -77,20 +77,19 @@ class Frontend extends TextScanner {
onWindowMessage(e) {
const action = e.data;
- const handlers = Frontend.windowMessageHandlers;
- if (hasOwn(handlers, action)) {
- const handler = handlers[action];
- handler(this);
- }
+ const handler = Frontend._windowMessageHandlers.get(action);
+ if (typeof handler !== 'function') { return false; }
+
+ handler(this);
}
onRuntimeMessage({action, params}, sender, callback) {
- const handlers = Frontend.runtimeMessageHandlers;
- if (hasOwn(handlers, action)) {
- const handler = handlers[action];
- const result = handler(this, params);
- callback(result);
- }
+ const handler = Frontend._runtimeMessageHandlers.get(action);
+ if (typeof handler !== 'function') { return false; }
+
+ const result = handler(this, params, sender);
+ callback(result);
+ return false;
}
getMouseEventListeners() {
@@ -195,26 +194,13 @@ class Frontend extends TextScanner {
}
}
-Frontend.windowMessageHandlers = {
- popupClose: (self) => {
- self.onSearchClear(true);
- },
+Frontend._windowMessageHandlers = new Map([
+ ['popupClose', (self) => self.onSearchClear(true)],
+ ['selectionCopy', () => document.execCommand('copy')]
+]);
- selectionCopy: () => {
- document.execCommand('copy');
- }
-};
-
-Frontend.runtimeMessageHandlers = {
- optionsUpdate: (self) => {
- self.updateOptions();
- },
-
- popupSetVisibleOverride: (self, {visible}) => {
- self.popup.setVisibleOverride(visible);
- },
-
- getUrl: () => {
- return {url: window.location.href};
- }
-};
+Frontend._runtimeMessageHandlers = new Map([
+ ['optionsUpdate', (self) => self.updateOptions()],
+ ['popupSetVisibleOverride', (self, {visible}) => self.popup.setVisibleOverride(visible)],
+ ['getUrl', () => ({url: window.location.href})]
+]);