Ajax Async Lib

Async lib for the west

Ekde 2024/03/23. Vidu La ĝisdata versio.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/490628/1347984/Ajax%20Async%20Lib.js

You will need to install an extension such as Tampermonkey, Greasemonkey 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 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.

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

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

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));
            },
        
        }
    }();

    })();