議論 » 開発

Detect XHR request

§
投稿日: 2016/01/17
編集日: 2016/01/17

Detect XHR request

Hey, I'd like to fire a function when the site does a XHR request.
The function I want to call uses GM_setValue and GM_getValue, so that makes it also more difficult.
I also tried the function below, but it only works when using it in the javascript console. When I use it with a userscript it doesn't work anymore...
I've already tried waitForKeyElements, but that doesn't seem to work for me.
And setTimeout and setInterval is not really an option.
Please help. Thanks in advance!

var oldXHR = window.XMLHttpRequest;
function newXHR() {
var realXHR = new oldXHR();
realXHR.addEventListener("readystatechange", function() {
if(realXHR.readyState==4 && realXHR.status==200){
afterAjaxComplete() //run your code here
}
}, false);
return realXHR;
}
window.XMLHttpRequest = newXHR;

返信を投稿

返信を投稿するにはログインしてください。