-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_whatsapp.js
51 lines (40 loc) · 1.41 KB
/
web_whatsapp.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
let dataTransfer = new DataTransfer();
let box = document.querySelectorAll("[role='textbox']")[1];
if (!box) {
alert("No chat open. Make sure you have opened the chat you want to spam.");
throw new Error("No chat open. Make sure you have opened the chat you want to spam.");
}
let count = parseInt(prompt("Enter number of messages (between 1 and 100):", "10"), 10);
if (isNaN(count) || count < 1 || count > 100) {
alert("Invalid input! Enter a NUMBER between 1 and 100.");
throw new Error("Invalid input for message count.");
}
let message = prompt("Enter the MESSAGE to spam:", "Hello from spammer...");
if (!message) {
alert("Message cannot be empty. Re-run the script to try again.");
throw new Error("Empty message input.");
}
dataTransfer.setData("text/plain", message);
function findSendButton() {
return document.querySelector("span[data-icon='send']")?.closest("button");
}
(async () => {
console.clear();
for (let i = 0; i < count; i++) {
box.focus();
box.dispatchEvent(new ClipboardEvent("paste", {
clipboardData: dataTransfer,
bubbles: true,
cancelable: true,
}));
await new Promise((resolve) => setTimeout(resolve, 100));
let sendButton = findSendButton();
if (sendButton) {
sendButton.click();
console.log(`"${message}" sent -> ${i + 1} times`);
} else {
console.warn("Send button not found. Stopping script.");
break;
}
}
})();