-
Notifications
You must be signed in to change notification settings - Fork 0
/
tazedirek.js
executable file
·45 lines (36 loc) · 1.15 KB
/
tazedirek.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
var BLOCKED_WORDS = ["Tazedirekt", "tazedirekt" ];
// Start the loop
loop();
window.setInterval(loop, 2000);
function loop() {
var userPosts = document.getElementsByClassName("userContent");
for (var i = 0; i < userPosts.length; i++) {
if (userPosts[i] !== undefined && isTazadirekt(userPosts[i])) {
var postContainer = userPosts[i].parentNode.parentNode.parentNode;
replacePostWithCat(postContainer)
}
}
}
// Replace with some cat gifs
function replacePostWithCat(post) {
//to invalidate cache
var randomId = Math.random();
post.innerHTML = "<a href=\"http://thecatapi.com\"><img style=\"width:100%;\" src=\"http://edgecats.net/?" + randomId+"\"></a>"
}
// Returns true if the post is sensed as a spoiler.
function isTazadirekt(post) {
var postString = getHTMLString(post);
for (var i = 0; i < BLOCKED_WORDS.length; i++) {
if (postString.indexOf(BLOCKED_WORDS[i]) > -1) {
return true;
}
}
return false;
}
// Get string representation of node.
function getHTMLString(node) {
node = node.cloneNode(true);
var tmp = document.createElement("div");
tmp.appendChild(node);
return tmp.innerHTML.toLowerCase();
}