Reputation: 21
Hello how to make a simple code in JS to Greasemonkey which click button on page after 4 sec? I'm fully beginner in JS.
Here is code of this button ;):
<a class="doIt" href="#" onClick="func_x()"></a>
Thanks for help.
Upvotes: 2
Views: 4517
Reputation: 8763
setTimeout(function() {
unsafeWindow.func_x(); // onclick event function
}, 4000);
or better yet
setTimeout(function() {
location.assign("javascript:func_x()"); // onclick event function
}, 4000);
Upvotes: 2
Reputation: 62783
setTimeout(function() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
var link = document.querySelector("a.doIt");
link.dispatchEvent(evt);
}, 4000);
References:
Live example:
Upvotes: 1