aboutsummaryrefslogtreecommitdiff
path: root/apps/extension/src/content.tsx
blob: 83d976cd17cc1a985dc4f62cca4e8ad959f92660 (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
45
window.addEventListener("message", (event) => {
  if (event.source !== window) {
    return;
  }
  const { jwt } = event.data;

  if (jwt) {
    if (
      !(
        window.location.hostname === "localhost" ||
        window.location.hostname === "anycontext.dhr.wtf" ||
        window.location.hostname === "supermemory.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((token) => {
  ReactDOM.createRoot(
    document.getElementById("anycontext-app-container")!,
  ).render(<SideBar jwt={token} />);
});