title: JavaScript - how Greasemonkey works
body: <p>I read "<a href="http://en.wikipedia.org/wiki/Greasemonkey#External_links" rel="nofollow noreferrer">Dive into Greasemonkey</a>" (by <a href="http://en.wikipedia.org/wiki/Mark_Pilgrim_%28software_developer%29" rel="nofollow noreferrer">Mark Pilgrim</a>) written in 2005. It mentions that Greasemonkey wraps a user script in an anonymous function wrapper. Does Greasemonkey insert the wrapper into the source JavaScript code or add it as any event handler such as <code>window.onload</code>?</p>