-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolice.js
54 lines (46 loc) · 1.63 KB
/
Police.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Function to replace specified words in text content
function replaceWords(node) {
const replacements = {
"skibidi": "***",
" rizz ": "***",
"fanum tax": "***",
"skibidi toilet": "***",
"gyatt": "***",
"Sigma": "***",
"Rizzler": "***",
"In Ohio": "***",
" Edge ": "***",
};
// Regular expression to match the specified words
const regex = new RegExp(Object.keys(replacements).join("|"), "gi");
// Recursive function to traverse the DOM tree and replace text content
function replaceText(node) {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(regex, match => replacements[match.toLowerCase()]);
} else if (node.nodeType === Node.ELEMENT_NODE) {
for (const childNode of node.childNodes) {
replaceText(childNode);
}
}
}
replaceText(node);
}
// Observer configuration to observe changes in the DOM
const observerConfig = {
childList: true,
subtree: true
};
// Function to handle mutations in the DOM
function handleMutations(mutationsList, observer) {
for(const mutation of mutationsList) {
for(const addedNode of mutation.addedNodes) {
replaceWords(addedNode);
}
}
}
// Create a MutationObserver instance
const observer = new MutationObserver(handleMutations);
// Start observing the document body for changes
observer.observe(document.body, observerConfig);
// Initial call to replace words in existing content
replaceWords(document.body);