this script for greasemonkey is working for me, to click a button, when a certain website was loaded.
But how can I set a waiting time? Example: The website loaded and the script waits 1 second till it is executed.
My second question is: how can I run it only once per pageload? The script starts over and over again.
// ==UserScript==
// @name _YOUR_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
function clickSubmitBtnWhenItAppears (jNode) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}
//-- Value match is case-sensitive
waitForKeyElements (
//"#btn_submit input[type='submit'][value*='Click Me Now']",
"input[type='submit'][value*='Click Me Now']",
clickSubmitBtnWhenItAppears
);
Script source: How do I get Greasemonkey to click on a button that only appears after a delay?
let timeoutID = setTimeout(function, delay in milliseconds, argument1, argument2,...); The delay is set in milliseconds and 1,000 milliseconds equals 1 second. If the delay is omitted from the setTimeout() method, then the delay is set to 0 and the function will execute.
import { setTimeout } from "timers/promises"; const yourFunction = async () => { await setTimeout(5000); console. log("Waited 5s"); await setTimeout(5000); console.
This might be what you are looking for:
$(document).ready(function() { //When document has loaded
setTimeout(function() {
//Code to run After timeout elapses
}, 2000); //Two seconds will elapse and Code will execute.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With