Created
April 17, 2022 02:41
-
-
Save 8dcc/2c595e5cf6ff4288b9ea19ba5ff3ec59 to your computer and use it in GitHub Desktop.
Add custom delay to userscript functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Delay function | |
// @namespace Violentmonkey Scripts | |
// @include *://example.com/* | |
// @run-at document-start | |
// @author Null (r4v10l1) | |
// ==/UserScript== | |
// --------------------- Settings --------------------- | |
var MY_DELAY = 500; // ms, delayChecker will wait this | |
var MY_INITIAL_DELAY = 500; // ms, the script will wait this before the first check | |
// ---------------------------------------------------- | |
function mainFunction() { | |
console.log("This is the main function to be executed.") | |
} | |
function delayChecker(customDelay) { | |
// Remove after you test the userscript! | |
console.log("Entered the checker! You can test the userscript by typing 'condition = true' on the console."); | |
if (condition) mainFunction(); | |
else setTimeout(function () { delayChecker(customDelay); }, customDelay); | |
} | |
condition = false; | |
setTimeout(function () { delayChecker(MY_DELAY); }, MY_INITIAL_DELAY); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are welcome.