Created
January 19, 2015 12:39
-
-
Save rakauchuk/b66687d6c029545f5cad to your computer and use it in GitHub Desktop.
handle ajaxComlete in chrome ext (jquery)
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
var main = function () { | |
var myEvent = document.createEvent('Event'); | |
myEvent.initEvent('CustomEvent', true, true); | |
function fireCustomEvent() { | |
document.body.dispatchEvent(myEvent); | |
}; | |
jQuery(document).ajaxComplete(function (event, request, settings) { | |
console.log("Ajax complete."); | |
fireCustomEvent(); | |
}); | |
}; | |
var injectedScript = document.createElement('script'); | |
injectedScript.type = 'text/javascript'; | |
injectedScript.text = '(' + main + ')("");'; | |
(document.body || document.head).appendChild(injectedScript); | |
document.body.addEventListener('CustomEvent', function () { | |
console.log("Received event!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment