4 ms·
Running it async will prevent the main screen from lagging: (async () => { const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); for
by ipsum2 2y ago
Running it async will prevent the main screen from lagging:
(async () => {
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
for (let i = 0; i < 10000; i++) {
document.getElementsByClassName('main-btn')[0].click();
await delay(5); // 5 ms sleep
}
})();
- i8i76876 2y ago7i67i76i76i76i798778kiki87778uuuuuuuujjjjjjjkkkkkkkk
- hombre_fatal 2y agoIf you're already using setTimeout, why not just use it directly? function clickLoop() { document.querySelector('.main-btn').click(); setTimeout(clickLoop, 50) }
- jampekka 2y agoThat's an infinite loop.
- deleted 2y ago[deleted]
- akx 2y agoBreakable by `clickLoop = null`.
- eterm 2y agoWhat's all this overengineering and waste creating timeouts? Why not just use setInterval? let interval = setInterval(() => document.querySelector('.main-btn').click(), 50) Then clearInterval(interval) to stop
- hombre_fatal 2y agoHow could you be so wasteful traversing the DOM tree every time to find .main-btn? Shame on you.
- phelipetls 2y agoOr use requestAnimationFrame to run infinitely at ~60fps window.requestAnimationFrame(function clickButton() { document.querySelector(".main-btn").click() window.requestAnimationFrame(clickButton) })
- 65 2y agoThis doesn't seem to logarithmically scale when you get the click percent increase upgrade, while the other code does.