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
| var sleep = delay => new Promise(resolve => setTimeout(resolve, delay));
var composeClick = function x(btn) { var rect = btn.getBoundingClientRect(); var x = rect.left + rect.width * Math.random(); var y = rect.top + rect.height * Math.random(); const mousedown = new MouseEvent("mousedown", { screenX: x + window.screen.availLeft, screenY: y + window.screen.availTop, clientX: x, clientY: y, }); const click = new MouseEvent("click", { screenX: x + window.screen.availLeft, screenY: y + window.screen.availTop, clientX: x, clientY: y, }); const mouseup = new MouseEvent("mouseup", { screenX: x + window.screen.availLeft, screenY: y + window.screen.availTop, clientX: x, clientY: y, }); btn.dispatchEvent(mousedown); return sleep(150 + Math.random() * 30) .then(() => { btn.dispatchEvent(click); return sleep(30 + Math.random() * 30); }).then(() => { btn.dispatchEvent(mouseup); }); }
function task() { var btn = document.querySelector(".continueButton"); if (!btn) { alert("Finish"); return; } composeClick(btn) .then(() => { return sleep(50 + Math.random() * 600); }) .then(() => { task(); }); } task();
|