From 8e7091c406aa0d5fcce0775e5ad06cac6e608735 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Wed, 24 Nov 2021 14:19:12 +0100 Subject: [PATCH] Add automark option --- request-cluster.ts | 16 ++++++++++++- sidebar/stolen-data.tsx | 50 +++++++++++++++++++++-------------------- stolen-data-entry.ts | 34 +++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 28 deletions(-) diff --git a/request-cluster.ts b/request-cluster.ts index 0b698c4..ea920d0 100644 --- a/request-cluster.ts +++ b/request-cluster.ts @@ -63,8 +63,16 @@ export class RequestCluster extends EventEmitter { return -1; } else if (indexA > indexB) { return 1; + } else if (entry1.value.length > entry2.value.length) { + return -1; + } else if (entry1.value.length < entry2.value.length) { + return 1; + } else if (entry1.isMarked && !entry2.isMarked) { + return -1; + } else if (!entry1.isMarked && entry2.isMarked) { + return 1; } else { - return entry1.value.length > entry2.value.length ? -1 : 1; + return 0; } } }) @@ -155,4 +163,10 @@ export class RequestCluster extends EventEmitter { exposesOrigin() { return this.requests.some((request) => request.exposesOrigin()); } + + autoMark() { + this.getRepresentativeStolenData().forEach((entry) => { + entry.autoMark(); + }); + } } diff --git a/sidebar/stolen-data.tsx b/sidebar/stolen-data.tsx index cc6d094..58c5048 100644 --- a/sidebar/stolen-data.tsx +++ b/sidebar/stolen-data.tsx @@ -23,9 +23,13 @@ export function StolenData({ if (!origin) { return
; } - const clusters = Object.values(getMemory().getClustersForOrigin(origin)).sort( - RequestCluster.sortCompare - ); + const clusters = Object.values(getMemory().getClustersForOrigin(origin)) + .sort(RequestCluster.sortCompare) + .filter((cluster) => !cookiesOnly || cluster.hasCookies()) + .filter( + (cluster) => + !cookiesOrOriginOnly || cluster.hasCookies() || cluster.exposesOrigin() + ); return (
{" "} @@ -53,6 +57,12 @@ export function StolenData({ Wyczyść pamięć + - {clusters - .filter((cluster) => !cookiesOnly || cluster.hasCookies()) - .filter( - (cluster) => - !cookiesOrOriginOnly || - cluster.hasCookies() || - cluster.exposesOrigin() - ) - .map((cluster) => { - return ( - - ); - })} + {clusters.map((cluster) => { + return ( + + ); + })}
); diff --git a/stolen-data-entry.ts b/stolen-data-entry.ts index fb3e1ea..c495b8a 100644 --- a/stolen-data-entry.ts +++ b/stolen-data-entry.ts @@ -21,6 +21,7 @@ export const Classifications = { }; const ID_PREVIEW_MAX_LENGTH = 20; +const MIN_COOKIE_LENGTH_FOR_AUTO_MARK = 15; const id = (function* id() { let i = 0; @@ -147,13 +148,19 @@ export class StolenDataEntry extends EventEmitter { } mark() { + const had_been_marked_before = this.marked; this.marked = true; - this.emit("change"); + if (!had_been_marked_before) { + this.emit("change"); + } } unmark() { + const had_been_marked_before = this.marked; this.marked = false; - this.emit("change"); + if (had_been_marked_before) { + this.emit("change"); + } } toggleMark() { @@ -171,6 +178,7 @@ export class StolenDataEntry extends EventEmitter { [ this.request.origin, this.request.originalURL, + this.request.originalPathname, getshorthost(this.request.origin), ].some((needle) => haystack.includes(needle)) ) @@ -215,6 +223,26 @@ export class StolenDataEntry extends EventEmitter { } exposesOrigin(): boolean { - return this.value.includes(getshorthost(this.request.origin)); + return ( + this.value.includes(getshorthost(this.request.origin)) || + this.value.includes(this.request.originalPathname) + ); + } + + autoMark() { + if ( + this.classification == "history" || + ((this.source === "cookie" || + this.name.toLowerCase().includes("id") || + this.name.toLowerCase().includes("cookie") || + this.name.toLowerCase().includes("ga") || + this.name.toLowerCase().includes("fb")) && + this.value.length > MIN_COOKIE_LENGTH_FOR_AUTO_MARK) + ) { + if (this.request.shorthost.includes("google") && this.name == "CONSENT") { + return; + } + this.mark(); + } } }