Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
in Dom eingefügter Code wird nicht auf Webseite richtig dargestellt
#3
Hm, dann eben hier alle 3 Dateien:
die manifest.json:
Code:
{
  "name": "Test3",
  "description": "blabla",
  "version": "1.0",
  "manifest_version": 3,
      "background": {"service_worker": "bg.js"},
  "permissions": ["scripting"],
  "host_permissions": ["<all_urls>"]


}

bg.js:
Code:
chrome.runtime.onInstalled.addListener(async () => {
  const old = await chrome.scripting.getRegisteredContentScripts();
  if (old[0]) await chrome.scripting.unregisterContentScripts({ids: old.map(s => s.id)});
  await chrome.scripting.registerContentScripts([{
    id: 'write',
    js: ['write.js'],
    matches: ['<all_urls>'],
    runAt: 'document_start',
    world: 'MAIN',
  }]);
});

und write.js:

Code:
(function(xhr) {

    var XHR = XMLHttpRequest.prototype;

    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(this.responseType);
                if ( this.responseType != 'blob') {
                    // responseText is string or null
                    try {

                        // here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
                        var arr = this.response;

                        // printing url, request headers, response headers, response body, to console
                                                //console.log(" ");
                        //console.log(this._url);
                        //console.log(JSON-parse(this._requestHeaders));
                        //console.log(responseHeaders);
                                                
                                                
//*************************************************************************************************************************                                                
                                                if(arr.includes("gameServerVersion")){
                                                    



                                                    //console.log(arr);
                                                    var wintext=arr.match(/&winnumber=[0-9]+/g);
                                                    //console.log(wintext[0]);
                                                    let result = arr.match(/&winnumber=[0-9]+/)[0].substring(11, (arr.length-1));
                                                    console.log(result);

                                                    let rot=["1","3","5","7","9","12","14","16","18","19","21","23","25","27","30","32","34","36"];
                                                    
                                                    
                                                    const element = document.getElementById("insertedDiv1234");
                                                    if(element!=null){
                                                        element.remove();
                                                    }
                                                    
                                                    const div=document.createElement("div");
                                                    div.setAttribute("id","insertedDiv1234");
                                                    div.setAttribute("style","position:fixed; top: 0px; left: 0px; width:20px; height:20px;");
                                                    
                                                    
                                                    if(rot.includes(result)){div.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(255, 0, 0);'>O</p>";}
                                                    else if(result.equals("0")){div.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 255, 0);'>O</p>";}
                                                    else{div.innerHTML="<p style='border-width:1px; border-style:solid; border-color:white; padding: 1em; color:white; background-color:rgb(0, 0, 0);'>O</p>";}
                                                    console.log(div);
                                                    document.body.appendChild(div);

                                                    console.log(result);                   
                                                }
/***************************************************************************************************************************************************                                                

                    } catch(err) {
                        //console.log("Error in responseType try catch");
                        //console.log(err);
                    }
                }

            }
        });

        return send.apply(this, arguments);
    };

})(XMLHttpRequest);



Welches Gewinnspiel meinst du? Es geht um einen Roulettetisch.
Zitieren


Nachrichten in diesem Thema
RE: in Dom eingefügter Code wird nicht auf Webseite richtig dargestellt - von bernd - 23.09.2022, 03:22

Gehe zu:


Benutzer, die gerade dieses Thema anschauen:
1 Gast/Gäste