aboutsummaryrefslogtreecommitdiff
path: root/apps/extension/src/content.tsx
blob: 0bc71e07ad660f27cf347400896602a7455c2457 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
window.addEventListener('message', (event) => {
  if (event.source !== window) {
    return;
  }
  const { jwt } = event.data;

  if (jwt) {
    if (
      !(
        window.location.hostname === 'localhost' ||
        window.location.hostname.endsWith('dhr.wtf')
      )
    ) {
      console.log(
        'JWT is only allowed to be used on localhost or anycontext.dhr.wtf',
      );
      return;
    }

    chrome.storage.local.set({ jwt }, () => {});
  }
});

const appContainer = document.createElement('div');
appContainer.id = 'anycontext-app-container';

// First in the body, above the content
document.body.insertBefore(appContainer, document.body.firstChild);

appContainer.style.zIndex = '9999';

import ReactDOM from 'react-dom/client';
import SideBar from './SideBar';

// get JWT from local storage
const jwt = chrome.storage.local.get('jwt').then((data) => {
  return data.jwt;
}) as Promise<string>

jwt.then((jwt) => {
  ReactDOM.createRoot(
    document.getElementById('anycontext-app-container')!,
  ).render(<SideBar jwt={jwt} />);
});