I tried applying this using ChatGPT, but it didn't work for me. Can you tell me where to put this code to make my code work?
// Функция для эмуляции нажатия мыши внутри элемента <canvas data-sentry-element="Stage"> function simulateMouseClickInCanvas() { const canvas = document.querySelector('canvas[data-sentry-element="Stage"]'); if (!canvas) { console.error("Элемент <canvas> не найден."); return; } const rect = canvas.getBoundingClientRect(); // Выбираем случайные координаты внутри элемента <canvas> const randomX = Math.random() * rect.width + rect.left; const randomY = Math.random() * rect.height + rect.top; // Создаём события мыши const mouseDownEvent = new MouseEvent("mousedown", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const mouseUpEvent = new MouseEvent("mouseup", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); const clickEvent = new MouseEvent("click", { bubbles: true, cancelable: true, clientX: randomX, clientY: randomY, }); // Эмулируем события canvas.dispatchEvent(mouseDownEvent); canvas.dispatchEvent(mouseUpEvent); canvas.dispatchEvent(clickEvent); } // Функция для выполнения кликов с рандомной задержкой function performRandomClicksInCanvas(maxClicks) { let clicksCount = 0; function clickWithRandomDelay() { if (clicksCount >= maxClicks) { console.log("Все клики выполнены"); return; } const delay = Math.random() * (2000 - 100) + 100; // Рандомная задержка от 0.1 до 2 секунд setTimeout(() => { simulateMouseClickInCanvas(); clicksCount++; console.log(`Клик ${clicksCount} выполнен (задержка: ${Math.round(delay)} мс)`); clickWithRandomDelay(); // Рекурсивный вызов для следующего клика }, delay); } clickWithRandomDelay(); } // Запуск выполнения 10 кликов performRandomClicksInCanvas(10);How to store execute javascript result in bas variable ?
-
I tried this code but bas variable didnt stored the result, i have checked this code by pasting it in console and the result is getting printed when entered on chrome console. But in bas the result is not getting stored in bas variable when using execute javascript action.
Link where i execute javascript code : https://www.hindigeetmala.net/singer/lata_mangeshkar.php
Code :var links = document.querySelectorAll("a"); var results = []; links.forEach(link => { if(link.href.includes("/song")){ results.push(link.href); } }) if(results.length > 0){ var uniqueSet = new Set(results); var resultsUnique = [...uniqueSet]; VAR_BASNEWVAR = resultsUnique; return resultsUnique; }How can i store the result in bas variable ?
-
@niceusername said in How to store execute javascript result in bas variable ?:
How can i store the result in bas variable ?
No way
-
@Fox said in How to store execute javascript result in bas variable ?:
@niceusername said in How to store execute javascript result in bas variable ?:
How can i store the result in bas variable ?
No way
Hey, I got the result in BAS variable but the result was an array but when it is passed to BAS variable it converts to string. I want to use that BAS variable as an array so i can loop through it, how can i achieve that please ?
-
@niceusername said in How to store execute javascript result in bas variable ?:
@Fox said in How to store execute javascript result in bas variable ?:
@niceusername said in How to store execute javascript result in bas variable ?:
How can i store the result in bas variable ?
No way
Hey, I got the result in BAS variable but the result was an array but when it is passed to BAS variable it converts to string. I want to use that BAS variable as an array so i can loop through it, how can i achieve that please ?
The result of executing the action will always be a string, use a delimiter, then the string to parse into an array