-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
30 lines (25 loc) · 837 Bytes
/
content.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
function cleanGoogleLink(link) {
const url = new URL(link.href);
if (url.hostname === 'www.google.com' && url.searchParams.has('url')) {
link.href = url.searchParams.get('url');
}
}
function cleanAllLinks() {
const links = document.querySelectorAll('a');
links.forEach(link => cleanGoogleLink(link));
}
// Clean links when the page content is fully loaded
document.addEventListener('DOMContentLoaded', cleanAllLinks);
// Observe the DOM for any changes and clean new or modified links
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList' || mutation.type === 'attributes') {
cleanAllLinks();
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
});