Last active
February 11, 2017 18:09
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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