Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Last active February 28, 2016 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiny-Giant/26f4066aa618906f2252 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/26f4066aa618906f2252 to your computer and use it in GitHub Desktop.
function addXHRListener(callback)
{
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function()
{
this.addEventListener('load', callback.bind(null, this), false);
open.apply(this, arguments);
};
};
addXHRListener(function(xhr)
{
if (/ajax-load-realtime/.test(xhr.responseURL))
{
var matches = /question" data-questionid="(\d+)/.exec(xhr.responseText);
var post;
if (matches === null)
{
matches = /answer" data-answerid="(\d+)/.exec(xhr.responseText);
if (matches === null)
{
return;
}
post = document.querySelector('[data-answerid="' + matches[1] + '"]');
}
else
{
post = document.querySelector('[data-questionid="' + matches[1] + '"]');
}
if (post === null)
{
return;
}
// do stuff
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment