-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
55 lines (55 loc) · 2 KB
/
content.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function interceptResponse(response) {
const originalJson = response.json;
response.json = function() {
return originalJson.apply(this, arguments).then(data => {
if (data && data.data) {
if (data.data.plinkoBet) {
chrome.runtime.sendMessage({
type: 'PLINKO_BET_DATA',
data: data.data.plinkoBet
});
} else if (data.data.kenoBet) {
chrome.runtime.sendMessage({
type: 'KENO_BET_DATA',
data: data.data.kenoBet
});
}
}
return data;
});
};
return response;
}
// Intercept fetch requests
const originalFetch = window.fetch;
window.fetch = function(input, init) {
return originalFetch.apply(this, arguments).then(interceptResponse);
};
// Intercept XMLHttpRequests
const originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('load', function() {
if (this.responseURL.includes('/_api/graphql')) {
try {
const responseData = JSON.parse(this.responseText);
if (responseData.data) {
if (responseData.data.plinkoBet) {
chrome.runtime.sendMessage({
type: 'PLINKO_BET_DATA',
data: responseData.data.plinkoBet
});
} else if (responseData.data.kenoBet) {
chrome.runtime.sendMessage({
type: 'KENO_BET_DATA',
data: responseData.data.kenoBet
});
}
}
} catch (error) {
console.error('Error parsing XHR response:', error);
}
}
});
originalXHROpen.apply(this, arguments);
};
console.log('Content script setup complete');