Hacker News new | past | comments | ask | show | jobs | submit login

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


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`.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: