-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-cals.js
35 lines (32 loc) · 1.05 KB
/
remove-cals.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
31
32
33
34
35
const removeCals = (parent = document, elementType = "p") => {
const regex = /^[a-zA-Z .]*[0-9]* kcal[.]?[a-zA-Z .]*$/gi;
const elements =
typeof parent?.querySelectorAll === "function"
? parent.querySelectorAll(elementType)
: [];
const calorieElements = Array.from(elements).filter((element) =>
regex.test(element.innerText)
);
calorieElements.forEach((element) => {
element.style.background = "white";
element.style.color = "white";
});
};
removeCals(document, "span");
removeCals(document, "p");
removeCals(document, "div");
const calorieObserver = new MutationObserver(function (mutationRecord) {
mutationRecord.forEach((mutation) => {
mutation?.addedNodes &&
Array.from(mutation?.addedNodes).length > 0 &&
Array.from(mutation.addedNodes).forEach((element) => {
setTimeout(removeCals(element, "span"), 0);
setTimeout(removeCals(element, "p"), 0);
setTimeout(removeCals(element, "div"), 0);
});
});
});
calorieObserver.observe(document.body, {
subtree: true,
childList: true,
});