Skip to content

error in send function #105

@DanielPHM24

Description

@DanielPHM24

async function enviarScript(scriptText){

I saw a mistake insend functions, because whatsapp made an update, I solved by myself here is the solutions:

async function enviarScript(scriptText) {
const lines = scriptText
.split(/[\n\t]+/)
.map(line => line.trim())
.filter(line => line);

const main = document.querySelector("#main");
const textarea = main?.querySelector(`div[contenteditable="true"]`);

if (!textarea) throw new Error("No hay una conversación abierta");

for (const line of lines) {
	console.log("Enviando línea:", line);

	// Limpiar el textarea antes de escribir
	textarea.focus();
	document.execCommand('selectAll', false, null);
	document.execCommand('delete', false, null);

	// Insertar texto
	document.execCommand('insertText', false, line);
	textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));

	// Esperar un poco antes de enviar
	await new Promise(resolve => setTimeout(resolve, 100));

	// Buscar el botón con aria-label="Send" y hacer clic
	const sendButton = document.querySelector('button[aria-label="Send"]');
	if (sendButton) {
		sendButton.click();
	} else {
		console.warn("Botón de enviar no encontrado");
	}

	// Esperar antes de pasar a la siguiente línea (ajusta si se salta mensajes)
	await new Promise(resolve => setTimeout(resolve, 500));
}

return lines.length;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions