forked from Matt-Fontes/SendScriptWhatsApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
26 lines (19 loc) · 1022 Bytes
/
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
let COPYPASTA = prompt("Insira o texto que quer enviar:");
async function enviarScript(scriptText){
const lines = scriptText.split(/[\n\t]+/).map(line => line.trim()).filter(line => line);
main = document.querySelector("#main"),
textarea = main.querySelector(`div[contenteditable="true"]`)
if(!textarea) throw new Error("Não há uma conversa aberta")
for(const line of lines){
console.log(line)
textarea.focus();
document.execCommand('insertText', false, line);
textarea.dispatchEvent(new Event('change', {bubbles: true}));
setTimeout(() => {
(main.querySelector(`[data-testid="send"]`) || main.querySelector(`[data-icon="send"]`)).click();
}, 50);
if(lines.indexOf(line) !== lines.length - 1) await new Promise(resolve => setTimeout(resolve, 250));
}
return lines.length;
}
enviarScript(COPYPASTA).then(e => console.log(`Código finalizado, ${e} mensagens enviadas`)).catch(console.error)