diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-08 20:01:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-08 20:01:57 +0900 |
commit | 8b9125871b59d915324176ab959bb0aed20a727a (patch) | |
tree | a10db125bd25c1447bb08de2ef156c010243f019 /src/console/index.js | |
parent | bbf90e77e99846c970118744066fbc21006761b5 (diff) | |
parent | 7ac00fce6f6c431f96c531179c6af3796df7e07a (diff) |
Merge pull request #24 from ueokande/yank-url
Yank url
Diffstat (limited to 'src/console/index.js')
-rw-r--r-- | src/console/index.js | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/console/index.js b/src/console/index.js index 7396a96..895fcc2 100644 --- a/src/console/index.js +++ b/src/console/index.js @@ -17,18 +17,25 @@ window.addEventListener('load', () => { consoleComponent = new ConsoleComponent(document.body, store); }); +const onMessage = (message) => { + switch (message.type) { + case messages.CONSOLE_SHOW_COMMAND: + return store.dispatch(consoleActions.showCommand(message.command)); + case messages.CONSOLE_SHOW_ERROR: + return store.dispatch(consoleActions.showError(message.text)); + case messages.CONSOLE_SHOW_INFO: + return store.dispatch(consoleActions.showInfo(message.text)); + case messages.CONSOLE_HIDE_COMMAND: + return store.dispatch(consoleActions.hideCommand()); + } +}; + store.subscribe(() => { completionComponent.update(); consoleComponent.update(); }); -browser.runtime.onMessage.addListener((action) => { - switch (action.type) { - case messages.CONSOLE_SHOW_COMMAND: - return store.dispatch(consoleActions.showCommand(action.command)); - case messages.CONSOLE_SHOW_ERROR: - return store.dispatch(consoleActions.showError(action.text)); - case messages.CONSOLE_HIDE: - return store.dispatch(consoleActions.hide(action.command)); - } -}); +browser.runtime.onMessage.addListener(onMessage); +window.addEventListener('message', (message) => { + onMessage(JSON.parse(message.data)); +}, false); |