-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
76 lines (69 loc) · 2.11 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
waitForCommentBoxToAppear='';
var clickEvent = new MouseEvent("click", {
"view": window,
"bubbles": true,
"cancelable": false
});
post="";
baitContent="";
$(document).ready(function(){
addClickBaitButton();
});
function addClickBaitButton()
{
try {
post=$('._5jmm').not('.handelled')[0];
$(post).addClass('handelled');
clickbaitlinkdiv=post.getElementsByClassName('_6m3');
if(clickbaitlinkdiv.length>0){
clickbaitlinkdiv=clickbaitlinkdiv[0];
postbuttons=post.getElementsByClassName('_42nr')[0];
clickbait=document.createElement('span');
clickbait.className='clickbait';
clickbait.innerHTML='<strong>Destroy Clickbait</strong>';
clickbait.addEventListener('click',function(){destroyBait(this);})
postbuttons.appendChild(clickbait);
}
} catch(e){}
setTimeout(function(){addClickBaitButton()},1000);
}
function destroyBait(clickbaitbutton) {
clearInterval(waitForCommentBoxToAppear);
commentSibling=clickbaitbutton.parentElement.children[1].children[0];
commentSibling.dispatchEvent(clickEvent);
clickbaitbutton.scrollIntoView();
while(clickbaitbutton.getElementsByClassName('_6m3').length==0)
{
clickbaitbutton=clickbaitbutton.parentElement;
}
post=clickbaitbutton.getElementsByClassName('_6m3')[0];
postanchor=post.getElementsByTagName('a')[0];
postlink=postanchor.getAttribute('onmouseover');
postlink=postlink.split('"');
postlink=postlink[1];
postlink=String(''+postlink);
postlink=postlink.split('\\').join('');
baitContent="";
chrome.runtime.sendMessage(postlink);
windowInterval=setInterval(function(){checkOpenState()},1000);
}
function checkOpenState() {
if(baitContent!="")
{
console.log('Window Closed');
clearInterval(windowInterval);
waitForCommentBoxToAppear=setInterval(function(){
commentField=$(':focus');
if(commentField.length!=0) {
document.execCommand('paste');
clearInterval(waitForCommentBoxToAppear);
}
else {
console.log('waiting');
}
},100);
}
else {
console.log('Window Still Open');
}
}