Detect when Gmail has finished loading using jQuery and GreaseMonkey

I am trying to add some jQuery materials to Gmail using the GreaseMonkey script. Adding a jQuery function works fine, but the problem is that I cannot detect when Gmail has finished loading.

This mainly happens:

  • I am updating gmail
  • Startup window starts
  • GM script runs 3 times at boot time
  • Something in the download window is changing
  • GM script runs again
  • Change page
  • GM script last run
  • Download and shut down Gmail

At this point, a bunch of JavaScript was loaded into the DOM, which probably calls some functions that AJAX uses to load the rest of the view.

I would like jQuery to do the stuff after step 8, when everything finished loading.

Does anyone know how to do this / discover?

+7
jquery greasemonkey gmail
source share
1 answer

Firstly, you can yell at Google to fix their gmail-greasemonkey API, which seems to break more every day. In particular, registerViewChangeCallback() will make the solution easier, but it seems to have stopped working correctly.

A workaround would be to delay the change of the main document changes. The following code seems to work for me in Firefox. You may need to change your iFrame content settings.

 // // ==UserScript== // @name Fire on page finished (with AJAX mods) // @namespace Gmail // @description This script shows one way to wait for an AJAX-heavy page to load. // @include http://mail.google.com/* // @include https://mail.google.com/* // ==/UserScript== // if (window.top != window.self) //don't run on frames or iframes return; var zGbl_PageChangedByAJAX_Timer = ''; window.addEventListener ("load", LocalMain, false); function LocalMain () { if (typeof zGbl_PageChangedByAJAX_Timer == "number") { clearTimeout (zGbl_PageChangedByAJAX_Timer); zGbl_PageChangedByAJAX_Timer = ''; } document.body.addEventListener ("DOMNodeInserted", PageBitHasLoaded, false); } function PageBitHasLoaded (zEvent) { if (typeof zGbl_PageChangedByAJAX_Timer == "number") { clearTimeout (zGbl_PageChangedByAJAX_Timer); zGbl_PageChangedByAJAX_Timer = ''; } zGbl_PageChangedByAJAX_Timer = setTimeout (function() {HandlePageChange (); }, 666); } function HandlePageChange () { removeEventListener ("DOMNodeInserted", PageBitHasLoaded, false); alert ('Page has finished loading.'); } 
+5
source share

All Articles