Created
June 24, 2011 13:48
-
-
Save cramforce/1044797 to your computer and use it in GitHub Desktop.
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
function set() { | |
var origTimeout = window.setTimeout; | |
window.setTimeout = function(cb, time) { | |
if (time == null || time == 0 && typeof cb === 'function') { | |
var active = true; | |
var mc = new MessageChannel(); | |
mc.port1.onmessage = function() { | |
if (active) { | |
cb(); | |
} | |
}; | |
mc.port2.postMessage(0); | |
var clear = function clearMessage() { | |
active = false; | |
}; | |
clear.emulateClearTimeout = true; | |
return clear; | |
} else { | |
return origTimeout.apply(this, arguments); | |
} | |
}; | |
var origClearTimeout = window.clearTimeout | |
window.clearTimeout = function(index) { | |
if (typeof index === 'function' && index.emulateClearTimeout) { | |
return index(); | |
} | |
return origClearTimeout(index); | |
}; | |
} | |
var script = '(' + set + ')()'; | |
var s = document.createElement('script'); | |
s.textContent = script; | |
document.getElementsByTagName('*')[0].insertBefore(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment