rentgen/components/toolbar/toolbar.tsx

143 lines
5.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import ReactDOM from 'react-dom';
import { useEmitter } from '../../util';
import { getMemory } from '../../memory';
2022-04-11 13:52:45 +02:00
browser.browserAction.setBadgeBackgroundColor({ color: '#ffb900' });
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,
});
return tab;
2021-10-03 09:03:56 +02:00
}
import './../../styles/global.scss';
import './toolbar.scss';
const Toolbar = () => {
const [origin, setOrigin] = React.useState<string | null>(null);
const [minValueLength, setMinValueLength] = React.useState<number | null>(
localStorage.getItem('minValueLength') === null
? 7
: (localStorage.getItem('minValueLength') as unknown as number)
);
const [cookiesOnly, setCookiesOnly] = React.useState<boolean>(false);
const [stolenDataView, setStolenDataView] = React.useState<boolean>(true);
2022-02-02 10:33:09 +01:00
const [cookiesOrOriginOnly, setCookiesOrOriginOnly] = React.useState<boolean>(false);
const [eventCounts, setEventCounts] = useEmitter(getMemory());
2022-02-02 10:33:09 +01:00
const [marksOccurrence, setMarksOccurrence] = React.useState<boolean>(false);
const [warningDataDialogAck, setWarningDataDialogAck] = React.useState<boolean>(
localStorage.getItem('warningDataDialogAck') === null
? true
: localStorage.getItem('warningDataDialogAck') == 'true'
? true
: false
);
const [logoVisibility, setLogoVisibility] = React.useState<boolean>(
localStorage.getItem('logoVisibility') === null
? false
: localStorage.getItem('logoVisibility') == 'true'
? true
: false
);
2021-11-06 21:48:25 +01:00
React.useEffect(() => {
const listener = async () => {
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);
listener();
return () => {
browser.tabs.onUpdated.removeListener(listener);
};
});
2021-11-06 21:48:25 +01:00
React.useEffect(() => {
2022-02-02 10:33:09 +01:00
for (const cluster of Object.values(getMemory().getClustersForOrigin(origin))) {
if (cluster.hasMarks()) {
return setMarksOccurrence(true);
2022-01-19 14:12:52 +01:00
}
}
2022-04-11 13:52:45 +02:00
return setMarksOccurrence(false);
}, [eventCounts['*'], origin]);
2022-01-19 14:12:52 +01:00
return (
<div className="toolbar">
2022-04-13 13:57:31 +02:00
<header className="header">
<img src="../../assets/icon-addon.svg" height={32}></img>
<div
2022-01-24 12:50:54 +01:00
className={
logoVisibility
? 'webpage-metadata'
: 'webpage-metadata webpage-metadata--without-logo'
2022-01-24 12:50:54 +01:00
}
>
{origin ? (
<>
<span>Analiza strony</span>
2022-02-02 10:33:09 +01:00
<span className="webpage-metadata--hyperlink">{origin}</span>
</>
2022-01-29 21:16:53 +01:00
) : (
<span>Przejdź do wybranej strony internetowej</span>
2022-01-29 21:16:53 +01:00
)}
</div>
{stolenDataView ? (
<a href="https://internet-czas-dzialac.pl">
2022-02-02 10:33:09 +01:00
<img src="/assets/icons/info_circle_outline.svg" width="20" height="20" />
</a>
) : (
<button onClick={() => setStolenDataView(true)}>
2022-02-02 10:33:09 +01:00
<img src="/assets/icons/short_left.svg" width="20" height="20" />
</button>
)}
</header>
2022-01-29 21:16:53 +01:00
2022-04-13 13:57:31 +02:00
<section className="summary">
<div>
<div className="counters">
<div className="counter counter--browser-history">12</div>
<div className="counter counter--cookies">21</div>
</div>
<div className="big-counter">33</div>
</div>
<p>Liczba wykrytych domen podmiotów trzecich</p>
</section>
2022-02-02 10:33:09 +01:00
2022-04-13 13:57:31 +02:00
<section className="details">
<p>
Strona wp.pl wysłała informacje o części Twojej historii przeglądania do
facebook.com, adnsx.com (i 43 innych).
</p>
<p>
Dokonała też zapisu i odczytu plików Cookie dla domen doubleclick.google.net,
3dsio.com (i 59 innych).
</p>
</section>
2022-04-13 13:57:31 +02:00
<section className="warning-container">
<span>
<strong>Takie przetwarzanie danych może być niezgodne z prawem.</strong> Kliknij
w przycisk <i>Generuj raport</i>, aby pomóc ustalić, czy ta strona nie narusza
RODO.
</span>
</section>
<section className="actions">
<a href="">Pokaż szczegóły</a>
<button>Generuj raport</button>
</section>
</div>
);
2021-10-03 09:03:56 +02:00
};
ReactDOM.render(<Toolbar />, document.getElementById('toolbar'));