import React, { useEffect, useState } from "react"; import { Readability } from "@mozilla/readability"; import tailwindBg from "../public/tailwind_bg.png"; export default function ContentApp({ token }: { token: string | undefined }) { const [text, setText] = useState(""); const [hover, setHover] = useState(false); const [loading, setLoading] = useState(false); const [importedCount, setImportedCount] = useState(0); const [isImporting, setIsImporting] = useState(false); useEffect(() => { document.addEventListener("mousemove", (e) => { const percentageX = (e.clientX / window.innerWidth) * 100; const percentageY = (e.clientY / window.innerHeight) * 100; if (percentageX > 75 && percentageY > 75) { setHover(true); } else { setHover(false); } }); const getUserData = () => { const NO_JWT = [ "supermemory.ai", "beta.supermemory.ai", "localhost:3000", ]; chrome.runtime.sendMessage({ type: "getJwt" }, (response) => { if (!response.jwt && !NO_JWT.includes(window.location.host)) { window.location.href = "https://supermemory.ai/signin"; } console.log("jwt", response.jwt); }); }; getUserData(); chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { console.log("request", request); console.log("sender", sender); console.log("sendResponse", sendResponse); if (request.type === "import-update") { setIsImporting(true); setImportedCount(request.importedCount); } if (request.type === "import-done") { setIsImporting(false); } }); return () => { document.removeEventListener("mousemove", () => {}); }; }, []); function sendUrlToAPI(spaces: number[]) { setLoading(true); setTimeout(() => { setLoading(false); }, 1500); // get the current URL const url = window.location.href; const blacklist: string[] = []; // check if the URL is blacklisted if (blacklist.some((blacklisted) => url.includes(blacklisted))) { console.log("URL is blacklisted"); return; } else { const clone = document.cloneNode(true) as Document; const article = new Readability(clone).parse(); const ogImage = document .querySelector('meta[property="og:image"]') ?.getAttribute("content"); const favicon = ( document.querySelector('link[rel="icon"]') as HTMLLinkElement )?.href; console.log("article", article); chrome.runtime.sendMessage({ type: "urlSave", content: article?.textContent, url, spaces, title: article?.title, description: article?.excerpt, ogImage: ogImage, favicon: favicon, }); } } return (
{isImporting && (

Your twitter bookmarks are being imported.

This is done completely locally, so please keep this tab open!

Imported {importedCount} bookmarks
)} {(window.location.host === "twitter.com" || window.location.host === "x.com") && ( )}
); }