blob: 416377803cf844e572cceaf65308e028e1524572 (
plain)
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
|
type ConditionalString = string | undefined;
let blocked: ConditionalString[] = [
"head > script:nth-child(34)",
"head > script:nth-child(43)"
];
let count = 0;
const observer = new MutationObserver(mutations => {
for (let i = 0; i < blocked.length; i++) {
if (blocked[i]) {
const element = document.querySelector(blocked[i]!) as HTMLElement | null;
if (element) {
if (element instanceof HTMLScriptElement) {
element.src = "";
} else if (element instanceof HTMLLinkElement && element.getAttribute("rel") === "stylesheet") {
element.href = "";
}
blocked[i] = undefined;
count++;
if (count >= blocked.length) {
observer.disconnect();
break;
}
}
}
}
});
observer.observe(document, {childList: true, subtree: true});
|