forked from rezafebran/wa-spam-js-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spamfix.js
77 lines (68 loc) · 2.31 KB
/
spamfix.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
var repeatingSpamFunction = null;
var message = '';
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
document.onclick = function(){
createSpamButton();
};
function createSpamButton () {
if(document.getElementById('spamButton') != null)
return;
var composeBar = getElementByXpath("//*[@id=\"main\"]/footer/div[1]");
if(composeBar == null)
return;
composeBar.oninput = function(){
editSpamButton();
};
var spamButton = document.createElement('button');
spamButton.setAttribute("id", "spamButton");
spamButton.innerHTML = 'SPAM';
spamButton.style.fontSize = '100%';
spamButton.style.padding = '0px 0px 10px 10px';
composeBar.append(spamButton);
editSpamButton();
}
function sendMessage () {
var evt = new Event('input', {
bubbles: true
});
var input = getElementByXpath("//*[@id=\"main\"]/footer/div[1]/div[2]/div/div[2]");
input.innerHTML = message;
input.dispatchEvent(evt);
getElementByXpath("//*[@id=\"main\"]/footer/div[1]/div[3]/button").click();
}
function doSpam(element) {
if(element.innerHTML == 'SPAM'){
var input = getElementByXpath("//*[@id=\"main\"]/footer/div[1]/div[2]/div/div[2]");
if(input.innerHTML == '' || input.innerHTML == null){
window.alert('Please Enter a Text to be spammed before using the spam button.');
return;
}
element.innerHTML = 'STOP';
message = input.innerHTML;
var interval = parseInt (prompt('Please enter spam-interval:', '500'));
repeatingSpamFunction = window.setInterval(function(){
sendMessage();
}, interval);
} else {
element.innerHTML = 'SPAM';
window.clearInterval(repeatingSpamFunction);
}
editSpamButton();
}
function editSpamButton(){
var spamButton = document.getElementById('spamButton');
var input = getElementByXpath("//*[@id=\"main\"]/footer/div[1]/div[2]/div/div[2]");
if(input.innerHTML == '' || input.innerHTML == null){
spamButton.style.cursor = 'not-allowed';
spamButton.style.color = '#D3D3D3';
spamButton.onclick = null;
} else {
spamButton.style.cursor = 'pointer';
spamButton.style.color = '#039be5';
spamButton.onclick = function(){
doSpam(this);
};
}
}