I am trying to create a Tampermonkey script to automatically fill a login form with my username and password and then I would like to click the login button. However, with the code below, it appears to wait the three seconds, and THEN it fills the text into the boxes. How can I "flush" the changes so that they appear before the wait time occurs?
Thanks!
(function() {
'use strict';
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
window.onbeforeunload = function (){
return "Leaving page...";
}
$(document).ready(function() {
document.getElementById("username").value = "userValue";
document.getElementById("password").value = "passwordValue";
wait(3000);
document.getElementsByClassName("btn-large").click();
});
})();