-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintercept.js
40 lines (38 loc) · 1.14 KB
/
intercept.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function interceptData() {
var xhrOverrideScript = document.createElement('script');
xhrOverrideScript.type = 'text/javascript';
xhrOverrideScript.innerHTML = `
(function() {
var XHR = XMLHttpRequest.prototype;
var send = XHR.send;
var open = XHR.open;
XHR.open = function(method, url) {
this.url = url; // the request url
return open.apply(this, arguments);
}
XHR.send = function() {
this.addEventListener('load', function() {
console.log(this.url);
if (this.url.includes('GetMarketChartData')) {
var evt = new CustomEvent("chartDataLoaded", {detail: JSON.parse(this.response)});
document.dispatchEvent(evt);
}
});
return send.apply(this, arguments);
};
})();
`
document.head.prepend(xhrOverrideScript);
}
function checkForDOM() {
if (document.body && document.head) {
interceptData();
} else {
requestIdleCallback(checkForDOM);
}
}
requestIdleCallback(checkForDOM);
//in content script include:
//document.addEventListener("chartDataLoaded",(e) => {
// console.log(e.detail);
//});