-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 931 Bytes
/
index.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
console.log("Laatuhesari käynnistetty");
const forbiddenKeywords = ["korona", "trump"];
const elementContainsForbiddenKey = (node) =>
forbiddenKeywords.some(word => (node.textContent || "").toLowerCase().indexOf(word) !== -1)
const removeArticle = (domNode) => {
if (domNode.tagName === "ARTICLE") {
domNode.remove();
} else if (domNode.parentNode) {
removeArticle(domNode.parentNode);
}
};
const checkForForbiddenKeywords = (domNode) => {
if (domNode && elementContainsForbiddenKey(domNode)) {
removeArticle(domNode);
}
if (domNode && domNode.childNodes) {
domNode.childNodes.forEach((x) => {
checkForForbiddenKeywords(x);
});
}
};
document.addEventListener("DOMNodeInserted", (event) => {
if (elementContainsForbiddenKey(event.target)) {
checkForForbiddenKeywords(event.target);
}
});
checkForForbiddenKeywords(document);