-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
99 lines (93 loc) · 3.94 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function removeFraudes(frauds, userid) {
const tweetsContainer = document.getElementById("react-root");
const observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach((mutation) => {
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((addedNode) => {
let tweets = addedNode.querySelectorAll('a[href*="/status/"]');
tweets.forEach(function(tweet){
if(tweet.href && !tweet.href.includes('/i/status') && (tweet.href.match(/\//g)||[]).length <= 5){
let parent = tweet.parentElement
let found = false
while (!found) {
if(parent.getAttribute("data-testid")=="cellInnerDiv"){
if(!parent.hasAttribute("was-tested")){
if(frauds.filter(x => x.tweet_id === tweet.href.split('/')[5]).length > 0){
parent.style.display = "none"
}else{
parent.setAttribute("was-tested", "true")
let timeframe = parent.getElementsByTagName('time')[0].getAttribute("datetime")
let divToModify = parent.querySelectorAll('[data-testid=User-Name]')[0].children[1].children[0]
let toBeAdded = divToModify.children[1].cloneNode(true)
let toBeAdded2 = divToModify.children[1].cloneNode(true)
divToModify.appendChild(toBeAdded)
let variables = {
parent: parent,
timeframe: timeframe,
userid: userid,
tweetid: tweet.href.split('/')[5]
}
toBeAdded2.children[0].innerHTML = "tap in ?"
toBeAdded2.addEventListener('click', function(event){
event.preventDefault()
addTapIn(variables)
});
divToModify.appendChild(toBeAdded2)
}
}
found=true
}
parent = parent.parentElement;
}
}
})
});
}
});
});
var config = {
attributes: true,
childList: true,
characterData: true,
subtree: true,
};
observer.observe(tweetsContainer, config);
}
function addTapIn(variables){
fetch("https://feurtracker.fr/api/no_tap_in",
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({user_id: variables.userid, tweet_id: variables.tweetid, tweeted_at: variables.timeframe})
})
variables.parent.style.display = "none"
}
function getRandomToken() {
var randomPool = new Uint8Array(32);
crypto.getRandomValues(randomPool);
var hex = '';
for (var i = 0; i < randomPool.length; ++i) {
hex += randomPool[i].toString(16);
}
return hex;
}
chrome.storage.sync.get('userid', function(items) {
var userid = items.userid;
if (userid) {
useToken(userid);
} else {
userid = getRandomToken();
chrome.storage.sync.set({userid: userid}, function() {
useToken(userid);
});
}
function useToken(userid) {
fetch("https://feurtracker.fr/api/no_tap_in?user_id=" + userid).then(res =>
res.json()).then(d => {
removeFraudes(d, userid);
})
}
});