-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendScript.js
More file actions
57 lines (44 loc) · 1.59 KB
/
SendScript.js
File metadata and controls
57 lines (44 loc) · 1.59 KB
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
async function enviarScript(scriptText) {
const lines = scriptText
.split(/[\n\t]+/)
.map(line => line.trim())
.filter(line => line);
const main = document.querySelector("#main");
if (!main) throw new Error("❌ Nenhuma conversa aberta!");
const textarea = main.querySelector('div[contenteditable="true"]');
if (!textarea) throw new Error("❌ Campo de mensagem não encontrado!");
for (const [index, line] of lines.entries()) {
console.log(`➡️ Enviando: ${line}`);
// Escreve a mensagem
textarea.focus();
document.execCommand("insertText", false, line);
textarea.dispatchEvent(new Event("input", { bubbles: true }));
await new Promise(resolve => setTimeout(resolve, 300));
// Novo seletor do botão de enviar
let sendButton = main.querySelector('button[aria-label="Enviar"]');
if (!sendButton) {
console.error("⚠️ Botão de enviar não encontrado, tentando novamente...");
await new Promise(resolve => setTimeout(resolve, 500));
sendButton = main.querySelector('button[aria-label="Enviar"]');
}
if (sendButton) {
sendButton.click();
console.log(`✅ Mensagem enviada (${index + 1}/${lines.length})`);
} else {
console.error("❌ Não consegui encontrar o botão de enviar!");
}
// Intervalo entre mensagens
if (index < lines.length - 1) {
await new Promise(resolve => setTimeout(resolve, 700));
}
}
return lines.length;
}
enviarScript(`
Adicionar
o
Texto
Aqui
`).then(qtd =>
console.log(`🎉 Código finalizado, ${qtd} mensagens enviadas!`)
).catch(console.error);