DF RequestHandler

Request handler library for Dead Frontier

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/579721/1834453/DF%20RequestHandler.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// Thanks to SilverBeam (creator of SilverScripts) for allowing me to use the serializeObject and makeRequest functions from SilverScripts

function serializeObject(obj)
    {
        var pairs = [];
        for (var prop in obj)
        {
            if (!obj.hasOwnProperty(prop)) continue;
            pairs.push(prop + "=" + obj[prop]);
        }
        return pairs.join("&");
    }

function makeRequest(requestUrl, requestParams, callbackFunc, callbackParams = null)
{
    return new Promise((resolve) =>
    {
        var xhttp = new XMLHttpRequest();
        var payload = null;
        xhttp.onreadystatechange = function()
        {
            if (this.readyState == 4 && this.status == 200)
            {
                // Invoke the callback with the request response text and some parameters, if any were supplied
                // then resolve the Promise with the callback's reponse
                let callbackResponse = null;
                if (callbackFunc != null)
                {
                    callbackResponse = callbackFunc(this.responseText, callbackParams);
                }
                if (callbackResponse == null)
                {
                    callbackResponse = true;
                }
                resolve(callbackResponse);
            }
        };

        payload = serializeObject(requestParams);

        xhttp.open("POST", "https://fairview.deadfrontier.com/onlinezombiemmo/" + requestUrl + ".php", true);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.setRequestHeader("x-requested-with", "ArysScriptsRequest");
        payload = "hash=" + unsafeWindow.hash(payload) + "&" + payload;
        xhttp.send(payload);
    });
}