-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
46 lines (39 loc) · 1.54 KB
/
content.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
if (document.readyState === 'complete' || document.readyState === 'interactive') {
replaceDT();
} else {
document.addEventListener('DOMContentLoaded', replaceDT);
}
function replaceDT() {
chrome.storage.sync.get({
wordDT: 'Not My President',
replaceDT: true
}, function(options) {
if (options.replaceDT) {
htmlReplace(options.wordDT);
window.setInterval(function() {
htmlReplace(options.wordDT);
}, 5000);
}
});
}
function htmlReplace(replace) {
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
for (var j = 0; j < element.childNodes.length; j++) {
var node = element.childNodes[j];
if (node.nodeType === 3) {
var text = node.nodeValue;
var replacedText = text.replace(/donald\sjohn\strump/gi, replace);
replacedText = replacedText.replace(/donald\sj[.]\strump/gi, replace);
replacedText = replacedText.replace(/donald\sj\strump/gi, replace);
replacedText = replacedText.replace(/donald\strump/gi, replace);
replacedText = replacedText.replace(/Trump/g, replace);
replacedText = replacedText.replace(/president\strump/gi, 'president ' + replace);
if (replacedText !== text) {
element.replaceChild(document.createTextNode(replacedText), node);
}
}
}
}
}