Ajax Async Lib

Async lib for the west

Version vom 23.03.2024. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/490628/1347984/Ajax%20Async%20Lib.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Ajax Async Lib
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Async lib for the west
// @include https://*.the-west.*/game.php*
// @include https://*.the-west.*.*/game.php*
// @license MIT
// ==/UserScript==


(function () {
    AjaxAsync = function() {
        jQuery.ajaxSetup({
            type: 'POST',
            dataType: 'json'
        });
        var makeUrl = function(options) {
            var url = 'game.php'
              , params = [];
            if (options.window)
                params.push('window=' + options.window);
            if (options.action)
                params.push('action=' + options.action, 'h=' + Player.h);
            if (options.ajax)
                params.push('ajax=' + options.ajax);
            if (options.mode)
                params.push('mode=' + options.mode);
            return url + params.length ? '?' + params.join('&') : '';
        };
        var onFinish = function(window) {
            return function() {
                if (window && window.hideLoader)
                    window.hideLoader();
                else if (window && window.hasOwnProperty('window'))
                    window.window.hideLoader();
            };
        };
        var request = async function(options) {
            var url = options.url || makeUrl(options);
            return await jQuery.ajax(url, options);
        };
        var defaultRequest = async function(options, window) {
            if (window && window.showLoader)
                window.showLoader();
            else if (window && window.hasOwnProperty('window'))
                window.window.showLoader();
            var result = await request(options);
            onFinish(window)();
            return result;
        };
        return {
            remoteCall: async function(window, action, param, view) {
                return await defaultRequest({
                    window: window,
                    action: action,
                    data: param
                }, view);
            },
            remoteCallMode: async function(window, mode, param, view) {
                return await defaultRequest({
                    window: window,
                    mode: mode,
                    data: param
                }, view);
            },
            get: async function(window, ajax, param, view) {
                return await defaultRequest({
                    window: window,
                    ajax: ajax,
                    data: param
                }, view);
            },
            gameServiceRequest: async function(method, urlparam, post) {
                return await defaultRequest({
                    url: Game.serviceURL + '/' + method + '/' + urlparam,
                    data: post
                });
            },
            request: request,
            wait: function (ms) {
                return new Promise(resolve => setTimeout(resolve, ms));
            },
        
        }
    }();

    })();