[Greasemonkey] Getting script to run once the page fully loads
Mark Pilgrim
pilgrim at gmail.com
Fri May 19 17:44:48 EDT 2006
On 5/19/06, Jeremy Dunck <jdunck at gmail.com> wrote:
> Actually, user scripts inject just before the load event-- on the
> firefox-specific DOMContentLoaded event.
>
> chrome/browser.js:
> GM_BrowserUI.chromeLoad = function(e) {
> ...
> GM_listen(this.appContent, "DOMContentLoaded", GM_hitch(this, "contentLoad"));
> ...
> }
>
> GM_BrowserUI.contentLoad = function(e) {
> ...
> if (GM_getEnabled() && GM_isGreasemonkeyable(href)) {
> ..
> this.gmSvc.domContentLoaded({ wrappedJSObject: unsafeWin });
> ...
> }
>
> components/greasemonkey.js:
> domContentLoaded: function(wrappedWindow) {
> ...
> this.injectScripts(scripts, href, unsafeWin);
This is all very interesting, but does not answer the original
poster's question. If I understand it correctly, you want a
Greasemonkey script to load *after* the page is completely finished
loading, including all external images, etc.
If so, then what you need to do is define an onload handler and call
your main function from it, like so:
function my_entire_script_code() {
... my code...
}
window.addEventListener('load', my_entire_script_code, false);
Hope this helps.
--
Cheers,
-Mark
More information about the Greasemonkey
mailing list