Re:Stimulation Clicker
by ipsum2 on Monday January 06, 2025 @01:47PM
(#42613824)
Running it async will prevent the main screen from lagging:
[ Parent
| on HN ]
Re:Stimulation Clicker
by hombre_fatal on Monday January 06, 2025 @01:54PM
(#42613942)
If you're already using setTimeout, why not just use it directly?
function clickLoop() {
document.querySelector('.main-btn').click();
setTimeout(clickLoop, 50)
}What'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
Re:Stimulation Clicker
by hombre_fatal on Monday January 06, 2025 @06:13PM
(#42617198)
How could you be so wasteful traversing the DOM tree every time to find .main-btn? Shame on you.
That's an infinite loop.
Breakable by `clickLoop = null`.
Re:Stimulation Clicker
by phelipetls on Monday January 06, 2025 @05:15PM
(#42616607)
Or use requestAnimationFrame to run infinitely at ~60fps
window.requestAnimationFrame(function clickButton() {
document.querySelector(".main-btn").click()
window.requestAnimationFrame(clickButton)
})This doesn't seem to logarithmically scale when you get the click percent increase upgrade, while the other code does.