aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
blob: e01172d5d5ffabd83e96932b7b559def5c079b3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import './console-frame.scss';
import { createStore } from 'shared/store';
import reducers from 'content/reducers';
import TopContentComponent from './components/top-content';
import FrameContentComponent from './components/frame-content';

const store = createStore(reducers);

let rootComponent = window.self === window.top
  ? new TopContentComponent(window, store)
  : new FrameContentComponent(window, store);

store.subscribe(() => {
  rootComponent.update();
});

browser.runtime.onMessage.addListener(msg => rootComponent.onMessage(msg));
rootComponent.update();

window.addEventListener('message', (event) => {
  let message = null;
  try {
    message = JSON.parse(event.data);
  } catch (e) {
    // ignore unexpected message
    return;
  }
  rootComponent.onMessage(message, event.source);
});