import React, { useEffect, useState } from "react"; import ReactDOM from "react-dom"; import memory from "./memory"; import { RequestCluster, Sources } from "./request-cluster"; import { Tab, useEmitter } from "./util"; async function getTabByID(id: number) { const tabs = await browser.tabs.query({ currentWindow: true }); return tabs.find((tab) => tab.id == id); } async function getCurrentTab() { const [tab] = await browser.tabs.query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT, }); return tab.id; } const TabDropdown = ({ setPickedTab, pickedTab, }: { setPickedTab: (tab_id: number) => void; pickedTab: number; }) => { const [tabs, setTabs] = useState([]); useEffect(() => { browser.tabs.query({ currentWindow: true }).then(setTabs); }, []); return ( { setPickedTab(parseInt(e.target.value)); }} > {tabs.map((tab) => ( {tab.title} ))} ); }; const StolenDataRow = ({ tabID, shorthost, refreshToken, minValueLength, }: { tabID: number; shorthost: string; refreshToken: number; minValueLength: number; }) => { const cluster = memory.getClustersForTab(tabID)[shorthost]; const icons: Record = { cookie: "🍪", pathname: "🛣", queryparams: "🅿", header: "H", }; return ( {cluster.id} {cluster.hasCookies() ? "🍪" : ""} x {cluster.requests.length} {cluster.getStolenData({ minValueLength }).map((entry) => ( {entry.name} {icons[entry.source]} {entry.value} {entry.isIAB ? "!!!!! IAB" : ""} ))} ); }; const StolenData = ({ pickedTab, refreshToken, minValueLength, }: { pickedTab: number | null; refreshToken: number; minValueLength: number; }) => { const [tab, setTab] = useState(null); useEffect(() => { getTabByID(pickedTab).then(setTab); }, [pickedTab]); if (!pickedTab || !tab) { return ; } const clusters = Object.values(memory.getClustersForTab(pickedTab)).sort( RequestCluster.sortCompare ); return ( {" "} {tab.title} {clusters.map((cluster) => ( ))} ); }; const Options = ({ minValueLength, setMinValueLength }) => { return ( Zaawansowane ustawienia Pokazuj tylko wartości o długości co najmniej{" "} setMinValueLength(parseInt(e.target.value))} /> ); }; const Sidebar = () => { const [pickedTab, setPickedTab] = useState(null); const [minValueLength, setMinValueLength] = useState(7); const counter = useEmitter(memory); return ( <> setPickedTab(await getCurrentTab())} > Wybierz aktywną kartę{" "} > ); }; ReactDOM.render(, document.getElementById("app"));