ProgramProdigy
ProgramProdigy

Reputation: 45

How do I make a div click without the mouse moving?

I'm trying to make a JavaScript code that injects into cpstest.org and when you click the start button, it automatically starts auto-clicking. I tried to make a script for it, but it just didn't work.

The start button has id start but I don't know the element to click. Viewing source code or using dev tools would be helpful, but those are blocked on my computer.

let i = 1;

document.querySelector('#start').addEventListener('click', function() {
    i = 0;
});

function repeat() {
    if (i == 0) {
        document.querySelector(unknownId).click()}; 
        requestAnimationFrame(repeat)
    }
};

repeat();

Upvotes: 0

Views: 153

Answers (1)

mstephen19
mstephen19

Reputation: 1926

Here's a solution:

// speed - how many CPS you want
// duration - how long the test is (in seconds)
const rapidClick = (speed, duration) => {
    const startButton = document.querySelector('button#start');
    const clickArea = document.querySelector('div#clickarea');

    // Start the test
    startButton.click()

    // Click the clickArea on an interval based on the "speed" provided
    const interval = setInterval(() => clickArea.click(), 1e3 / speed);

    // Clear the interval after the duration has passed
    setTimeout(() => clearInterval(interval), duration * 1e3);
}

// Do 100 CPS for 5 seconds
rapidClick(100, 5)

I noticed that even when setting the speed parameter to something insane like 1000 CPS, the test says only 133-139 clicks per second. Seems like it caps off at 139. Hope this helps.

Upvotes: 0

Related Questions