I did not work with GreaseMonkey, but I assume that your script is in its own area, and all of its variables are freed after the script completes. Since you define init in this area, but then call it on the main page, the function is undefined when it is called.
You can put the whole function in an onclick event or call a callback:
if (elem.addEventListener) { elem.addEventListener('click',init,false); } else { elem.attachEvent('onclick',init); }
(attachEvent is IE specific)
source share