PlanForUs / naskille

// ==UserScript==
// @name         naskille
// @namespace    https://ru.waysofhistory.com/
// @version      0.1
// @description  try to take over the world!
// @author       rteert
// @match        https://*.waysofhistory.com/gen/html/*
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var $ = unsafeWindow.jQuery;
    if (!$) {
        return;
    }

    if (!unsafeWindow.tabEconomicsMoney) {
        // Некорректная страница, либо несовместимая версия
        console.info('govno');
        return;
    }
    console.info(unsafeWindow);
    var targ=document.getElementsByClassName('tab-wrp economics-stock-wrp')[0];
    installButtonHook();
    function addButtons() {
        var saveTacticsContainer = $('.js-saveTactic').parent();
        if (saveTacticsContainer.length > 0) {
            if (saveTacticsContainer.find('.tactics-addon-export-btn').length === 0) {
                saveTacticsContainer.prepend($('<button class="button1 tactics-addon-import-btn"/>').text("По нубски сделанный метод сдачи отчета - пуск").on('click', naskille));

            }
        }
    }

    function installButtonHook() {
        var original_afterShow = tabTacticsEdit.prototype.afterShow;

        tabTacticsEdit.prototype.afterShow = function () {
            original_afterShow.apply(this, arguments);
            addButtons();
        };
        if (global.console) {
            global.console.log('Export Tactics addon installed');
        }
    }
    function naskille(){
        var acc={
            'army':{'list':[]},
            'armytraining':{'list':[]},
            'assistant':wofh.account.assistant,
            'assistfor':[],
            'country':{'id':wofh.account.country.id,'name':wofh.account.country.name},
            'id':wofh.account.id,
            'name':wofh.account.name,
            'money':wofh.account.money,
            'pop':wofh.account.pop,
            'race':wofh.account.race,
            'sex':wofh.account.sex,
            'specialists':{'list':wofh.account.specialists.list},
            'townslist':wofh.account.townslist,
            'vote':wofh.account.vote,
            'allstreams':[],
            'allbarters':[],
            'time':0
        };
        function setListArm(from, to) {
            let alo=Object.keys(from.list)
            for(let elem of alo){
                to.list.push(({'id':from.list[elem].id, 'count':from.list[elem].count}))
            }
        }
        setListArm(wofh.account.army, acc.army)
        setListArm(wofh.account.armytraining, acc.armytraining)
        if(wofh.account.assistfor!=null){
            let lb=Object.keys(wofh.account.assistfor);
            for(let elem of lb){
                acc.assistfor.push({'id':wofh.account.assistfor[elem].id,'name':wofh.account.assistfor[elem].name});
            }
        }
        var towns=[];
        var townslo=Object.keys(wofh.towns);
        for(let idt of townslo){
            let town={
                'army':{
                    'free':{'list':[]},
                    'intown':{'list':[]},
                    'own':{'list':[]},
                    'sum':{'list':[]},
                    'training':{'list':[]}
                },
                'bonus':{'real':wofh.towns[idt].bonus.real},
                'budget':{},
                'budgetSum':wofh.towns[idt].budgetSum,
                'buildings':[],
                'climate':wofh.towns[idt].climate,
                'country':wofh.towns[idt].country,
                'id':wofh.towns[idt].id,
                'name':wofh.towns[idt].name,
                'deposit':{'climate':wofh.towns[idt].deposit.climate,'id':wofh.towns[idt].deposit.id,'res':wofh.towns[idt].deposit.res},
                'pop':wofh.towns[idt].pop,
                'pos':wofh.towns[idt].pos,
                'race':wofh.towns[idt].race,
                'slots':{'list':[]},
                'specialists':{'list':wofh.towns[idt].specialists.list},
                'stock':{'max':wofh.towns[idt].stock.max,'list':[],'foodpriority':wofh.towns[idt].stock.foodpriority},
                'taxes':wofh.towns[idt].taxes,
                'terrain':wofh.towns[idt].terrain,
                'traders':wofh.towns[idt].traders,
                'work':wofh.towns[idt].work,
                'streams':[],
                'barters':[],
                'time':wofh.towns[idt].time
            };
            acc.time=wofh.towns[idt].time;
            setListArm(wofh.towns[idt].army.free, town.army.free);
            setListArm(wofh.towns[idt].army.intown, town.army.intown);
            setListArm(wofh.towns[idt].army.own, town.army.own);
            setListArm(wofh.towns[idt].army.sum, town.army.sum);
            setListArm(wofh.towns[idt].army.training, town.army.training);
            for(let elem of Object.keys(wofh.towns[idt].budget)){
                town.budget[elem]={};
                for(let elem2 of Object.keys(wofh.towns[idt].budget[elem])){
                    if(elem2){
                        town.budget[elem][elem2]=wofh.towns[idt].budget[elem][elem2];
                    }
                }
            }
            for(let elem of Object.keys(wofh.towns[idt].buildings)){
                town.buildings.push(wofh.towns[idt].buildings[elem]);
            }
            for(let elem of Object.keys(wofh.towns[idt].slots.list)){
                town.slots.list.push({
                    'id':wofh.towns[idt].slots.list[elem].id,
                    'level':wofh.towns[idt].slots.list[elem].level,
                    'pos':wofh.towns[idt].slots.list[elem].pos,
                    'active':wofh.towns[idt].slots.list[elem].active,
                    'needPay':wofh.towns[idt].slots.list[elem].needPay
                });
            }
            for(let elem of Object.keys(wofh.towns[idt].stock.list)){
                town.stock.list[elem]={};
                for(let elem2 of Object.keys(wofh.towns[idt].stock.list[elem])){
                    if(elem2!='town' && elem2!='account' && elem2!='lib' && elem2!='country'){
                        town.stock.list[elem][elem2]=wofh.towns[idt].stock.list[elem][elem2];
                        // town.stock.list.push({(elem.toString()):{elem2:wofh.towns[idt].stock.list[elem][elem2]}});
                    }
                }
            }
            // for (let i = 0; i < 200; i++) {
            //     if(wofh.towns[idt].bonus.real[i]!=null){
            //         town.bonus.real.push({(""+i):wofh.towns[idt].bonus.real[i]})
            //     }
            // }
            towns.push(town);
        }
        for(let i=0;i<1000000;i++){
            if(wofh.streams.list[i]!=null){
                for(let el of towns){
                    if(el.id==wofh.streams.list[i].town1 || el.id==wofh.streams.list[i].town2){
                        let obj={};
                        for(let ellems of Object.keys(wofh.streams.list[i])){
                            if(ellems!='town' && ellems!='account' && ellems!='lib' && ellems!='country' && ellems!='countries'&& ellems!='towns' && ellems!='accounts'){
                                obj[ellems]=wofh.streams.list[i][ellems];
                            }
                        }
                        el['streams'].push(obj);
                        acc.allstreams.push(obj);
                    }
                }
            }
        }
        for(let i=0;i<1000000;i++){
            if(wofh.barterOffers.list[i]!=null){
                for(let el of towns){
                    if(el.id==wofh.barterOffers.list[i].town){
                        let obj={};
                        for(let ellems of Object.keys(wofh.barterOffers.list[i])){
                            if( ellems!='account' && ellems!='lib' && ellems!='country' && ellems!='countries'&& ellems!='towns' && ellems!='accounts'){
                                obj[ellems]=wofh.barterOffers.list[i][ellems];
                            }
                        }
                        el['barters'].push(obj);
                        acc.allbarters.push(obj);
                    }
                }
            }
        }
        var repAll=[acc, towns];
        copy(JSON.stringify(repAll));

    }
    // Your code here...
})();