Raw Source
ProgramZero / CatWar ClosedHack

// ==UserScript==
// @name         CatWar ClosedHack
// @namespace    superhacker
// @version      1.2.4
// @description  Хак для вара
// @author       Hacker
// @copyright    2020, https://vk.com/nikitaplayminec
// @license      MIT; https://opensource.org/licenses/MIT
// @downloadURL https://openuserjs.org/install/ProgramZero/CatWar_Hack.user.js
// @updateURL https://openuserjs.org/meta/ProgramZero/CatWar_Hack.meta.js
// @include      https://catwar.su/*
// @grant        GM_xmlhttpRequest
// @grant        GM.xmlHttpRequest
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

(function(win, $) {
    'use strict';
    const scriptUrl = "https://volchlibrary.000webhostapp.com/";
    function getScript() {
        let key = "cwmodss_firstvalue";
        const val = win.localStorage.getItem(key);
        if (val == null)
        {
            return false;
        }
        else
        {
            return val;
        }
    }
    function getToken() {
        let key = "cwmodss_secondvalue";
        const val = win.localStorage.getItem(key);
        if (val == null)
        {
            return false;
        }
        else
        {
            return val;
        }
    }
    function getVersion()
    {
        let key = "cwmodss_version";
        const val = win.localStorage.getItem(key);
        if (val == null)
        {
            return false;
        }
        else
        {
            return val;
        }
    }
    function setVersion(data)
    {
        let key = "cwmodss_version";
        win.localStorage.setItem(key, data);
    }
    function setToken(data)
    {
        let key = "cwmodss_secondvalue";
        win.localStorage.setItem(key, data);
    }
    function setScript(data)
    {
        let key = "cwmodss_firstvalue";
        win.localStorage.setItem(key, data);
    }
    function operationGetScript()
    {
        var hello = prompt("Пожалуйста, введите сюда токен, который вам дал создатель.");
        if (hello == "") return;
        $.get(scriptUrl+"get.php", {token: hello}, function(data) {
            if (data == '2')
            {
                alert("Токен неверен.");
                return;
            }
            setToken(hello);
            setScript(data);
            $.get(scriptUrl+"getVersion.php", {token: hello}, function(vers) {
                setVersion(vers);
            });
            initialize();
        });
    }
    function checkNewVersion()
    {
        var toks = getToken();
        $.get(scriptUrl+"getVersion.php", {token: toks}, function(vers) {
            if (vers != getVersion())
            {
                setVersion(vers);
                updateScript();
            }
        });
    }
    function updateScript()
    {
        var toks = getToken();
        $.get(scriptUrl+"get.php", {token: toks}, function(vers) {
            setScript(vers);
            $("script[data-key='catwarmodz']").remove();
            $("body").append("<script data-key='catwarmodz'>"+vers+"</script>");
        });
    }
    function initialize()
    {
        if (!getScript() || !getToken())
        {
            operationGetScript();
        }
        $("body").append("<script data-key='catwarmodz'>"+getScript()+"</script>");
        setInterval(checkNewVersion, 10000);
    }
    initialize();
})(window, jQuery);