-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimprove-privacy.user.js
More file actions
99 lines (83 loc) · 2.97 KB
/
improve-privacy.user.js
File metadata and controls
99 lines (83 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ==UserScript==
// @name Improve Privacy
// @version 0.30
// @downloadURL https://userscripts.codonaft.com/improve-privacy.user.js
// @require https://userscripts.codonaft.com/utils.js
// ==/UserScript==
// TODO: https://github.com/f321x/nostr-tracking-token-remover/tree/main/nostr_tracking_token_remover/rulesets
(_ => {
'use strict';
const PROXY = pickRandom(['imgproxy.nostu.be/insecure/f:webp/rs:fill::360/plain/', 'imgproxy.nosotros.app/_/feed_img/plain/', 'wsrv.nl/?url=']);
const imageURL = url => {
if (!PROXY) return url;
return `https://${PROXY}${encodeURIComponent(url)}`;
};
const h = window.location.hostname;
const hiddenNodes = 'div[class^="langGeoPickerIcons"] use, div[role="contentinfo"], div#gws-output-pages-elements-homepage_additional_languages__als, div#voice-search-button, span.preference-hint, span.style-scope.ytd-topbar-logo-renderer';
const links = '[href]';
const cleanup = node => {
try {
if (node.data?.clickTrackingParams?.length > 0) {
node.data.clickTrackingParams = '';
}
} catch (e) {
err(e, node);
}
try {
if (!node.matches(links)) return true;
let href = node.href;
if (!href?.startsWith) return true;
if (href.startsWith('/')) {
href = `${window.location.origin}${href}`;
}
const url = new URL(href);
Array.from(url.searchParams.keys())
.filter(k => k.startsWith('utm_') || k === 'notification_referrer_id' || k === 'redir_token')
.forEach(k => url.searchParams.delete(k));
maybeUpdateUrl(node, url, href);
if (h === 'tagpacker.com' && !node.closest?.('ul.nav')) {
node.addEventListener('click', _ => {
if (!event.isTrusted) return;
event.preventDefault();
event.stopImmediatePropagation();
window.location = href;
}, true);
return;
}
const youtube = href.startsWith('https://www.youtube.com/watch?') || href.startsWith('https://youtu.be/') || href.startsWith('https://m.youtube.com/');
const maps = href.startsWith('https://maps.app.goo.gl/');
if (!youtube && !maps) return true;
Array.from(url.searchParams.keys())
.filter(k => maps || !['index', 'list', 't', 'v'].includes(k))
.forEach(k => url.searchParams.delete(k));
maybeUpdateUrl(node, url, href);
} catch (e) {
err(e, node);
}
return true;
};
const maybeUpdateUrl = (node, url, href) => {
const newHref = url.toString();
if (newHref !== href) {
node.href = newHref;
if (node.textContent?.trim() === href) {
node.innerHTML = newHref;
}
}
};
subscribeOnChanges(document.body, `img, ${links}, ${hiddenNodes}`, (node, _observer) => {
try {
if (node.matches('img[href^="https://i.ytimg.com/"]')) {
node.href = imageURL(node.href);
return false;
}
if (['youtube.com', 'youtu.be', 'google.com', 'xhamster.com'].find(i => h.endsWith(i)) && node.matches(hiddenNodes)) {
node.style.display = 'none';
return false;
}
} catch (e) {
err(e, node);
}
return cleanup(node);
});
})();