I’m having real difficulties using Greasemonkey and Firefox javascript to inject a button that, when selected, will execute a function.
For example, I am trying to place the button right after the “Unanswered” button on the SO “Ask a Question” page.
I wish it to run a function that will do anything, say alert ("Hello World") or console.log('TEST start'), for example.
Can someone please post up some sample code to make this work? Once I have a working sample, then I should be able to go from there.
Many thanks in advance.
The process for this kind of thing is:
For your example page:
Inspecting with Firebug shows that the Unanswered “button” HTML looks like this:
So we will add a “button” like this:
We’ll activate it with jQuery’s
.click().For this page and this button, we do not need to worry about AJAX.
Putting it all together, a complete working script looks like: