Greasy Fork

New Userscript

try to take over the world!

目前为 2020-11-07 提交的版本。查看 最新版本

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       AlegreVida
// @match        https://s46-tr.ikariam.gameforge.com/?view=city*
// @match        https://s46-tr.ikariam.gameforge.com/?view=island*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function fnc_BuildingsTableListener(){

        function fnc_BuildingsTable(){
            if($('#js_tab_premiumTradeAdvisorBuildings').hasClass('selected')){

                //var city = {name:"", id:"", link:"", buildings:(new Array(30)) };
                //var building = {lvl:0, status:0, link:""};

                var cities = new Array($('.table01:first tr').length-1);
                var cityPNG = 'skin/layout/city.png';

                var buildingCounter = 0;

                var allBuildings = new Array(30);
                for (var x = 1; x <= $('#buildingsOverview .table01').length; x++){
                    for (var y = 2; y <= $('#buildingsOverview .table01:nth-of-type('+x+') tr.headingrow th').length; y++){
                        var th = $('#buildingsOverview .table01:nth-of-type('+x+') tr.headingrow th:nth-of-type(' + y + ')');
                        allBuildings[buildingCounter] = { title:$(th).attr('title'), src:$(th).find('img').attr('src') };
                        buildingCounter = buildingCounter + 1;
                    }
                }

                console.log("Length of AllBuildings: " + allBuildings.length);

                buildingCounter = 0;

                for(var a = 2; a <= $('#buildingsOverview .table01:first tr').length; a++){
                    var link = $('#buildingsOverview .table01:first tr:nth-of-type(' + a + ') a');
                    var href = $('#buildingsOverview .table01:first tr:nth-of-type(' + a + ') a').attr('href');
                    var city = {
                        name:link.text(),
                        link:href,
                        id:href.slice(href.lastIndexOf('=')+1, href.length),
                        buildings:new Array(30)
                    };
                    cities[a-2] = city;
                }

                for(var i = 1; i <= $('#buildingsOverview .table01').length; i++){
                    var table = $('#buildingsOverview .table01:nth-of-type(' + i + ')');
                    for(var j = 2; j <= $(table).find('tr').length; j++){
                        var row = $(table).find('tr:nth-of-type(' + j + ')');
                        for(var k = 1; k <= $(row).find('td').length; k++){
                            var td = $(row).find('td:nth-of-type(' + k + ')');
                            var buildingLink = $(row).find('td:nth-of-type(' + k + ') a');
                            var flag = $(buildingLink).length > 0 ? true : false;
                            var build = {
                                lvl: flag ? $(buildingLink).text() : "-",
                                link: flag ? $(buildingLink).attr('href') : null,
                                status:0
                            };



                            if($(td).find('div.upgrade').length > 0){
                                build.status = 1;
                            }else if($(td).find('div.upgradeList').length > 0){
                                build.status = 2;
                            }

                            cities[j-2].buildings[(i-1)*5 + k-1] = build;
                        };
                    };
                }

                //var upgradeHTML = '<td class="building"><div class="upgradeList"><a href="?view=city&dialog=' + keyword + '&cityId=' + cityId + '" class">' + cityLvl + '<span>' + timeText + '</span></a></div></td>';
                //var upgradeListHTML = '<td class="building"><div class="upgrade"><a href="?view=city&dialog=' + keyword + '&cityId=' + cityId + '">' + cityLvl + '<span>' + timeText + '</span></a></div></td>';


                while($('#buildingsOverview .content .table01').length > 1){
                    $('#buildingsOverview .content .table01:last').remove();
                }

                while($('#buildingsOverview .content .table01 tr:first th').length > 1){
                    $('#buildingsOverview .content .table01 tr:first th:last').remove();
                }

                for(var i2 = 2; i2 <= $('#buildingsOverview .content .table01 tr').length; i2++){
                    while($('#buildingsOverview .content .table01 tr:nth-of-type(' + i2 + ') td').length > 0){
                        $('#buildingsOverview .content .table01 tr:nth-of-type(' + i2 + ') td:last').remove();
                    }
                }


                var z = 0;
                while(z <= 29){
                    $('#buildingsOverview .content .table01:first tr:nth-of-type(1)').append('<th class="building" title="' + allBuildings[z].title + '"><img width="28px" src="' + allBuildings[z].src + '" alt="' + allBuildings[z].title + '" title="' + allBuildings[z].title + '"></th>');
                    z++;
                }

                for(var w = 2; w <= $('#buildingsOverview .content:first .table01:first tbody tr').length; w++){
                    var v = 0;
                    while(v <= 29){
                        if(cities[w-2].buildings[v].status == 0){
                            if(cities[w-2].buildings[v].link == null){
                                $('#buildingsOverview .content:first .table01:first tr:nth-of-type(' + w + ')').append('<td class="building">-</td>');
                            }else{
                                $('#buildingsOverview .content:first .table01:first tr:nth-of-type(' + w + ')').append('<td class="building"><a href="' + cities[w-2].buildings[v].link + '" title="' + cities[w-2].buildings[v].name + '">'+ cities[w-2].buildings[v].lvl +'</a></td>');
                            }
                        }else if(cities[w-2].buildings[v].status == 1){
                            $('#buildingsOverview .content:first .table01:first tr:nth-of-type(' + w + ')').append('<td class="building"><div class="upgrade"><a href="' + cities[w-2].buildings[v].link + '">' + cities[w-2].buildings[v].lvl + '</a></div></td>');
                        }else if(cities[w-2].buildings[v].status == 2){
                            $('#buildingsOverview .content:first .table01:first tr:nth-of-type(' + w + ')').append('<td class="building"><div class="upgradeList"><a href="' + cities[w-2].buildings[v].link + '">' + cities[w-2].buildings[v].lvl + '</a></div></td>');
                        }
                        v = v+1;
                    }
                }

                $('#premiumTradeAdvisorBuildings').css("width", "auto");
                $('.mainContentScroll:first').css("width", "auto");
                $('#buildingsOverview').css("width", "auto");
                $('#premiumTradeAdvisorBuildings>div.mainHeader').css("background-position-x", "center");
                $('.mainContentScroll:first').css("height", "");
                $('#premiumTradeAdvisorBuildings_c').css("left", "75px");
                $('#premiumTradeAdvisorBuildings_c').css("top", "250px");
                $('#premiumTradeAdvisorBuildings_c').css("right", "auto");
                $('#premiumTradeAdvisorBuildings_c').css("z-index", "98");

                $('#premiumTradeAdvisorBuildings ul.tabmenu').css("width", "100%");

                $('#js_backlinkButton').css("left", "780px");
                $('#premiumTradeAdvisorBuildings div.close').css("left", "800px");
                //$('#buildingsOverview .content').append('<table class="table01"><tbody></tbody></table>');

                $('#premiumTradeAdvisorBuildings>div.mainContentScroll>div.mainContent>div.center').remove();
                //$('#premiumTradeAdvisor>div.mainContentScroll>div.mainContent>div.center').remove();

                for(var zz = 2; zz <= $('#buildingsOverview .content:first .table01:first tr.headingrow th').length; zz++){
                    //$('#buildingsOverview .content:first .table01:first tr.headingrow th:nth-of-type('+zz+') img').css("width", "30px");
                }

            }
        };

        $('buildingsOverview .table01:nth-of-type(2) tr:nth-of-type(8) td:nth-of-type(4) .upgrade').text();

        var params_BuildingsTable = {
            id: 'premiumTradeAdvisorBuildings',
            parent: document.querySelector('body'),
            recursive: false,
            done: function() {
                fnc_BuildingsTable();
            }
        };

        new MutationObserver(function(mutations) {
            params_BuildingsTable.done();
        }).observe(params_BuildingsTable.parent || document, {
            childList: true
        });
    };
    fnc_BuildingsTableListener();
    // Your code here...
})();