Remove more tracking params

This commit is contained in:
the-djmaze 2022-10-03 16:11:44 +02:00
parent da451ed369
commit aa357af4c5

View file

@ -23,28 +23,31 @@ const
tel = /(^|\s|\n|\/?>)(tel:(\+[0-9().-]+|[0-9*#().-]+(;phone-context=\+[0-9+().-]+)?))/g, tel = /(^|\s|\n|\/?>)(tel:(\+[0-9().-]+|[0-9*#().-]+(;phone-context=\+[0-9+().-]+)?))/g,
// Strip tracking // Strip tracking
stripParams = /^(utm_|ec_|fbclid|mc_eid|mkt_tok|_hsenc|vero_id|oly_enc_id|oly_anon_id|__s)/i,
urlGetParam = (url, name) => new URL(url).searchParams.get(name) || url, urlGetParam = (url, name) => new URL(url).searchParams.get(name) || url,
base64Url = data => atob(data.replace(/_/g,'/').replace(/-/g,'+')), base64Url = data => atob(data.replace(/_/g,'/').replace(/-/g,'+')),
stripTracking = text => text stripTracking = url => {
.replace(/tracking\.(printabout\.nl[^?]+)\?.*/i, (...m) => m[1]) url = url
.replace(/^.+awstrack\.me\/.+(https:%2F%2F[^/]+)/i, (...m) => decodeURIComponent(m[1])) .replace(/tracking\.(printabout\.nl[^?]+)\?.*/i, (...m) => m[1])
.replace(/^.+(www\.google|safelinks\.protection\.outlook\.com).+$/i, () => urlGetParam(text, 'url')) .replace(/^.+awstrack\.me\/.+(https:%2F%2F[^/]+)/i, (...m) => decodeURIComponent(m[1]))
.replace(/^.+go\.dhlparcel\.nl.+\/([^/]+)$/i, (...m) => base64Url(m[1])) .replace(/^.+(www\.google|safelinks\.protection\.outlook\.com).+$/i, () => urlGetParam(url, 'url'))
// Mandrill .replace(/^.+go\.dhlparcel\.nl.+\/([^/]+)$/i, (...m) => base64Url(m[1]))
.replace(/^.+\/track\/click\/.+\?p=.+$/i, () => { // Mandrill
let d = urlGetParam(text, 'p'); .replace(/^.+\/track\/click\/.+\?p=.+$/i, () => {
try { let d = urlGetParam(url, 'p');
d = JSON.parse(base64Url(d)); try {
if (d?.p) { d = JSON.parse(base64Url(d));
d = JSON.parse(d.p); if (d?.p) {
d = JSON.parse(d.p);
}
} catch (e) {
console.error(e);
} }
} catch (e) { return d?.url || url;
console.error(e); });
} url = new URL(url);
return d?.url || text; let s = url.searchParams;
}) [...s.keys()].forEach(key => stripParams.test(key) && s.delete(key));
.replace(/(\?|&(amp;)?)utm_[a-z]+=[^&?#]*/gi, '$1') // Urchin Tracking Module
.replace(/(\?|&(amp;)?)ec_[a-z]+=[^&?#]*/gi, '$1') // Sitecore
/** TODO: implement other url strippers like from /** TODO: implement other url strippers like from
* https://www.bleepingcomputer.com/news/security/new-firefox-privacy-feature-strips-urls-of-tracking-parameters/ * https://www.bleepingcomputer.com/news/security/new-firefox-privacy-feature-strips-urls-of-tracking-parameters/
* https://github.com/newhouse/url-tracking-stripper * https://github.com/newhouse/url-tracking-stripper
@ -52,7 +55,8 @@ const
* https://maxchadwick.xyz/tracking-query-params-registry/ * https://maxchadwick.xyz/tracking-query-params-registry/
* https://github.com/M66B/FairEmail/blob/master/app/src/main/java/eu/faircode/email/UriHelper.java * https://github.com/M66B/FairEmail/blob/master/app/src/main/java/eu/faircode/email/UriHelper.java
*/ */
; return url.toString();
};
export const export const
@ -168,11 +172,6 @@ export const
oElement.remove(); oElement.remove();
return; return;
} }
// if (['CENTER','FORM'].includes(name)) {
if ('FORM' === name || 'O:P' === name || (nonEmptyTags.includes(name) && ('' == oElement.textContent.trim()))) {
('A' !== name || !oElement.querySelector('IMG')) && replaceWithChildren(oElement);
return;
}
/* /*
// Idea to allow CSS // Idea to allow CSS
if ('STYLE' === name) { if ('STYLE' === name) {
@ -249,6 +248,12 @@ export const
setAttribute('tabindex', '-1'); setAttribute('tabindex', '-1');
} }
// if (['CENTER','FORM'].includes(name)) {
if ('FORM' === name || 'O:P' === name || (nonEmptyTags.includes(name) && ('' == oElement.textContent.trim()))) {
('A' !== name || !oElement.querySelector('IMG')) && replaceWithChildren(oElement);
return;
}
// SVG xlink:href // SVG xlink:href
/* /*
if (hasAttribute('xlink:href')) { if (hasAttribute('xlink:href')) {