aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-20 13:15:26 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-20 13:15:26 -0500
commite14bd75a4f2f25c8fc36ee801d952960987e76ad (patch)
tree9f9744ca05ebea90968da66bf509c50c51a237e7 /ext/mixed
parentcab2a3998169040a6a6d5bda828d4a8af5592cd6 (diff)
Change how getUrl message is handled
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/core.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 36056c36..edb1f913 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -231,15 +231,29 @@ class EventDispatcher {
* Default message handlers
*/
-(() => {
- function onMessage({action}, sender, callback) {
- switch (action) {
- case 'getUrl':
- callback({url: window.location.href});
- break;
+const yomichan = (() => {
+ class Yomichan {
+ constructor() {
+ this._messageHandlers = new Map([
+ ['getUrl', this._onMessageGetUrl.bind(this)]
+ ]);
+
+ chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
+ }
+
+ _onMessage({action, params}, sender, callback) {
+ const handler = this._messageHandlers.get(action);
+ if (typeof handler !== 'function') { return false; }
+
+ const result = handler(params, sender);
+ callback(result);
+ return false;
+ }
+
+ _onMessageGetUrl() {
+ return {url: window.location.href};
}
- return false;
}
- chrome.runtime.onMessage.addListener(onMessage);
+ return new Yomichan();
})();