-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
44 lines (37 loc) · 1.1 KB
/
content.js
File metadata and controls
44 lines (37 loc) · 1.1 KB
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
36
37
38
39
40
41
42
43
44
const abusiveWords = [
"fuck","fucking","fucker","shit","bullshit","asshole","bastard",
"bitch","slut","whore","dick","cock","pussy","motherfucker",
"mf","jerk","retard","moron","idiot","stupid","dumb",
"bloody","damn","sonofabitch","boobs",
"madarchod","bhenchod","behenchod","bhosdike","bhosdiwala",
"chutiya","lund","loda","lauda","gaand","gandu",
"harami","kameena","kamina","randi","saala","sala",
"kutta","kamine","haraami",
"fuker","fuking"
];
const regex = new RegExp(`\\b(${abusiveWords.join("|")})\\b`, "gi");
function censorText(node) {
if (node.nodeType === Node.TEXT_NODE) {
node.textContent = node.textContent.replace(regex, "****");
}
}
function walkDOM(element) {
element.childNodes.forEach(child => {
censorText(child);
walkDOM(child);
});
}
walkDOM(document.body);
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
walkDOM(node);
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});