diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-15 07:37:42 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-15 07:37:42 +0900 |
commit | 042aa94936c9114f0a0fd05fb0a91df8f5565ecd (patch) | |
tree | 8a9b0ad4d771cc8aeb82081ae9c6a7c2354df971 /src/content | |
parent | 157ebaef9c386175f84332bab003ec9d53ef3bac (diff) |
console only top window
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/index.js | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/content/index.js b/src/content/index.js index 65be89f..4d1658e 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -28,8 +28,6 @@ store.subscribe(() => { } }); -consoleFrames.initialize(window.document); - const reloadSettings = () => { return browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, @@ -38,17 +36,43 @@ const reloadSettings = () => { }); }; -browser.runtime.onMessage.addListener((action) => { - switch (action.type) { - case messages.CONSOLE_HIDE_COMMAND: - window.focus(); - consoleFrames.blur(window.document); - return Promise.resolve(); - case messages.SETTINGS_CHANGED: - return reloadSettings(); - default: - return Promise.resolve(); - } -}); +// TODO: the followin methods should be implemented in each top component and +// frame component +const initTopComponents = () => { + consoleFrames.initialize(window.document); + + browser.runtime.onMessage.addListener((action) => { + switch (action.type) { + case messages.CONSOLE_HIDE_COMMAND: + window.focus(); + consoleFrames.blur(window.document); + return Promise.resolve(); + case messages.SETTINGS_CHANGED: + return reloadSettings(); + default: + return Promise.resolve(); + } + }); +}; + +const initFrameConponents = () => { + browser.runtime.onMessage.addListener((action) => { + switch (action.type) { + case messages.CONSOLE_HIDE_COMMAND: + window.focus(); + return Promise.resolve(); + case messages.SETTINGS_CHANGED: + return reloadSettings(); + default: + return Promise.resolve(); + } + }); +}; + +if (window.self === window.top) { + initTopComponents(); +} else { + initFrameConponents(); +} reloadSettings(); |