Created
February 28, 2014 15:37
-
-
Save CezaryDanielNowak/9273158 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() { | |
window.xhrs = []; | |
var tmpSend = XMLHttpRequest.prototype.send, | |
tmpSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader, | |
tmpOpen = XMLHttpRequest.prototype.open; | |
XMLHttpRequest.prototype.open = function(type, url, async, user, pass) { | |
this._requestHeaders = []; | |
this._openArgs = arguments; | |
// this.theRequestUrlAndType = type + ' ' + url | |
// + (user || pass ? ' (' + user + ' / ' + pass + ')' : ''); | |
return tmpOpen.apply(this, this._openArgs); | |
}; | |
XMLHttpRequest.prototype.setRequestHeader = function() { | |
this._requestHeaders.push(arguments); | |
return tmpSetRequestHeader.apply(this, arguments); | |
}; | |
XMLHttpRequest.prototype.send = function(/* data is arguments[0] */) { | |
var t = this; | |
var args = arguments; | |
t._edit = function() { | |
t._openArgs[1] = prompt("Confirm XHR url:\n" + t._openArgs[1], t._openArgs[1]) || t._openArgs[1]; | |
var newData = prompt("Confirm XHR data for:\n" + t._openArgs[1], (args[0] == null ? '' : args[0]) ); | |
if(newData === null) | |
return; | |
args[0] = newData; | |
var xhr = new XMLHttpRequest(); | |
xhr.open.apply(xhr, t._openArgs); | |
if(t._requestHeaders && this._requestHeaders.length) { | |
t._requestHeaders.forEach(function(headerArgs){ | |
tmpSetRequestHeader.apply(xhr, headerArgs); | |
}); | |
} | |
return xhr.send.apply(xhr, args); | |
}; | |
xhrs.push(t); | |
console.log("xhrs[" + (xhrs.length-1) + "]._edit() to resend with new data", args); | |
return tmpSend.apply(t, args); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment