I’m trying to add some jQuery stuff to Gmail using a GreaseMonkey script. Adding jQuery functionality works fine, but the problem is that I can’t really detect when Gmail has finished loading.
This is basically what happens:
- I refresh Gmail
- The loading window starts
- The GM script starts 3 times, during the loading window
- Something in the loading window changes
- The GM script starts one more time
- The page changes
- The GM script starts for the last time
- Gmail view loads and finishes
At this point a bunch of JavaScript has been loaded into the DOM that probably calls on some functions that use AJAX to load the rest of the view.
I’d like for jQuery to do stuff after step 8, when everything has finished loading.
Does anyone know how to do/detect this?
First, you can yell at Google to fix their gmail-greasemonkey API — which seems to break more each day. Specifically,
registerViewChangeCallback()would facilitate a solution but it seems to have stopped working correctly.A workaround would be to delay-fire off main document changes. The following code seems to work for me, on Firefox. It might need tweaking for iFrame content.