-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanilla-js.html
38 lines (34 loc) · 1.09 KB
/
vanilla-js.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hide Words</title>
</head>
<body>
<p>This is a commercial website.</p>
<script>
document.addEventListener('DOMContentLoaded', function() {
function hideWords(words) {
var textNodes = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
false
);
var node;
while (node = textNodes.nextNode()) {
var text = node.nodeValue;
for (var i = 0; i < words.length; i++) {
var regex = new RegExp('\\b' + words[i] + '\\b', 'gi');
text = text.replace(regex, '');
}
node.nodeValue = text;
}
}
var wordsToHide = ['commercial'];
hideWords(wordsToHide);
});
</script>
</body>
</html>