▲ 2 r/tampermonkey
Problem creating a very simple autoclicker
First off: I'm not a programmer and I barely know any JavaScript. I want to use Tampermonkey to create an automation that clicks a button called PROCESS on a page with multiple identical buttons (in name). When I click one, it disappears (the page doesn't refresh), and what I want is for them to be clicked one after the other with a 60-second interval (the order of the buttons doesn't matter).
The buttons are identified by `type="button" value="PROCESS"`.
I asked Gemini for help, and they gave me some code that seems correct, but somehow it doesn't work. Any idea?
// ==UserScript==
// 60 seconds
// website url
// 0.1
// try to take over the world!
// You
// *://*/*
// none
// ==/UserScript==
(function() {
'use strict';
const INTERVAL_MS = 60000; // 60 seconds
function pressNextButton() {
// Selects exactly the button inputs with the value PROCESS
const buttons = document.querySelectorAll('input[type="button"][value="PROCESS"]');
if (buttons.length > 0) {
console.log(`[Autoclicker] ${buttons.length} buttons remain. Clicking the first one...`);
// Triggers the native click event
buttons[0].click();
} else {
console.log('[Autoclicker] No more PROCESS buttons were found. Process completed.');
}
}
// Waits 3 seconds for the page to load the elements before the first click
setTimeout(() => {
pressNextButton();
setInterval(pressNextButton, INTERVAL_MS);
}, 3000);
})();
u/De-monV — 8 days ago