0

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();
mstephen19
  • 1,733
  • 1
  • 5
  • 20
  • `elt.click()` simulates a click on the given element `elt`. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click – Nice Books Jun 15 '22 at 08:36

1 Answers1

0

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.

mstephen19
  • 1,733
  • 1
  • 5
  • 20