Last active
February 11, 2017 21:40
-
-
Save tegomass/734b5a868f9222a6c1a89a42232768b5 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/tegomass/734b5a868f9222a6c1a89a42232768b5/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