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,16 +23,18 @@ 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 => {
url = url
.replace(/tracking\.(printabout\.nl[^?]+)\?.*/i, (...m) => m[1]) .replace(/tracking\.(printabout\.nl[^?]+)\?.*/i, (...m) => m[1])
.replace(/^.+awstrack\.me\/.+(https:%2F%2F[^/]+)/i, (...m) => decodeURIComponent(m[1])) .replace(/^.+awstrack\.me\/.+(https:%2F%2F[^/]+)/i, (...m) => decodeURIComponent(m[1]))
.replace(/^.+(www\.google|safelinks\.protection\.outlook\.com).+$/i, () => urlGetParam(text, 'url')) .replace(/^.+(www\.google|safelinks\.protection\.outlook\.com).+$/i, () => urlGetParam(url, 'url'))
.replace(/^.+go\.dhlparcel\.nl.+\/([^/]+)$/i, (...m) => base64Url(m[1])) .replace(/^.+go\.dhlparcel\.nl.+\/([^/]+)$/i, (...m) => base64Url(m[1]))
// Mandrill // Mandrill
.replace(/^.+\/track\/click\/.+\?p=.+$/i, () => { .replace(/^.+\/track\/click\/.+\?p=.+$/i, () => {
let d = urlGetParam(text, 'p'); let d = urlGetParam(url, 'p');
try { try {
d = JSON.parse(base64Url(d)); d = JSON.parse(base64Url(d));
if (d?.p) { if (d?.p) {
@ -41,10 +43,11 @@ const
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
return d?.url || text; return d?.url || url;
}) });
.replace(/(\?|&(amp;)?)utm_[a-z]+=[^&?#]*/gi, '$1') // Urchin Tracking Module url = new URL(url);
.replace(/(\?|&(amp;)?)ec_[a-z]+=[^&?#]*/gi, '$1') // Sitecore let s = url.searchParams;
[...s.keys()].forEach(key => stripParams.test(key) && s.delete(key));
/** 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')) {