mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2026-10-22 23:12:12 +03:00
Add hooks.js for Ajax request intercepting
This commit is contained in:
1 parent
e7e0163fc7
commit
265e8bf29d
1 file changed
+31
@@ -0,0 +1,31 @@
|
||||
var HOOKS = (function(){
|
||||
return {
|
||||
/*
|
||||
* Intercepts an AJAX response, and passes the original request open() arguments and the request object itself to the provided function.
|
||||
*/
|
||||
onAjaxResponse: function(func){
|
||||
var prevOpen = XMLHttpRequest.prototype.open;
|
||||
var prevSend = XMLHttpRequest.prototype.send;
|
||||
|
||||
XMLHttpRequest.prototype.open = function(){
|
||||
this.$requestArguments = arguments;
|
||||
return prevOpen.apply(this, arguments);
|
||||
};
|
||||
|
||||
XMLHttpRequest.prototype.send = function(){
|
||||
var req = this;
|
||||
var prevEvent = this.onreadystatechange;
|
||||
|
||||
this.onreadystatechange = function(){
|
||||
if (req.readyState === XMLHttpRequest.DONE && req.status === 200){
|
||||
func(this.$requestArguments, req);
|
||||
}
|
||||
|
||||
return prevEvent.apply(this, arguments);
|
||||
};
|
||||
|
||||
return prevSend.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
};
|
||||
})();
|
||||
Reference in new issue
Block a user