From 14413ed86ffa91abc3f0d23f179c1bcd1b52c089 Mon Sep 17 00:00:00 2001 From: Thallys_San Date: Thu, 19 Jun 2025 01:31:01 -0300 Subject: [PATCH] Update shrekSendScript.js --- shrekSendScript.js | 58 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/shrekSendScript.js b/shrekSendScript.js index ff005de..8344294 100644 --- a/shrekSendScript.js +++ b/shrekSendScript.js @@ -1,28 +1,46 @@ -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) - +async function sendMessages(scriptText) { + const lines = scriptText + .split(/[\n\t]+/) + .map(line => line.trim()) + .filter(line => line); + + const main = document.querySelector("#main"); + if (!main) throw new Error("Main conversation element not found"); + + const textarea = main.querySelector(`div[contenteditable="true"]`); + if (!textarea) throw new Error("No open conversation found"); + + for (const line of lines) { + console.log("Sending:", line); + textarea.focus(); + document.execCommand('selectAll', false, null); + document.execCommand('delete', false, null); document.execCommand('insertText', false, line); - textarea.dispatchEvent(new Event('change', {bubbles: true})); - - setTimeout(() => { - (main.querySelector(`[data-testid="send"]`) || main.querySelector(`[data-icon="send"]`)).click(); - }, 100); - - if(lines.indexOf(line) !== lines.length - 1) await new Promise(resolve => setTimeout(resolve, 250)); + textarea.dispatchEvent(new Event('input', { bubbles: true })); + + // Wait for send button to be ready + await new Promise(resolve => setTimeout(resolve, 300)); + + const sendButton = + main.querySelector('button[aria-label="Send"]') || + main.querySelector('span[data-icon="wds-ic-send-filled"]')?.closest("button"); + + if (!sendButton) { + console.warn("⚠️ Send button not found. Skipping this line."); + continue; + } + + sendButton.click(); + + // Wait 100ms between messages + if (lines.indexOf(line) !== lines.length - 1) + await new Promise(resolve => setTimeout(resolve, 100)); } - + return lines.length; } - -enviarScript(` +sendMessages(` SHREK Written by