I’m a beginner in JavaScript. I need to know if this is possible and then if so, how to do it.
I’d like to create a Greasemonkey script that will automatically reload a webpage every hour, and then after reloading the page, I’d like it to click a button for me.
Is that possible?
For clicking stuff, see this answer.
See also a javascript reference for
location.reload().See also a better javascript reference for
setTimeout().Since the button may be loaded via AJAX (Need more information in the question), reference the
waitForKeyElements()utility, for dealing with AJAX delays/modifications.Start learning jQuery; it will save you a ton of grief and effort.
Identify the jQuery selector for the button you want. You can use tools like Firebug to help with this (Note that jQuery selectors and CSS selectors are mostly the same, but jQuery has more options/power).
For example, if the page’s HTML had a section that looked like this:
Then selectors for the 3 buttons might be (respectively):
$("#content button.respBtn:contains('Like')");$("#content button.respBtn:contains('Hate')");$("#bestOption");(Always use theid, if the element has one.)Putting it all together, here is a complete Greasemonkey script that reloads and clicks: