Skip to content

Instantly share code, notes, and snippets.

@erdemkiiliic
Last active September 10, 2023 09:39
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 erdemkiiliic/3e3caa666ca1c950c4db3e94a8d3f049 to your computer and use it in GitHub Desktop.
Save erdemkiiliic/3e3caa666ca1c950c4db3e94a8d3f049 to your computer and use it in GitHub Desktop.
xml/http listener with js
if (typeof window.jsXMLHTTPListener === 'undefined') {
let jsXMLHTTPListener = {
isCallFinishedStatus: 1,
pointerSize: 0,
pointerFinishSize: 0,
isCallFinished: function() {
return 1 === this.isCallFinishedStatus;
},
setCallFinished: function(i = 0) {
this.isCallFinishedStatus = i;
},
bindEvents: function(i, t) {
var e = t.XMLHttpRequest.prototype.send;
t.XMLHttpRequest.prototype.send = function() {
i.setCallFinished(0);
var n = this;
i.pointerSize++;
var s = t.setInterval(function() {
4 == n.readyState && (i.pointerFinishSize++, i.pointerSize === i.pointerFinishSize ? i.setCallFinished(1) : i.setCallFinished(0), clearInterval(s));
}, 1);
return e.apply(this, [].slice.call(arguments));
};
},
init: function() {
this.bindEvents(this, window);
},
};
(window.jsXMLHTTPListener = jsXMLHTTPListener), window.jsXMLHTTPListener.init();
let a = window.jsXMLHTTPListener.isCallFinished();
console.log(a);
} else {
let a = window.jsXMLHTTPListener.isCallFinished();
console.log(a);
}
//usage
setInterval(() => {
let a = window.jsXMLHTTPListener.isCallFinished();
console.log(a);
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment