Last active
September 10, 2023 09:39
-
-
Save erdemkiiliic/3e3caa666ca1c950c4db3e94a8d3f049 to your computer and use it in GitHub Desktop.
xml/http listener with js
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
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