Skip to content

Instantly share code, notes, and snippets.

@rakauchuk
Created January 19, 2015 12:39
Show Gist options
  • Save rakauchuk/b66687d6c029545f5cad to your computer and use it in GitHub Desktop.
Save rakauchuk/b66687d6c029545f5cad to your computer and use it in GitHub Desktop.
handle ajaxComlete in chrome ext (jquery)
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