aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/optimize/home-page.ts
blob: 5ca4c2eb10609069c105be116c73745f4f771067 (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
29
30
const replace: (any[] | undefined)[] = [
	["#slider > img", { src: "" }],
	["#slider > img.nivo-main-image", { src: "" }]
];
let count = 0;

const observer = new MutationObserver(() => {
	for (let i = 0; i < replace.length; i++) {
		if (replace[i]) {
			const element = document.querySelector(replace[i]![0]) as HTMLElement | null;
			if (element) {
				const attributes = replace[i]![1];
				if (attributes.innerHTML) {
					element.innerHTML = attributes.innerHTML;
				}
				delete attributes.innerHTML;
				for (const attribute in attributes) {
					element.setAttribute(attribute, attributes[attribute]);
				}
				replace[i] = undefined;
				count++;
				if (count >= replace.length) {
					observer.disconnect();
					break;
				}
			}
		}
	}
});
observer.observe(document, {childList: true, subtree: true});