summaryrefslogtreecommitdiff
path: root/content_script.js
blob: 680ac6c00f966932379e9d07b2f409965d99a163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
window.onload = () => {
  if (window.recorderInjected) return
  Object.defineProperty(window, 'recorderInjected', { value: true, writable: false })

  // Setup message passing
  const port = chrome.runtime.connect(chrome.runtime.id)
  port.onMessage.addListener(msg => window.postMessage(msg, '*'))
  window.addEventListener('message', event => {
    // Relay client messages
    if (event.source === window && event.data.type) {
      port.postMessage(event.data)
    }
    if(event.data.type === 'PLAYBACK_COMPLETE'){
      port.postMessage({ type: 'REC_STOP' }, '*')
    }
    if(event.data.downloadComplete){
      document.querySelector('html').classList.add('downloadComplete')
    }
  })

  document.title = 'bbbrecorder'
  window.postMessage({ type: 'REC_CLIENT_PLAY', data: { url: window.location.origin } }, '*')
}