From 8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 21:47:39 +0200 Subject: Adding upstream version 2020.10.7. Signed-off-by: Daniel Baumann --- src/js/firstparties/google-static.js | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/js/firstparties/google-static.js (limited to 'src/js/firstparties/google-static.js') 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); +}); -- cgit v1.2.3