diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:47:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:47:39 +0000 |
commit | 8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 (patch) | |
tree | 5fd46925c6b4a881c9208772ed8e5cc0588bc164 /src/js/firstparties/google-static.js | |
parent | Initial commit. (diff) | |
download | privacybadger-upstream.tar.xz privacybadger-upstream.zip |
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/js/firstparties/google-static.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/js/firstparties/google-static.js b/src/js/firstparties/google-static.js new file mode 100644 index 0000000..cf73004 --- /dev/null +++ b/src/js/firstparties/google-static.js @@ -0,0 +1,41 @@ +let g_wrapped_link = "a[href^='https://www.google.com/url?']"; + +// Unwrap a Hangouts tracking link +function unwrapLink(a) { + let href = new URL(a.href).searchParams.get('q'); + if (!window.isURL(href)) { + return; + } + + // remove all attributes except for target, class, style and aria-* + // attributes. This should prevent the script from breaking styles and + // features for people with disabilities. + for (let i = a.attributes.length - 1; i >= 0; --i) { + const attr = a.attributes[i]; + if (attr.name !== 'target' && attr.name !== 'class' && + attr.name !== 'style' && !attr.name.startsWith('aria-')) { + a.removeAttribute(attr.name); + } + } + + a.rel = "noreferrer"; + a.href = href; +} + +// Scan the page for all wrapped links +function unwrapAll() { + document.querySelectorAll(g_wrapped_link).forEach((a) => { + unwrapLink(a); + }); +} + +// TODO race condition; fix waiting on https://crbug.com/478183 +chrome.runtime.sendMessage({ + type: "checkEnabled" +}, function (enabled) { + if (!enabled) { + return; + } + unwrapAll(); + setInterval(unwrapAll, 2000); +}); |