First of all madam, I need you to lower your cockiness. I dont see the issue with your question, I see an issue with the locked thread.
Too bad so many extensions out there inject code into a website and change the DOM...
all malicious, right? ;-)
Secondly, I wanna inject this file here to the site, so it draws colored boxes based on values within 2 specific request responses.
JavaScript:
function test(){
console.log("This is a Test!");
}
test();
var prevBalance=0;
var thisBalance=0;
(function(xhr) {
console.log("recognizing a new http request...");
var XHR = XMLHttpRequest.prototype;
console.log("XHR");
var open = XHR.open;
var send = XHR.send;
var setRequestHeader = XHR.setRequestHeader;
XHR.open = function(method, url) {
this._method = method;
this._url = url;
this._requestHeaders = {};
this._startTime = (new Date()).toISOString();
return open.apply(this, arguments);
};
XHR.setRequestHeader = function(header, value) {
this._requestHeaders[header] = value;
return setRequestHeader.apply(this, arguments);
};
XHR.send = function(postData) {
this.addEventListener('load', function() {
var endTime = (new Date()).toISOString();
var myUrl = this._url ? this._url.toLowerCase() : this._url;
if(myUrl) {
if (postData) {
if (typeof postData === 'string') {
try {
// here you get the REQUEST HEADERS, in JSON format, so you can also use JSON.parse
this._requestHeaders = postData;
} catch(err) {
console.log('Request Header JSON decode failed, transfer_encoding field could be base64');
console.log(err);
}
} else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean') {
// do something if you need
}
}
// here you get the RESPONSE HEADERS
var responseHeaders = this.getAllResponseHeaders();
console.log("responseHeaders:"+responseHeaders);
console.log("this.responseType:"+this.responseType);
if ( this.responseType != 'blob') {
// responseText is string or null
try {
/*
<input class="form-input ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" id="form-pass" type="password" name="password" ng-model="credentials.password" placeholder="Password" required="required" style="">
*/
// here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
var arr = this.response;
console.log(arr);
// printing url, request headers, response headers, response body, to console
console.log(" ");
console.log(this._url);
this._requestHeaders
//console.log(this._requestHeaders.toLocaleString());
//console.log(responseHeaders);
if(arr.includes("numbers=")){
//second box
const test21 = document.getElementById("insertedDiv21");
if(test21!=null){
test21.remove();
}
const div21=document.createElement("div");
div21.setAttribute("id","insertedDiv21");
div21.setAttribute("style","position:fixed; top: 40px; left: 0px; width:20px; height:20px;");
div21.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(255, 255, 255);'></p>";
document.body.appendChild(div21);
}
//*************************************************************************************************************************
if(arr.includes("winnumber=")){
//get result
let wintext=arr.match(/&winnumber=[0-9]+/g);
let result = arr.match(/&winnumber=[0-9]+/)[0].substring(11, (arr.length-1));
let rot=["1","3","5","7","9","12","14","16","18","19","21","23","25","27","30","32","34","36"];
//get balance and balance change
let tempBalance=arr.match(/&credit=[0-9]+/)[0].substring(8, (arr.length-1));
let diff=tempBalance-prevBalance;
console.log("diff="+diff+"!");
//first box, color of last drawn number
const test11 = document.getElementById("insertedDiv11");
if(test11!=null){
test11.remove();
}
const div11=document.createElement("div");
div11.setAttribute("id","insertedDiv11");
div11.setAttribute("style","position:fixed; top: 0px; left: 0px; width:20px; height:20px;");
if(rot.includes(result)){
div11.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(255, 0, 0);'></p>";}
else if((result=="0")){
div11.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 255, 0);'></p>";}
else{
div11.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 0, 0);'></p>";}
document.body.appendChild(div11);
//second box, are controls usable again? white yes, black no
const test21 = document.getElementById("insertedDiv21");
if(test21!=null){
test21.remove();
}
const div21=document.createElement("div");
div21.setAttribute("id","insertedDiv21");
div21.setAttribute("style","position:fixed; top: 40px; left: 0px; width:20px; height:20px;");
div21.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 0, 0);'></p>";
document.body.appendChild(div21);
//third box, balance change white=bigger, blue=equal and black=less than before
const test12 = document.getElementById("insertedDiv12");
if(test12!=null){
test12.remove();
}
const div12=document.createElement("div");
div12.setAttribute("id","insertedDiv12");
div12.setAttribute("style","position:fixed; top: 0px; left: 40px; width:20px; height:20px;");
if((prevBalance==0)||(parseInt(diff)==0)){
div12.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 0, 255);'></p>";
}
else if(parseInt(diff)>0){
div12.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(255, 255, 255);'></p>";
}
else{
div12.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 0, 0);'></p>";
}
prevBalance=tempBalance;
document.body.appendChild(div12);
}
//***************************************************************************************************************************************************
} catch(err) {
//console.log("Error in responseType try catch");
//console.log(err);
}
}
}
});
return send.apply(this, arguments);
};
})(XMLHttpRequest);
background is that I am building a java bot to play roulette for me.
and in order to make my life easier, I wanna use a chrome extension (that is to be built here)
that catches each and every request , if it's one of t2 specific ones, it will draw certain boxes (deleting old ones if there are already any).
so it basically displays one box showing the last draws color,
one box to display wether the wheel is spinning or if I can currently place bets and stuff (handily the time certsin requests come in corresponds to the monet buttons on the roulette wheel are usable again9,
and other stuff.
oh and one box that visually shows how the balance changed in the last draw (so if we lost, won or no change).
While the whole concept worked when trying it on a website with a roulette simulator
it sadly didnt work on the actual casino website.
requests were console.logged the whole time the site was loading the roulette room (while the visual loading bar was on the screen) however
as soon as the actual roulette table was on screen, jsut no network requests were caught anymore.
(in chrome developer tools, in the network tab, I can clearly see the basically same requests and responses happening when playing that I also did in the simulator. so aside from very small differences its the very same. well, the table is from netent too, so was to be expected)
my random guess was that, since the website url didnt change but the visual website content (and therefor the DOM) changed, I would assume that at some point somehow the injected script got somehow deleted.
aand without it being in there, it obviously wouldnt catch and react to requests either.
so I wanted to check if somethign different happens if I inject the script each time a new request is made.
Cause, as I wrote in the original post, currently the script is only injected onvce at the very beginning.
if the injected script somehow gets deleted along the way, it's gone.
so injecting it every now and then might give me some clue on wtf is happening in there.
well, was the plan but couldnt manage to get the right order for the eventlistener and executescript thing and some handicapped ones told me my code was malicious. after locking the tpopic without zero explanation or anything, leaving one to random guess....