Skip to content

Instantly share code, notes, and snippets.

@allquest
Last active February 11, 2017 18:09
Show Gist options
  • Save allquest/3e5b163374d4be41f599e12b0695294f to your computer and use it in GitHub Desktop.
Save allquest/3e5b163374d4be41f599e12b0695294f to your computer and use it in GitHub Desktop.
WaitForGmail loading -- The jQuery ready function doesn't work on AJAX call, use this instead -- Use this link to embed : https://gist.githubusercontent.com/allquest/3e5b163374d4be41f599e12b0695294f/raw/
/*
usage example: waitForGmail(function(){ console.log('TEGO!!')});
*/
function waitForGmail(callback){
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);
if (callback){
callback();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment