rentgen/sidebar/sidebar.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-10-03 09:03:56 +02:00
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
2021-11-07 13:01:01 +01:00
import Options from "../options";
2021-11-07 09:17:19 +01:00
import { StolenData } from "./stolen-data";
2021-11-07 13:57:24 +01:00
import { getMemory, useEmitter } from "../util";
2021-10-03 09:03:56 +02:00
async function getCurrentTab() {
const [tab] = await browser.tabs.query({
active: true,
windowId: browser.windows.WINDOW_ID_CURRENT,
});
2021-11-06 21:48:25 +01:00
return tab;
2021-10-03 09:03:56 +02:00
}
const Sidebar = () => {
2021-11-06 21:48:25 +01:00
const [origin, setOrigin] = useState<string | null>(null);
2021-10-04 18:51:51 +02:00
const [minValueLength, setMinValueLength] = useState<number | null>(7);
2021-11-06 20:02:02 +01:00
const [cookiesOnly, setCookiesOnly] = useState<boolean>(false);
2021-11-07 13:57:24 +01:00
const [counter, setCounter] = useEmitter(getMemory());
2021-11-06 21:48:25 +01:00
useEffect(() => {
const listener = async (data) => {
console.log("tab change!");
const tab = await getCurrentTab();
const url = new URL(tab.url);
if (url.origin.startsWith("moz-extension")) {
return;
}
setOrigin(url.origin);
};
browser.tabs.onUpdated.addListener(listener);
return () => {
browser.tabs.onUpdated.removeListener(listener);
};
});
2021-10-03 09:03:56 +02:00
return (
<>
2021-11-06 21:48:25 +01:00
{/* <div id="selector">
2021-10-03 09:03:56 +02:00
<TabDropdown setPickedTab={setPickedTab} pickedTab={pickedTab} />
<button
id="get_current_tab_button"
onClick={async () => setPickedTab(await getCurrentTab())}
>
Wybierz aktywną kartę{" "}
</button>
2021-11-06 21:48:25 +01:00
</div> */}
2021-10-03 20:13:36 +02:00
<Options
minValueLength={minValueLength}
setMinValueLength={setMinValueLength}
2021-11-06 20:02:02 +01:00
cookiesOnly={cookiesOnly}
setCookiesOnly={setCookiesOnly}
2021-10-03 16:33:23 +02:00
/>
<StolenData
2021-11-06 21:48:25 +01:00
origin={origin}
2021-10-03 16:33:23 +02:00
refreshToken={counter}
refresh={() => setCounter((c) => c + 1)}
2021-10-03 16:33:23 +02:00
minValueLength={minValueLength}
2021-11-06 20:02:02 +01:00
cookiesOnly={cookiesOnly}
2021-10-03 16:33:23 +02:00
/>
2021-10-03 09:03:56 +02:00
</>
);
};
ReactDOM.render(<Sidebar />, document.getElementById("app"));