-
Notifications
You must be signed in to change notification settings - Fork 0
/
prevent_messenger_tracking.user.js
45 lines (44 loc) · 1.48 KB
/
prevent_messenger_tracking.user.js
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
// ==UserScript==
// @name Prevent Messenger from Tracking Links
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Rewrites links on messenger.com to go directly to the link instead of through l.messenger.com
// @author Raymond Chee
// @match https://www.messenger.com/t/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function rewriteHref(el) {
Array.from(el.attributes)
.filter(a => a.name.startsWith("data-lynx-"))
.forEach(a => el.removeAttribute(a.name));
if (el.href && el.href.startsWith("https://l.messenger.com/l.php")) {
el.href = new URL(el.href).searchParams.get("u");
}
}
var mutationObserver = new MutationObserver(
mutations => mutations.forEach(
m => {
var nodes;
switch (m.type) {
case "childList":
nodes = Array.from(m.addedNodes).filter(el => el.attributes);
break;
case "attributes":
nodes = [m.target];
break;
default:
return;
}
nodes.forEach(rewriteHref)
}
)
);
mutationObserver.observe(document.documentElement, {
childList: true,
subtree: true,
attribute: true,
attributeFilter: ["href", "data-lynx-hover"],
});
})();