Skip to content

Instantly share code, notes, and snippets.

@jaimalchohan
Forked from suprememoocow/intercept.js
Last active December 26, 2015 11:09
Show Gist options
  • Save jaimalchohan/7142034 to your computer and use it in GitHub Desktop.
Save jaimalchohan/7142034 to your computer and use it in GitHub Desktop.
(function(XHR) {
"use strict";
var stats = [];
var timeoutId = null;
var open = XHR.prototype.open;
var send = XHR.prototype.send;
XHR.prototype.open = function(method, url, async, user, pass) {
this._url = url;
open.call(this, method, url, async, user, pass);
};
XHR.prototype.send = function(data) {
var self = this;
var start;
var oldOnReadyStateChange;
var url = this._url;
function onReadyStateChange() {
if(self.readyState == 4 /* complete */) {
puts 'hello';
}
if(oldOnReadyStateChange) {
oldOnReadyStateChange();
}
}
if(!this.noIntercept) {
start = new Date();
if(this.addEventListener) {
this.addEventListener("readystatechange", onReadyStateChange, false);
} else {
oldOnReadyStateChange = this.onreadystatechange;
this.onreadystatechange = onReadyStateChange;
}
}
send.call(this, data);
}
})(XMLHttpRequest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment