Add functioning cookiesOnly filter

This commit is contained in:
Kuba Orlik 2021-11-06 20:02:02 +01:00
parent f8f5921872
commit d220c22291
3 changed files with 56 additions and 25 deletions

View File

@ -18,7 +18,9 @@
"storage", "storage",
"<all_urls>", "<all_urls>",
"webRequest", "webRequest",
"webRequestBlocking" "webRequestBlocking",
"cookies",
"privacy"
], ],
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {

View File

@ -17,7 +17,7 @@ export class StolenDataEntry {
) { ) {
try { try {
this.iab = TCString.decode(value); this.iab = TCString.decode(value);
console.log(this.iab); // console.log(this.iab);
this.isIAB = true; this.isIAB = true;
} catch (e) {} } catch (e) {}
} }
@ -52,13 +52,17 @@ export class RequestCluster extends EventEmitter {
return false; return false;
} }
getStolenData(filter: { minValueLength: number }): StolenDataEntry[] { getStolenData(filter: {
minValueLength: number;
cookiesOnly: boolean;
}): StolenDataEntry[] {
return this.requests return this.requests
.map((request) => request.getAllStolenData()) .map((request) => request.getAllStolenData())
.reduce((a, b) => a.concat(b), []) .reduce((a, b) => a.concat(b), [])
.filter((entry) => { .filter((entry) => {
return entry.value.length >= filter.minValueLength; return entry.value.length >= filter.minValueLength;
}) })
.filter((entry) => !filter.cookiesOnly || entry.source === "cookie")
.sort((entry1, entry2) => .sort((entry1, entry2) =>
entry1.getPriority() > entry2.getPriority() ? -1 : 1 entry1.getPriority() > entry2.getPriority() ? -1 : 1
) )

View File

@ -48,13 +48,14 @@ const TabDropdown = ({
const StolenDataRow = ({ const StolenDataRow = ({
tabID, tabID,
shorthost, shorthost,
refreshToken,
minValueLength, minValueLength,
cookiesOnly,
}: { }: {
tabID: number; tabID: number;
shorthost: string; shorthost: string;
refreshToken: number; refreshToken: number;
minValueLength: number; minValueLength: number;
cookiesOnly: boolean;
}) => { }) => {
const cluster = memory.getClustersForTab(tabID)[shorthost]; const cluster = memory.getClustersForTab(tabID)[shorthost];
const icons: Record<Sources, string> = { const icons: Record<Sources, string> = {
@ -71,17 +72,19 @@ const StolenDataRow = ({
</h2> </h2>
<table> <table>
<tbody> <tbody>
{cluster.getStolenData({ minValueLength }).map((entry) => ( {cluster
<tr> .getStolenData({ minValueLength, cookiesOnly })
<th style={{ maxWidth: "200px", wordWrap: "break-word" }}> .map((entry) => (
{entry.name} <tr>
</th> <th style={{ maxWidth: "200px", wordWrap: "break-word" }}>
<td>{icons[entry.source]}</td> {entry.name}
<td style={{ wordWrap: "anywhere" as any }}> </th>
{entry.value} {entry.isIAB ? "!!!!! IAB" : ""} <td>{icons[entry.source]}</td>
</td> <td style={{ wordWrap: "anywhere" as any }}>
</tr> {entry.value} {entry.isIAB ? "!!!!! IAB" : ""}
))} </td>
</tr>
))}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -92,10 +95,12 @@ const StolenData = ({
pickedTab, pickedTab,
refreshToken, refreshToken,
minValueLength, minValueLength,
cookiesOnly,
}: { }: {
pickedTab: number | null; pickedTab: number | null;
refreshToken: number; refreshToken: number;
minValueLength: number; minValueLength: number;
cookiesOnly: boolean;
}) => { }) => {
const [tab, setTab] = useState<Tab | null>(null); const [tab, setTab] = useState<Tab | null>(null);
useEffect(() => { useEffect(() => {
@ -114,21 +119,29 @@ const StolenData = ({
<h1> <h1>
<img src={tab.favIconUrl} width="20" height="20" /> {tab.title} <img src={tab.favIconUrl} width="20" height="20" /> {tab.title}
</h1> </h1>
{clusters.map((cluster) => ( {clusters
<StolenDataRow .filter((cluster) => !cookiesOnly || cluster.hasCookies())
tabID={pickedTab} .map((cluster) => (
shorthost={cluster.id} <StolenDataRow
key={cluster.id} tabID={pickedTab}
refreshToken={refreshToken} shorthost={cluster.id}
minValueLength={minValueLength} key={cluster.id}
/> refreshToken={refreshToken}
))} minValueLength={minValueLength}
cookiesOnly={cookiesOnly}
/>
))}
</div> </div>
</div> </div>
); );
}; };
const Options = ({ minValueLength, setMinValueLength }) => { const Options = ({
minValueLength,
setMinValueLength,
cookiesOnly,
setCookiesOnly,
}) => {
return ( return (
<fieldset> <fieldset>
<h3>Zaawansowane ustawienia</h3> <h3>Zaawansowane ustawienia</h3>
@ -141,6 +154,14 @@ const Options = ({ minValueLength, setMinValueLength }) => {
value={minValueLength} value={minValueLength}
onChange={(e) => setMinValueLength(parseInt(e.target.value))} onChange={(e) => setMinValueLength(parseInt(e.target.value))}
/> />
<br />
<input
type="checkbox"
id="cookiesOnly"
value={cookiesOnly}
onChange={(e) => setCookiesOnly(e.target.checked)}
/>
<label htmlFor="cookiesOnly">Pokazuj tylko dane z cookiesów</label>
</fieldset> </fieldset>
); );
}; };
@ -148,6 +169,7 @@ const Options = ({ minValueLength, setMinValueLength }) => {
const Sidebar = () => { const Sidebar = () => {
const [pickedTab, setPickedTab] = useState<number | null>(null); const [pickedTab, setPickedTab] = useState<number | null>(null);
const [minValueLength, setMinValueLength] = useState<number | null>(7); const [minValueLength, setMinValueLength] = useState<number | null>(7);
const [cookiesOnly, setCookiesOnly] = useState<boolean>(false);
const counter = useEmitter(memory); const counter = useEmitter(memory);
return ( return (
<> <>
@ -163,11 +185,14 @@ const Sidebar = () => {
<Options <Options
minValueLength={minValueLength} minValueLength={minValueLength}
setMinValueLength={setMinValueLength} setMinValueLength={setMinValueLength}
cookiesOnly={cookiesOnly}
setCookiesOnly={setCookiesOnly}
/> />
<StolenData <StolenData
pickedTab={pickedTab} pickedTab={pickedTab}
refreshToken={counter} refreshToken={counter}
minValueLength={minValueLength} minValueLength={minValueLength}
cookiesOnly={cookiesOnly}
/> />
</> </>
); );