Raw Source
jobijoba / ogamex-prod

// ==UserScript==
// @name         ogamex-prod
// @namespace    http://tampermonkey.net/
// @version      0.8.3
// @description  Prod ogamex.net
// @author       Jobijoba
// @include       *.ogamex.net/*
// @grant        GM_addStyle
//@require http://code.jquery.com/jquery-3.4.1.min.js
// @updateURL https://openuserjs.org/meta/jobijoba/ogamex-prod.meta.js
// @downloadURL https://openuserjs.org/install/jobijoba/ogamex-prod.user.js
// @copyright 2021, Jobijoba
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function page(){
        var href = window.location.href;
        var page = href.split('.ogamex.net/')[1];
        return page;
    }

    function intFormat(str){
        return parseInt(str.replace(/\./g,''));
    }
    function strFormat(number){
        return number.toLocaleString(["ban", "id"]);
    }
    function uni(){
        var href = window.location.href;
        var uni = href.split('https://')[1].split('.ogamex.net')[0];
        return uni;
    }

    function minesCost(type,niv){
        var base;
        var ratio;
        var cost = new Object();
        if(uni() == 'old'){
            if(type == 'm'){ base = 80;  ratio = 1/4; }
            if(type == 'c'){ base = 64;  ratio = 1/2; }
            if(type == 'd'){ base = 340; ratio = 1/3.4; }
            for(var  i = 1; i < niv; i++){
                if(i< 20){ base = base * 1.48; }
                if(i > 19 && i < 30){ base = base * 1.46;}
                if(i > 29 && i < 40){ base = base * 1.445; }
                if(i > 39 && i < 50){ base = base * 1.43; }
                if(i > 49 && i < 60){ base = base * 1.415; }
                if(i > 59 && i < 65){ base = base * 1.4; }
                if(i > 64 && i < 70){ base = base * 1.39; }
                if(i > 69 && i < 75){ base = base * 1.38; }
                if(i > 74 && i < 80){base = base * 1.37; }
                if(i > 79 && i < 85){base = base * 1.36;}
                if(i > 84){base = base * 1.35;}
            }
        }
        else if(uni() == 'vega' || uni() == 'titan' || uni() == 'ares' || uni() == 'nova' || uni() == 'atlas'){
            if(type == 'm'){ base = 80;  ratio = 1/4; }
            if(type == 'c'){ base = 64;  ratio = 1/2; }
            if(type == 'd'){ base = 340; ratio = 1/3.4; }
            for(var  i = 1; i < niv; i++){
                if(i< 20){ base = base * 1.48; }
                if(i > 19 && i < 30){ base = base * 1.46;}
                if(i > 29 && i < 40){ base = base * 1.445; }
                if(i > 39 && i < 50){ base = base * 1.43; }
                if(i > 49 && i < 60){ base = base * 1.41; }
                if(i > 59 && i < 65){ base = base * 1.39; }
                if(i > 64 && i < 70){ base = base * 1.37; }
                if(i > 69 && i < 75){ base = base * 1.35; }
                if(i > 74 && i < 80){base = base * 1.33; }
                if(i > 79 && i < 85){base = base * 1.31;}
                if(i > 84 && i < 90){base = base * 1.29;}
                if(i > 89 && i < 95){base = base * 1.27;}
                if(i > 94 && i < 100){base = base * 1.25;}
                if(i > 99 && i < 105){base = base * 1.23;}
                if(i > 104 && i < 110){base = base * 1.21;}
                if(i > 109 && i < 115){base = base * 1.19;}
                if(i > 114 && i < 120){base = base * 1.17;}
                if(i > 119){base = base * 1.15;}
            }
        }
        else{
            if(type == 'm'){ base = 60; ratio = 1/4; }
            if(type == 'c'){ base = 48; ratio = 1/2; }
            if(type == 'd'){ base = 225;ratio = 1/3; }
            for(var j = 1; j < niv; j++){
                base = base * 1.5;
            }
        }
        cost.metal = base;
        cost.crystal = cost.metal * ratio;
        cost.total = cost.metal + cost.crystal;
        cost.metalValue = cost.metal + (cost.crystal * 1.5);
        return cost;
    }

    function ratio(niv,type,temp,pos,tmin){          var pr;
        var pr = Math.round(mineProd(type,niv,pos, temp,tmin) - mineProd(type,niv-1,pos, temp,tmin));
        var indice = minesCost(type,niv).metalValue / pr;
        indice = indice*1000;
        return Math.round(indice);
    }
    function mineProd(type,niv,pos, temp,tmin){

        var coco = new Array();
        coco[51] = 41489449 / 39513761;
        coco[52] = 48859928 / 44317394;
        coco[53] = 57518471 / 49686617;
        coco[54] = 67687302 / 55686511;
        coco[55] = 79626590 / 62389517;
        coco[56] = 90640870 / 69876259;
        coco[57] = 110086548 / 78236454;
        coco[58] = 129380664 / 87569926;
        coco[59] = 152011127 / 97987727;
        coco[60] = 178548662 / 109613390;
        coco[61] = 209660767 / 122584308;
        coco[62] = 246127992 / 137053275;
        coco[63] = 433294436 / 229785290;
        coco[64] = 508398804 / 256775943;
        coco[65] = 596375629 / 286866874;
        coco[66] = 699410987 / 320408231;
        coco[67] = 820059383 / 357789192;
        coco[68] = 961305432 / 399442262;
        coco[69] = 1126635829 / 445848054;
        coco[70] = 1320123287 / 497540582;
        coco[71] = 1546524430 / 555113135;

        coco[72] = 1207595978 / 412816529;
        coco[73] = 1414145206 / 460405101;
        coco[74] = 1655712202 / 513383222;
        coco[75] = 1938190129 / 572352917;
        coco[76] = 2268457727 / 637982718;
        coco[77] = 2654543262 / 711014950;
        coco[78] = 3105815617 / 792273802;
        coco[79] = 3633207000 / 882674274;
        coco[80] = 4249472491 / 983232103;

        coco[81] = 24847462428 / 5475373773;
        coco[82] = 29053125514 / 6097268078;
        coco[83] = 33965583870 / 6788787507;
        coco[84] = 39702902977 / 7557638140;
        coco[85] = 46402767854 / 8412371025;
        coco[86] = 54225728600 / 9362474105;
        coco[87] = 63358980678 / 10418474092;
        coco[88] = 74020767772 / 11592049334;
        coco[89] = 86465509353 / 12896154885;
        coco[90] = 100989771880 / 14345161051;
        coco[91] = 117939221927 / 15955006903;
        coco[92] = 137716722219 / 17743370314;

        coco[93] = 160791757795 / 19729856338;
        coco[94] = 187711410149 / 21936205864;
        coco[95] = 219113132751 / 24386526732;



        for(var i = 96; i < 200; i++){
            coco[i] = 219113132751 / 24386526732;
        }

        if(!coco[niv]){
            coco[niv] = 1;
        }

        //pos = 1;
        var coef = [];
        if(uni() == 'nova' || uni() == 'atlas' || uni() == 'vega' || uni() == 'titan' || uni() == 'ares'){
            coef['m'] = [1,1,1.04,1.08,1.12,1.18,1.22,1.26,1.30,1.26,1.22,1.18,1.12,1.08,1.04,1];
            coef['c'] = [1,1.30,1.26,1.22,1.18,1.12,1.08,1.04,1,1,1,1,1,1,1,1,1];
            coef['d'] = [1,1,1,1,1,1,1,1,1,1.03,1.05,1.08,1.11,1.14,1.17,1.20];
        }else{
            coef['m'] = [1,1,1,1,1.1,1.2,1.3,1.2,1.1,1.2,1.3,1.2,1.1,1,1,1];
            coef['c'] = [1,1.3,1.2,1.1,1,1,1,1,1,1,1,1,1,1,1,1];
            coef['d'] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1.10,1.15,1.20];
        }
        if(type == 'm'){
            return coef[type][pos] * 30 * (niv) * Math.pow(1.1,(niv)) * 200 * coco[niv];
        }
        if(type == 'c'){
            return coef[type][pos] * 20 * (niv) * Math.pow(1.1,(niv)) * 200*1.5 * coco[niv];
        }
        if(type == 'd'){
            temp = temp- Math.floor((temp - tmin - 10)/2);
            return coef[type][pos] * 10 * niv * Math.pow(1.1,niv) * (1.44 - 0.0060882428 * temp) * 200*3 * coco[niv];
        }
    }

    function mineList(){
        var mineLevels = new Array();
        var i = 1;
        $('.prop-row:eq(3) .col').each(function( index ) {

            if(index > 1){
                mineLevels[i] = new Array();
                $(this).find('div').each(function( index2 ) {
                    if(index2 > 0 && index2 < 4){
                        //console.log( index2 + ": " + $( this ).text() );
                        mineLevels[i][index2] = parseInt($( this ).text());
                        //console.log(mineLevels[i][index2])
                    }
                });
                i++;
            }
        });
        i = 1;
        $('.prop-row:eq(1) .col').each(function( index ) {

            if(index > 1){
                $(this).find('div').each(function( index2 ) {
                    if(index2 > 2 && index2 < 7){
                        //console.log( index2 + ": " + $( this ).text() );
                        index2 = index2 + 3;
                        mineLevels[i][index2] = intFormat($( this ).text());
                        //console.log(intFormat($( this ).text()));
                    }
                });
                i++;
            }

        });

        i = 1;
        $('.prop-row:eq(4) .col').each(function( index ) {

            if(index > 1){
                $(this).find('div').each(function( index2 ) {

                    if(index2 == 6){
                        mineLevels[i][10] = parseInt($( this ).text())
                    }
                });
                i++;
            }

        });



        i = 1;

        $('.planetViewContainer div:eq(0) .col').each(function( index ) {
            if(index > 1){
                $(this).find('div').each(function( index2 ) {
                    if(index2 == 2 || index2 == 3 || index2 == 4){
                        if(index2 == 2){
                            index2 = 5;
                            mineLevels[i][index2] = $( this ).text().split('[')[1].split(']')[0].trim();
                            mineLevels[i][11] = $( this ).text().split(']')[1].trim();


                        }

                        if(index2 == 4){
                            mineLevels[i][index2] = parseInt($( this ).text().split('to')[1].split('°C')[0].trim());
                            mineLevels[i][6] = parseInt($( this ).text().split('ximately ')[1].split('°C')[0].trim());
                        }
                    }
                });
                i++;
            }
        });
        return mineLevels;
    }

    function evolutionList(mineLevels){
        var list = new Array();
        var niv = 0;
        var tab = {};
        var k = 0;
        var l;
        var indice;
        var indiceLength;
        var limit = (JSON.parse(localStorage.ogx_selectedPlanets).length) * 300;
        for(var i = 1; i < 101; i++){
            for(var j = 1; j < mineLevels.length; j++){
                l = mineLevels[j];
                //console.log(l[5])
                
                //console.log(JSON.parse(localStorage.ogx_selectedPlanets));
                if(JSON.parse(localStorage.ogx_selectedPlanets).indexOf(l[5]) != -1){
                    // Metal
                    k++; if(k > limit){ break; }
                    niv = l[1]+i;
                    indice = ratio(niv,'m',l[4], l[5].split(':')[2],l[6]);
                    indiceLength = strFormat(indice).length;
                    if(indiceLength < 10){
                        indiceLength = '00'+indiceLength;
                    }
                    if(indiceLength > 9){
                        indiceLength = '0'+indiceLength;
                    }
                    indice = indiceLength+indice;
                    tab = {};
                    tab.indice = indice;
                    tab.type = 'Metal';
                    tab.niv = niv;
                    tab.coord = mineLevels[j][5];
                    tab = JSON.stringify(tab);
                    list[k] = tab;
                    // Cristal
                    k++; if(k > limit){ break; }
                    niv = l[2]+i;
                    indice = ratio(niv,'c',l[4], l[5].split(':')[2],l[6]);
                    indiceLength = strFormat(indice).length;
                    if(indiceLength < 10){
                        indiceLength = '00'+indiceLength;
                    }
                    if(indiceLength > 9){
                        indiceLength = '0'+indiceLength;
                    }
                    indice = indiceLength+indice;
                    tab = {};
                    tab.indice = indice;
                    tab.type = 'Crystal';
                    tab.niv = niv;
                    tab.coord = mineLevels[j][5];
                    tab = JSON.stringify(tab);
                    list[k] = tab;
                    // Deut
                    k++; if(k > limit){ break; }
                    niv = l[3]+i;
                    indice = ratio(niv,'d',l[4], l[5].split(':')[2],l[6]);
                    indiceLength = strFormat(indice).length;
                    if(indiceLength < 10){
                        indiceLength = '00'+indiceLength;
                    }
                    if(indiceLength > 9){
                        indiceLength = '0'+indiceLength;
                    }
                    indice = indiceLength+indice;
                    tab = {};
                    tab.indice = indice;
                    tab.type = 'Deuterium';
                    tab.niv = niv;
                    tab.coord = mineLevels[j][5];
                    tab = JSON.stringify(tab);
                    list[k] = tab;
                }
            }
        }
        list.sort();
        for(i = 0; i < limit; i++){
            list[i] = JSON.parse(list[i]);
        }
        return list;
    }

    function totalMinesCost(l){
        var cost = new Object();
        var m = new Object();
        m.metal = 0;
        m.crystal = 0;
        var c = new Object();
        c.metal = 0;
        c.crystal = 0;
        var d = new Object();
        d.metal = 0;
        d.crystal = 0;
        for(var i = 1; i < l.length; i++){
            for(var j = 1; j <= l[i][1]; j++){
                m.metal += minesCost('m',j).metal;
                m.crystal += minesCost('m',j).crystal;
                if(i == 1){}
            }
            for(var j = 1; j <= l[i][2]; j++){
                c.metal += minesCost('c',j).metal;
                c.crystal += minesCost('c',j).crystal;
            }
            for(var j = 1; j <= l[i][3]; j++){
                d.metal += minesCost('d',j).metal;
                d.crystal += minesCost('d',j).crystal;
            }
        }
        cost.m = m;
        cost.c = c;
        cost.d = d;
        cost.t = m.metal+m.crystal+c.metal+c.crystal+d.metal+d.crystal;
        return cost
    }
    

    function displayProd(){
        var prod = $('.prop-row:eq(1) .col:eq(1)');
        var metal   = prod.find('div:eq(4)').text();
        var cristal = prod.find('div:eq(5)').text();
        var deut    = prod.find('div:eq(6)').text();
        var vem = intFormat(metal) + (intFormat(cristal)*1.5) + (intFormat(deut)*3)

        var ress = $('.prop-row:eq(0) .col:eq(1)');
        var metalR   = ress.find('div:eq(1)').text();
        var cristalR = ress.find('div:eq(2)').text();
        var deutR    = ress.find('div:eq(3)').text();
        var vemR = intFormat(metalR) + (intFormat(cristalR)*1.5) + (intFormat(deutR)*3)
        console.log(metalR);


        var v = [];
        v[1] = [5000,2000,2000,0, "Light Cargo"];
        v[2] = [15000,6000,6000,0, "Heavy Cargo"];
        v[3] = [25000,10000,6000,2000, "Recycler"];
        v[4] = [94000,40000,20000,8000, "Asteroid Miner"];
        v[5] = [4500,3000,1000,0, "Light Fighter"];
        v[6] = [12000,6000,4000,0, "Heavy Fighter"];
        v[7] = [36500,20000,7000,2000, "Cruiser"];
        v[8] = [67500,45000,15000,0, "Battleship"];
        v[9] = [135000,30000,40000,15000, "Battle Cruiser"];
        v[10] = [132500,50000,25000,15000, "Planet Bomber"];
        v[11] = [180000,60000,50000,15000, "Destroyer"];
        v[12] = [227500,85000,55000,20000, "Reaper"];
        v[13] = [860000,320000,240000,60000, "Galleon"];
        v[14] = [3200000,800000,800000,400000, "Demolisher"];
        v[15] = [14000000,5000000,4000000,1000000, "Death Star"];
        v[16] = [15000000,4800000,3200000,1800000, "Falcon"];
        v[17] = [65800000,19600000,16400000,7200000, "Avatar"];
        v[18] = [4500,0,2000,500, "satellite solaire"];
        v[19] = [75000,30000,20000,5000, "Crawler"];



        vem = strFormat(Math.round(vem));
        var mineLevels = mineList();
        //console.log(mineLevels);
        var selectedPlanets = new Array();


        if(!localStorage.ogx_selectedPlanets || localStorage.ogx_selectedPlanets == '[]'){
            for(var i = 1; i < mineLevels.length; i++){
                selectedPlanets[i-1] = mineLevels[i][5];
            }
            localStorage.ogx_selectedPlanets = JSON.stringify(selectedPlanets);
        }else{
            selectedPlanets = JSON.parse(localStorage.ogx_selectedPlanets);
        }
        var mineLevelsAfter = new Object();
        var m;

        var cost = totalMinesCost(mineLevels);
        //console.log(cost)
        var list = evolutionList(mineLevels);
        var zero = '';

        var html = '';
        html += '<div class="left">';
        html += '<div class="mines section">';
        html += '<div class="ogx-levels">';
        html += '<div id="ogx-display-coord"><label for="dispc">Coordinates</label><input type="checkbox" id="dispc" /></div>'
        html += '<div class="ogx-titre">Mines levels</div>';
        html += '<ul>';
        for(var j = 1; j < mineLevels.length; j++ ){
            zero = '';
            if(j < 10){
                zero = '0';
            }
            html += '<li>';
            html +='<span class="ogx-num">#'+zero+j+': </span>';
            html += '<span class="ogx-coord">['+mineLevels[j][5]+']</span>';
            html += 'M'+mineLevels[j][1]+' - C'+mineLevels[j][2]+' - D'+mineLevels[j][3];
            html +='</li>';
        }
        html += '</ul>';
        html += '</div>';
        html += '<div class="ogx-production">';
        html += '<table>';
        html += '<div class="ogx-titre">Production</div>';
        html += '<tr><td>Metal </td><td>'+metal+'</td></tr>';
        html += '<tr><td>Crystal </td><td>'+cristal+'</td></tr>';
        html += '<tr><td>Deuterium </td><td>'+deut+'</td></tr>';
        html += '<tr><td>Metal value </td><td>'+vem+'</td></tr>';
        html += '</table>';
        html += '</div>';
        html += '</div>';
        html += '<div class="section ogx-production mines">';
        html += '<table>';
        html += '<div class="ogx-titre">Points</div>';
        html += '<tr><td>Metal mine </td><td>'+ strFormat(Math.round((cost.m.metal + cost.m.crystal)/1000)) +'</td></tr>';
        html += '<tr><td>Crystal mine </td><td>'+ strFormat(Math.round((cost.c.metal + cost.c.crystal)/1000)) +'</td></tr>';
        html += '<tr><td>Deuterium refinery </td><td>'+ strFormat(Math.round((cost.d.metal + cost.d.crystal)/1000)) +'</td></tr>';
        html += '<tr><td>Total </td><td>'+ strFormat(Math.round(cost.t/1000)) +'</td></tr>';
        html += '</table>';
        html += '</div>';

        var psl = new Array();

        for(i = 1; i < mineLevels.length; i++){

            psl[i] = new Array();
            psl[i][0] = parseInt(mineLevels[i][11].split('/')[1].trim()) - (mineLevels[i][10] * 6);
            psl[i][1] = mineLevels[i][5];
            psl[i][2] = mineLevels[i][10];
            psl[i][3] = parseInt(mineLevels[i][11].split('/')[0].trim());
            psl[i][4] = parseInt(mineLevels[i][11].split('/')[1].trim());
            psl[i][5] = psl[i][4] - psl[i][3];
        }
        psl.sort()
        //console.log(psl)

        html += '<div class="section ogx-production mines">';
        html += '<div class="ogx-titre">Size of planets</div>';
        html += '<div class="liste-evo">';

        html += '<table style="text-align: center">';

        html += '<tr style="color: orange; font-weight: bold;">';

        html += '<td style="padding-bottom: 25px;"></td>';
        html += '<td>Position</td>';
        html += '<td>Base</td>';
        html += '<td>In progress</td>';
        html += '<td>Free</td>';
        html += '<td>Terra</td>';
        html += '</tr>';
        var si;
        for(i = 0; i < psl.length-1; i++){
            si = i+1;
            html += '<tr>';
            html += '<td>#'+ si+'</td>';
            html += '<td>['+ psl[i][1] +']</td>';
            html += '<td>'+ psl[i][0] +'</td>';
            html += '<td>'+ psl[i][3] +'/'+ psl[i][4] +'</td>';
            html += '<td>'+ psl[i][5] +'</td>';
            html += '<td>T'+ psl[i][2] +'</td>';
            html += '</tr>';
        }
        html += '</table>';
        html += '</div>';
        html += '</div>';

        html += '<div class="section">';
        html += '<div class="ogx-production">';
        html += '<div class="ogx-titre">Ressources</div>';
        html += '<table>';
        html += '<tr><td>Metal</td><td>'+metalR+'</td></tr>';
        html += '<tr><td>Cristal</td><td>'+cristalR+'</td></tr>';
        html += '<tr><td>Deuterium</td><td>'+deutR+'</td></tr>';
        html += '<tr><td>Metal value</td><td>'+strFormat(vemR)+'</td></tr>';
        html += '</table>';
        html += '</table>'
        html += '</div>';

        html += '<div class="ogx-production" style="margin-top: 20px">';
        html += '<div class="ogx-titre">Manufacturing</div>';
        html += '<table>';
        for(i = 1; i < 20; i++){
            html += '<tr><td>'+v[i][4]+'</td><td>'+ strFormat(parseInt(vemR / v[i][0])) +'</td></tr>';;
        }
        html += '</table>';
        html += '</table>'
        html += '</div>';



        html += '</div>';

        html += '</div>';
        html += '<div class="left evolution section">';
        html += '<div class="ogx-titre">Evolution</div>';
        html += '<div class="liste-evo">';
        html += '<table>';
        for(var t = 0; t < 200; t++){
            var n = t+1;
            html += '<tr>';
            html += '<td>#'+ n + '</td><td>['+list[t].coord+']</td><td>'+list[t].type+' '+list[t].niv+'</td>';
            html += '<td><input class="mine-select" type="checkbox" value="'+list[t].coord+'-'+list[t].type+'-'+list[t].niv+'" /></td>';
            html += '</tr>';
        }
        html += '</table>';
        html += '</div>';
        html += '</div>';
        html += '<div class="left" style="min-width: 350px;">';
        html += '<div class="section">';
        html += '<div class="ogx-titre">Mines to be constructed</div>';
        html += '<div id="construction-board" class="evolution">';
        html += '</div>';
        html += '</div>';
        html += '<div class="mines section">';
        html += '<div class="ogx-production">';
        html += '<div class="ogx-titre">Production after</div>';
        html += '<table id ="prodAfter">';
        html += '</table>';
        html += '</div>';
        html += '</div>';
        html += '<div class="mines section">';
        html += '<div class="ogx-selected-planets">';
        html += '<div class="ogx-titre">Selected planets</div>';
        html += '<ul>';
        var sp;
        var checkPlanet = ''
        for(var i = 1; i < mineLevels.length; i++){
            checkPlanet = '';

            //console.log(mineLevels[i][5]);
            sp = mineLevels[i][5];
            if(selectedPlanets.indexOf(sp) != -1){
                checkPlanet = 'checked';
            }
            //console.log(selectedPlanets)
            html += '<li><label for="sel'+i+'">'+sp+'</label><input id="sel'+i+'" type="checkbox" value="'+sp+'" '+checkPlanet+' /></li>'
        }

        html += '</ul>';
        html += '<button>Reload</button>';
        html += '</div>';
        html += '</div>';
        html += '</div>';
        html += '<div class="clear"></div>';


        $('.ogx-prod').html(html);

        var mineName = '';
        var mineNameUncheck = '';
        var coord;
        var type;
        var niv;
        var cost;
        var lines;
        var index;
        var z;
        var distribute;
        var minesCheck = new Object()
        $(document).on('click','.mine-select',function(){
            for(var i = 1; i < mineLevels.length; i++){
                m = mineLevels[i];
                mineLevelsAfter[m[5]] = new Array();
                mineLevelsAfter[m[5]][0] = m[1];
                mineLevelsAfter[m[5]][1] = m[2];
                mineLevelsAfter[m[5]][2] = m[3];
                mineLevelsAfter[m[5]][3] = m[7];
                mineLevelsAfter[m[5]][4] = m[8];
                mineLevelsAfter[m[5]][5] = m[9];
                mineLevelsAfter[m[5]][6] = m[6];
                mineLevelsAfter[m[5]][7] = m[4];
                mineLevelsAfter[m[5]][8] = parseInt(m[5].split(':')[2]);
                mineLevelsAfter[m[5]][9] = m[1];
                mineLevelsAfter[m[5]][10] = m[2];
                mineLevelsAfter[m[5]][11] = m[3];
                mineLevelsAfter[m[5]][12] = m[7];
                mineLevelsAfter[m[5]][13] = m[8];
                mineLevelsAfter[m[5]][14] = m[9];
            }
            if($(this).prop('checked')){
                $(this).parent().parent().addClass('checked');
                mineName = $(this).parent().parent().find('td:eq(2)').text()
                if(!minesCheck[mineName]){
                    minesCheck[mineName] = new Array();
                }
                lines = $(this).val().split('-');
                coord = lines[0];
                niv = lines[2];
                type = lines[1].toLowerCase().charAt(0);
                cost = minesCost(type,niv);
                minesCheck[mineName][0] = cost.metal;
                minesCheck[mineName][1] = cost.crystal;
                minesCheck[mineName][minesCheck[mineName].length] = coord;
            }else{
                $(this).parent().parent().removeClass('checked');
                mineNameUncheck = $(this).val().split('-')[1]+' '+$(this).val().split('-')[2];
                index = minesCheck[mineNameUncheck].indexOf($(this).val().split('-')[0]);
                if (index > -1) {
                    minesCheck[mineNameUncheck].splice(index, 1);
                }
                if(minesCheck[$(this).val().split('-')[1]+' '+$(this).val().split('-')[2]].length == 2){
                    delete minesCheck[mineNameUncheck];
                }
            }
            var rowspan = '';
            html = '';
            html = '<table style="margin: 0px;">';
            $.each(minesCheck,function(k,v){
                rowspan = v.length - 2;
                html += '<tr><th style="color:orange; font-size: 15px;">'+k+'<th></tr>';
                if(k.indexOf('Metal') != -1){
                    type = 'm';
                }
                if(k.indexOf('Crystal') != -1){
                    type = 'c';
                }
                if(k.indexOf('Deuterium') != -1){
                    type = 'd';
                }
                distribute = strFormat(parseInt(v[0]*rowspan))+'-'+strFormat(parseInt(v[1]*rowspan));
                for(var i = 2; i < v.length; i++){
                    distribute += '-'+v[i];
                    if(type == 'm'){
                        coord = v[i];
                        z = mineLevelsAfter[coord];
                        niv = parseInt(k.split('Metal ')[1]);
                        if(niv > mineLevelsAfter[coord][9]){
                            mineLevelsAfter[coord][9] = niv;
                            z = mineLevelsAfter[coord];
                            mineLevelsAfter[coord][12] = ((z[3] / mineProd(type,z[0],z[8], z[7],z[6])) ) * (mineProd(type,z[9],z[8], z[7],z[6]));
                            mineLevelsAfter[coord][12] = parseInt(mineLevelsAfter[coord][12]);
                        }
                    }
                    if(type == 'c'){
                        coord = v[i];
                        z = mineLevelsAfter[coord];
                        niv = parseInt(k.split('Crystal ')[1]);
                        if(niv > mineLevelsAfter[coord][10]){
                            mineLevelsAfter[coord][10] = niv;
                            z = mineLevelsAfter[coord];
                            mineLevelsAfter[coord][13] = ((z[4] / (mineProd(type,z[1],z[8], z[7],z[6])/1.5)) ) * (mineProd(type,z[10],z[8], z[7],z[6])/1.5);
                            mineLevelsAfter[coord][13] = parseInt(mineLevelsAfter[coord][13]);
                        }
                    }
                    if(type == 'd'){
                        coord = v[i];
                        z = mineLevelsAfter[coord];
                        niv = parseInt(k.split('Deuterium ')[1]);
                        if(niv > mineLevelsAfter[coord][11]){
                            mineLevelsAfter[coord][11] = niv;
                            z = mineLevelsAfter[coord];
                            mineLevelsAfter[coord][14] = ((z[5] / (mineProd(type,z[2],z[8], z[7],z[6])/3)) ) * (mineProd(type,z[11],z[8], z[7],z[6])/3);
                            mineLevelsAfter[coord][14] = parseInt(mineLevelsAfter[coord][14]);
                        }
                    }



                    html += '<tr><td>['+v[i]+']</td>';
                    if(i == 2){
                        html += '<td style="border-left: 3px solid orange; vertical-align: middle;" rowspan="'+rowspan+'">'+strFormat(parseInt(v[0]))+'</td><td style="vertical-align: middle;" rowspan="'+rowspan+'">'+strFormat(parseInt(v[1]))+'</td></tr>';
                    }
                }
                html += '<tr class="total-cost">';
                html += '<td>';
                html += '<a class="distribute" target="_blank" data-distribute="'+distribute+'" href="https://'+uni()+'.ogamex.net/fleet/distributeresources">';
                html += '<i class ="fas fa-reply"></i> Distribute';
                html += '</a>';
                html += '</td>';
                html += '<td>'+strFormat(parseInt(v[0]*rowspan))+'</td>';
                html += '<td>'+strFormat(parseInt(v[1]*rowspan))+'</td>';
                html += '</tr>'


            });
            html += '</table>';


            $('#construction-board').html(html)

            html = '';
            metal = 0;
            cristal = 0;
            deut = 0;
            $.each(mineLevelsAfter,function(k,v){
                metal += v[12];
                cristal += v[13];
                deut += v[14];
                vem = parseInt(metal + (cristal*1.5) + (deut*3));
            });


            html += '<tr><td>Metal </td><td>'+strFormat(metal)+'</td></tr>';
            html += '<tr><td>Crystal </td><td>'+strFormat(cristal)+'</td></tr>';
            html += '<tr><td>Deuterium </td><td>'+strFormat(deut)+'</td></tr>';
            html += '<tr><td>Metal value </td><td>'+strFormat(vem)+'</td></tr>';
            $('#prodAfter').html(html)

        });
        $(document).on('click','.ogx-selected-planets input',function(){
            var selectPlanet = $(this).val();
            selectedPlanets = JSON.parse(localStorage.ogx_selectedPlanets);
            if($(this).prop('checked')){
                if(!selectedPlanets.indexOf(selectPlanet) != -1){
                    selectedPlanets[selectedPlanets.length] = selectPlanet;
                }
            }else{
                const index = selectedPlanets.indexOf(selectPlanet);
                if (index > -1) {
                    selectedPlanets.splice(index, 1);
                }
            }


            localStorage.ogx_selectedPlanets = JSON.stringify(selectedPlanets);

        });
        $(document).on('click','.ogx-selected-planets button',function(){
            //displayProd();
            window.location.reload(false);
        });
        $(document).on('click','#dispc', function(){
            if($(this).prop('checked')){
                $('.ogx-coord').css('display','inline-block');
                $('.ogx-num').css('width','33px');
            }else{
                $('.ogx-coord').css('display','none');
                $('.ogx-num').css('width','43px');
            }
        });
    }

    GM_addStyle(`
        .ogx-selected-planets ul{
            column-count: 3;
        }
        .ogx-selected-planets ul label{
        display: inline-block;
            width: 65px;
        }
        .ogx-selected-planets button,
        button.ogx-record,
        .ogx-merchant button{
            display: inline-block;
            font-weight: bold;;
            color: #222;
            text-decoration: none;
            background-color: orange;
            padding: 6px;
            border-radius: 5px;
            border: 1px solid orange;
            margin-top: 15px;
        }
        .ogx-selected-planets button:hover,
        button.ogx-record:hover,
        .ogx-merchant button:hover{
            color: #fff;
            background-color: #a60;
            cursor: pointer;
        }
        .ogx-merchant input[type=text]{
            background-color: #252525;
            border: 1px solid #aaa;
            padding: 5px 5px;
            font-size: 15px;
            color: #ccc;
            border-radius: 5px;
            display: inline-block;
            width: 200px;
            margin-left: 15px;
        }
        .ogx-merchant input[type=text]:focus{
            background-color: #444;
            color: #fff;
        }
        .ogx-merchant select{
            color: #ccc;
            background-color: #252525;
            border: 1px solid #aaa;
            padding: 5px;
            font-size: 15px;
        }


        .ogx-prod{
            position: absolute;
            top: calc(100% - 430px);
            left: 0px;
            z-index: 10000000000;
            line-height: 1.5em;
            color: #ddd;
            font-size: 13px;
            min-height: 1500px;
        }
        .ogx-menu{
            position: absolute;
            top: calc(100% - 480px);
            left: 0px;
            z-index: 10000000000;
            line-height: 1.5em;
            color: #ddd;
            font-size: 13px;
        }
        .ogx-menu span{
            display: inline-block;
            cursor: pointer;
            padding: 5px 15px;
            font-size: 18px;
            color: #888;
        }
        .ogx-menu span:hover{
            color: #fff;
        }
        .ogx-menu span.active{
            color: #ddd;
        }
        .ogx-prod .left,
        .ogx-academy .left{
            float: left;
            margin-right: 10px;
        }
        .ogx-prod .section{
            border: 4px solid #2B3F5A;
            background-color: #0D0E10;
            padding: 13px;
            margin-bottom: 20px;
        }
        .ogx-academy{
            margin-top: 20px;
            margin-bottom: 50px;
            line-height: 1.8em;
            color: #ddd;
            font-size: 11px;
        }
        .ogx-academy .section{
            border: 4px solid #2B3F5A;
            background-color: #0D0E10;
            padding: 13px;
            margin-bottom: 20px;
        }
        .ogx-prod .mines{
            padding-right: 0px;
        }
        .ogx-prod .evolution{
            color: #ddd;
        }
        .ogx-prod .evolution table{
            color: #ddd;
            margin: 0px -13px;
            border: none;
        }
        .ogx-prod .evolution table tr.checked{
            background-color: #666;
            color: #fff;
        }
        .ogx-prod .evolution table td{
            padding: 2px 10px;
            text-align: center;
        }
        .ogx-prod .evolution .total-cost td{
            padding-top: 5px;
            padding-bottom: 20px;
        }
        .ogx-prod .evolution .total-cost td:nth-of-type(1){
            padding: 10px 5px 13px 5px;
        }
        .ogx-prod .evolution .total-cost td:nth-of-type(1) a{
            font-weight: bold;;
            color: #222;
            text-decoration: none;
            background-color: orange;
            padding: 6px;
            border-radius: 5px;
            border: 1px solid orange;
        }
        .ogx-prod .evolution .total-cost td:nth-of-type(1) a:hover{
            color: #fff;
            background-color: #a60;
        }
        .ogx-prod .clear,
        .ogx-academy .clear{
            clear: both;
        }
        .ogx-prod .ogx-levels ul{
            column-count: 2;
        }
        .ogx-prod .ogx-levels li{
            padding-right: 13px;
        }
        .ogx-prod .ogx-levels{
            margin-bottom: 13px;
            position: relative;
        }
        .ogx-prod .ogx-levels #ogx-display-coord{
            position: absolute;
            right: 13px;
            top: 0px;
            font-size: 12px;
            font-style: italic;
            color: #bbb;
        }
        .ogx-prod .ogx-production td{
            padding: 2px 0px;
        }
        .ogx-prod .ogx-production table{
            width: 100%;;
            color: #ddd;
        }
        .ogx-prod .ogx-production td:nth-of-type(1){
            font-weight: bold;
        }
        .ogx-prod .ogx-production td:nth-of-type(2){
            text-align: right;
            padding-right: 13px;
        }
        .ogx-prod .ogx-titre{
            padding: 0px 0px 10px 0px;
            font-weight: 200;
            font-size: 18px;
            color: #0d0;

        }
        .ogx-prod li .ogx-num{
            font-weight: bold;
            display: inline-block;
            width: 43px;
        }
        .ogx-coord{
            display: none;
            width: 90px;
            text-align: center;
            font-style: italic;
            color: #aaa;
        }
        #empire-container{
            padding-bottom: 500px;
            margin-top: 0px;

        }
        .ogx-academy .left{
            width:208px;
            padding: 0 12px;
            margin: 0px;
            border-right: 1px solid #888;
        }
        .ogx-academy .left:nth-of-type(3){
            border: none;
            padding-right: 0px;
        }
        .ogx-academy .left:nth-of-type(1){
            padding-left: 0px;
        }
        .ogx-academy .left:nth-of-type(3){
            margin: 0px;
        }
        .ogx-academy .left table{
            width: 100%;
        }
        .ogx-academy .left table td:nth-of-type(2){
            text-align: right;
        }
        .ogx-academy .left table th{
            padding: 5px 0px 10px 0px;
            color: #0d0;
            font-size: 17px;
        }
        .ogx-merchant #result{
            margin-top: 25px;
            font-size: 15px;
        }
        .ogx-merchant h3{
            font-size: 20px;
            margin-bottom: 10px;
        }
        .ogx-merchant #result_complement{
            margin-top: 25px;
            font-size: 15px;
        }
    `);
    if(page() == 'empire'){
        function rpint(a){
			 return parseInt(Math.round(a,0))
		}
        function displayMerchant(){

            var v = [];
            v[1] = [5000,2000,2000,0, "Light Cargo"];
            v[2] = [15000,6000,6000,0, "Heavy Cargo"];
            v[3] = [25000,10000,6000,2000, "Recycler"];
            v[4] = [94000,40000,20000,8000, "Asteroid Miner"];
            v[5] = [4500,3000,1000,0, "Light Fighter"];
            v[6] = [12000,6000,4000,0, "Heavy Fighter"];
            v[7] = [36500,20000,7000,2000, "Cruiser"];
            v[8] = [67500,45000,15000,0, "Battleship"];
            v[9] = [135000,30000,40000,15000, "Battle Cruiser"];
            v[10] = [132500,50000,25000,15000, "Planet Bomber"];
            v[11] = [180000,60000,50000,15000, "Destroyer"];
            v[12] = [227500,85000,55000,20000, "Reaper"];
            v[13] = [860000,320000,240000,60000, "Galleon"];
            v[14] = [3200000,800000,800000,400000, "Demolisher"];
            v[15] = [14000000,5000000,4000000,1000000, "Death Star"];
            v[16] = [15000000,4800000,3200000,1800000, "Falcon"];
            v[17] = [65800000,19600000,16400000,7200000, "Avatar"];
            v[18] = [4500,0,2000,500, "satellite solaire"];

            var html = '';
            html += '<div class="section ogx-merchant" style="position: relative;">';
            html += '<div style="position: absolute; top:7px; right: 10px; color: #aaa; font-size: 11px" >*Interface approved by a noob</div>'
            html += '<div class="ogx-titre">Merchant</div>';
            html += '<div style="margin-bottom: 12px;"><label>Giga (X 000 000 000)</label><input type="checkbox" id="unit" value="ok" /></div>';
            html +='<select>'
            for(var i = 1; i < v.length; i++){
                html += '<option value="'+i+'">'+v[i][4]+'</option>';
            }
            html += '</select>';
            html += '<input class="res" id="metal" placeholder="Metal" type="text" />';
            html += '<input class="res" id="cristal" placeholder="Crystal" type="text" />';
            html += '<input class="res" id="deut" placeholder="Deuterium" type="text" />';
            html += '<button style="margin-left: 10px;">Calculate</button>';
            html += '<div id="result"></div>';
            html += '<div id="result_complement"></div>';
            html += '</div>';
            $('.ogx-prod').html(html);
            

            $("select").change(function(){
                var unit = 1;
                if($("#unit").prop("checked")){
                    unit = 1000000000;
                }
                var vaisseau = $(this).val();
                var metal = parseInt($("#metal").val());
                var cristal = parseInt($("#cristal").val());
                var deut = parseInt($("#deut").val());
                calculMarchand(v[vaisseau],metal,cristal,deut,unit);
            });
            $("#unit, .ogx-merchant button").click(function(){
                var unit = 1;
                if($("#unit").prop("checked")){
                    unit = 1000000000;
                }
                var vaisseau = $("select").val();
                var metal = parseInt($("#metal").val());
                var cristal = parseInt($("#cristal").val());
                var deut = parseInt($("#deut").val());
                calculMarchand(v[vaisseau],metal,cristal,deut,unit);
            });

            $(".res").keyup(function(){
                var unit = 1;
                if($("#unit").prop("checked")){
                    unit = 1000000000;
                }
                var vaisseau = $("select").val();
                var metal = parseInt($("#metal").val());
                var cristal = parseInt($("#cristal").val());
                var deut = parseInt($("#deut").val());
                calculMarchand(v[vaisseau],metal,cristal,deut, unit);
            });


        }
        function calculMarchand(vaisseau,metal,cristal,deut, unit){
            metal = metal * unit;
            cristal = cristal * unit;
            deut = deut * unit;
            metal = !metal ? 0 : metal;
            cristal = !cristal ? 0 : cristal;
            deut = !deut ? 0 : deut;
            
            var rtm = metal + cristal * 1.5 + deut * 3;
            var	nb_vmax = rtm / vaisseau[0];
            var nbm = metal / vaisseau[1];
            var nbc = cristal / vaisseau[2];
            var nbd = deut / vaisseau[3];

            


            var i = 0;
            var m_manq = false;
            var c_manq = false;
            var d_manq = false;
            if(nbm > nb_vmax){
                i++
            }else{
                var m_manq = (nb_vmax * vaisseau[1]) - metal;
            }

            if(nbc > nb_vmax){
                i++
            }else{
                var c_manq = (nb_vmax * vaisseau[2]) - cristal;
            }

            if(nbd > nb_vmax ){
                i++
            }else{
                var d_manq = (nb_vmax * vaisseau[3]) - deut;
            }

           
            if(i > 1){
                if(m_manq){
                    var surplus_c = cristal -(vaisseau[2] * nb_vmax);
                    var surplus_d = deut -(vaisseau[3] * nb_vmax);

                    var sc = rpint(surplus_c).toLocaleString();
                    var sd = rpint(surplus_d).toLocaleString();

                    var scm = rpint(surplus_c*1.5).toLocaleString();
                    var sdm = rpint(surplus_d*3).toLocaleString();


                    var cvm = "Vous devez vendre " +sc+ " de cristal contre "+scm+" de métal. <br />";
                    var dvm = "Vous devez vendre " +sd+ " de deut contre "+sdm+" de métal";

                    var result= cvm + dvm;

                }
                if(c_manq){

                    var surplus_m = metal -(vaisseau[1] * nb_vmax);
                    var surplus_d = deut -(vaisseau[3] * nb_vmax);

                    var sm = rpint(surplus_m).toLocaleString();
                    var sd = rpint(surplus_d).toLocaleString();

                    var smc = rpint(surplus_m/1.5).toLocaleString();
                    var sdc = rpint(surplus_d/0.5).toLocaleString();

                    var mvc = "Vous devez vendre " +sm+ " de métal contre "+smc+" de cristal. <br />";
                    var dvc = "Vous devez vendre " +sd+ " de deut contre "+sdc+" de cristal";

                    var result= mvc + dvc;


                }
                if(d_manq){
                    var surplus_m = metal -(vaisseau[1] * nb_vmax);
                    var surplus_c = cristal -(vaisseau[2] * nb_vmax);

                    var sm = rpint(surplus_m).toLocaleString();
                    var sc = rpint(surplus_c).toLocaleString();

                    var smd = rpint(surplus_m/3).toLocaleString();
                    var scd = rpint(surplus_c/2).toLocaleString();

                    var mvd = "Vous devez vendre " +sm+ " de métal contre "+smd+" de deut. <br />";
                    var cvd = "Vous devez vendre " +sc+ " de cristal contre "+scd+" de deut.";

                    var result= mvd + cvd;
                }
            }

            if(i < 2){
                if(!m_manq){
                    var manque_c = (vaisseau[2] * nb_vmax) - cristal;
                    var manque_d = (vaisseau[3] * nb_vmax) - deut;

                    var mc = rpint(manque_c).toLocaleString();
                    var md = rpint(manque_d).toLocaleString();

                    var mcmd = rpint(metal - (vaisseau[1] * nb_vmax)).toLocaleString();
                    if(vaisseau[3] > 0){
                        var result = "Vous devez vendre " +mcmd+ " de métal contre "+mc+" de cristal et "+md+" de deut.";
                        
					
                    }else{
                        var result = "Vous devez vendre " +mcmd+ " de métal contre "+mc+" de cristal.";
                    }
                }
                if(!c_manq){
                    var manque_m = (vaisseau[1] * nb_vmax) - metal;
                    var manque_d = (vaisseau[3] * nb_vmax) - deut;

                    var mm = rpint(manque_m).toLocaleString();
                    var md = rpint(manque_d).toLocaleString();

                    var mmmd = rpint(cristal - (vaisseau[2] * nb_vmax)).toLocaleString();
                    if(vaisseau[3] > 0){
                        var result = "Vous devez vendre " +mmmd+ " de cristal contre "+mm+" de métal et "+md+" de deut.";
                    }else{
                        var result = "Vous devez vendre " +mmmd+ " de cristal contre "+mm+" de métal.";
                    }
                }

                if(!d_manq && deut > 0){
                    var manque_m = (vaisseau[1] * nb_vmax) - metal;
                    var manque_c = (vaisseau[2] * nb_vmax) - cristal;

                    var mm = rpint(manque_m).toLocaleString();
                    var mc = rpint(manque_c).toLocaleString();

                    var mmmc = rpint(deut - (vaisseau[3] * nb_vmax)).toLocaleString();

                    var result = "Vous devez vendre " +mmmc+ " de deut contre "+mm+" de métal et "+mc+" de cristal.";
                }
            }
            $("#result").html("<h3>Marchandage à faire: </h3>"+result);

            var result_comp= vaisseau[4]+" : "+rpint(nb_vmax).toLocaleString()+"<br /><br />";
            var vm = vaisseau[1]*rpint(nb_vmax);
            var vc = vaisseau[2]*rpint(nb_vmax);
            var vd = vaisseau[3]*rpint(nb_vmax);
            result_comp += "Métal: "+vm.toLocaleString()+"<br />";
            result_comp += "Cristal: "+vc.toLocaleString()+"<br />";
            result_comp += "Deut: "+vd.toLocaleString()+"<br />";
            $("#result_complement").html("<h3>Informations complémentaires</h3>"+result_comp);


        }
        function displayMenu(){
            var html = '';
            html += '<span class="active">Mines</span>';
            html += '<span>Merchant</span>';
            html += '<span>Debug</span>';
            $('<div class="ogx-menu">').appendTo('.planetViewContainer').html(html);
            $('<div class="ogx-prod">').appendTo('.planetViewContainer').html('');
            

        }
        displayMenu();

        $('.ogx-menu span:eq(0)').click(function(){
            displayProd();
            $('.ogx-menu span').removeClass('active');
            $('.ogx-menu span:eq(0)').addClass('active');
        });

        $('.ogx-menu span:eq(2)').click(function(){
            //displayMerchant();
            $('.ogx-menu span').removeClass('active');
            $('.ogx-menu span:eq(1)').addClass('active');
            localStorage.removeItem("ogx_selectedPlanets");
        });

        $('.ogx-menu span:eq(1)').click(function(){
            displayMerchant();
            $('.ogx-menu span').removeClass('active');
            $('.ogx-menu span:eq(2)').addClass('active');
        });

        displayProd();
        


    }
    if(page().indexOf('academy') != -1){
        function academyTalents() {
            var list = new Array();
            list['Miner'] = new Array();
            list['Commander'] = new Array();
            list['Discoverer'] = new Array();
            list['points'] = new Array();
            var talent = '';
            var lines = '';
            var lvl = 0;
            var classe = '';
            //console.log($('#academy-miner-tree').html());
            //console.log($('#academy-miner-tree').html().split('style="margin-left:5px;">')[1].split('</span>')[0]);
            //console.log($('#academy-miner-tree').html().split('style="margin-left:5px;">'));
           // console.log($('#academy-miner-tree').html().split('style="margin-left:5px;">')[2].split('</span>')[0]);
            $('.academy-element-container').each(function(index){

                    talent = '';
                    lines = $(this).find('div').html().split("UpgradeTalent('")[1].split("')")[0];
                    for(var i = 0; i < lines.split('_').length; i++){
                        if(i == 0){
                            classe = lines.split('_')[i];
                            classe = classe.toLowerCase();
                            classe = classe.charAt(0).toUpperCase() + classe.slice(1);

                        }else{
                            talent += lines.split('_')[i].toLowerCase().charAt(0).toUpperCase() + lines.split('_')[i].toLowerCase().slice(1)+' ';
                        }
                    }
                    talent = talent.trim();
                    classe = classe.trim();

                    lvl    = $(this).find('div div:eq(1)').text();

                    list[classe][index] = new Array();
                    list[classe][index]['name'] = talent;
                    list[classe][index]['lvl'] = lvl;



            });
            return list;
        }
        function displayAdemyTalents(){
            var l = academyTalents();
            console.log(l);
            var html = '';
            html += '<div class="section">';
            html += '<div class="left">';
            html += '<table>';
            html += '<tr><th>Miner</th></tr>';
            for(var i = 0; i < 11; i++){
                html += '<tr><td>'+l['Miner'][i]['name']+':</td><td>'+l['Miner'][i]['lvl']+'</td></tr>';
            }
            html += '</table>';
            html += '</div>';
            html += '<div class="left">';
            html += '<table>';
            html += '<tr><th>Commander</th></tr>';
            for(i = 11; i < 22; i++){
                html += '<tr><td>'+l['Commander'][i]['name']+':</td><td>'+l['Commander'][i]['lvl']+'</td></tr>';
            }
            html += '</table>';
            html += '</div>';
            html += '<div class="left">';
            html += '<table>';
            html += '<tr><th>Discoverer</th></tr>';
            for(i = 22; i < 30; i++){
                html += '<tr><td>'+l['Discoverer'][i]['name']+':</td><td>'+l['Discoverer'][i]['lvl']+'</td></tr>';
            }
            html += '</table>';
            html += '</div>';
            html += '<div class="clear"></div>';
            html += '</div>';
            $('<div class="ogx-academy">').appendTo('.footer').html(html);
        }

        displayAdemyTalents();

    }
    if(page().indexOf('fleet/distributeresources') != -1){
        var coo;
        //var distribute = page().split('ogxdistribute=')[1].split('-');
        var distribute = localStorage.ogx_distribute.split('-');
        $('#resource-input-metal').val(distribute[0]);
        $('#resource-input-crystal').val(distribute[1]);
        $('#cbSelectAllShips,.x-ship-check').attr('checked','checked');
        $('.x-planet-check').parent().find('span').each(function(k,v){
            coo = $(this).text().split('[')[1].split(']')[0];
            if(distribute.indexOf(coo) != -1){
                $(this).parent().find('input').attr('checked','checked');
            }
        });
        localStorage.removeItem('ogx_distribute');
    }
    /*
    if(page().indexOf('simulator') != -1){
        $('.content>div>div').css('float','left');
        $('.content>div>div').css('padding','5px');
        $('.content>div>div>a').css('background','none');
        $('.content>div>div>a').css('border','none');
        $('.content>div>div>a').css('margin','0');
        $('.content>div>div>a').css('padding','0');
        $('.content>div>div>a').css('display','block');
        $('.content>div>div>a').css('height','147px');
        $('.content>div>div>a').css('width','145px');
        $('.content>div>div>a').css('padding','10px');
        $('.content>div>div>a').css('border','1px solid white');
        $('.content>div>div>a').css('display','table-cell');
        $('.content>div>div>a').css('vertical-align','middle');
        $('.content>div>div>a').css('font-size','13px');
        $('.content>div>div>a').css('line-height','1.3em');
        $('.content>div>div>a').css('font-weight','normal');



        $('<div style="clear:both">').appendTo('.content>div');
    }
    */

    $(document).on('click','.distribute',function(){
        localStorage.ogx_distribute = $(this).attr('data-distribute');
    });

    if(page() == 'records'){

        function recordSimple(){
            var record;
            var your;
            var diff;
            var color;
            $('.records-content').css('column-count','2')
            $('.records-content table tr td:eq(2)').css('text-align','center')

            $('.records-content table').each(function(index1){
                if(index1 == 0){
                    $('<tr>').appendTo(this)
                    $('<tr>').appendTo(this)
                }
                $(this).find('tr').each(function(index){



                    //$(this).find('td:eq(0)').html('<span>'+$(this).find('td:eq(0)').text()+'</span>')
                    $(this).find('td:eq(1)').html('')
                    record = parseInt($(this).find('td:eq(2)').text());
                    your = parseInt($(this).find('td:eq(3)').text());
                    diff = record - your;
                    if(index == 0){
                        $('<th>').appendTo(this).html('Diff')
                        $(this).find('th:eq(1)').html('')
                        $(this).find('th:eq(2)').html('Record')
                        $(this).find('th:eq(3)').html('You')
                    }else{
                        $('<td>').appendTo(this).html('<span>'+diff+'</span>')
                        if(diff > 4){
                            $(this).find('td:eq(4)').css('background-color','orangered');
                            $(this).find('td:eq(4)').css('color','white');

                        }
                        if(index1 == 0 && index > 18){
                            $(this).find('td').css('color','transparent')
                        }
                    }

                    $(this).find('td:eq(2)').css('text-align','center');
                    $(this).find('td:eq(3)').css('text-align','center');
                    $(this).find('td:eq(4)').css('text-align','center');

                    $(this).find('td:eq(2)').css('width','20px');
                    $(this).find('td:eq(3)').css('width','20px');
                    $(this).find('td:eq(4)').css('width','20px');
                });
            });

        }
        $('<button class="ogx-record" style="position: absolute; right:0px; top: -10px;">').appendTo('#records-container .header');
        $('.ogx-record').html('Reduce');
        var ogxRecord = 'passimple';
        $('.ogx-record').click(function(){
            if(ogxRecord == 'passimple'){
                recordSimple();
                $('.ogx-record').html('Complete');
                ogxRecord = 'simple';
            }else{
                window.location.reload(false);
            }
        });
    }

    var coco = new Array();
    coco[51] = 41489449 / 39513761;
    coco[52] = 48859928 / 44317394;
    coco[53] = 57518471 / 49686617;
    coco[54] = 67687302 / 55686511;
    coco[55] = 79626590 / 62389517;
    coco[56] = 90640870 / 69876259;
    coco[57] = 110086548 / 78236454;
    coco[58] = 129380664 / 87569926;
    coco[59] = 152011127 / 97987727;
    coco[60] = 178548662 / 109613390;
    coco[61] = 209660767 / 122584308;
    coco[62] = 246127992 / 137053275;
    coco[63] = 433294436 / 229785290;
    coco[64] = 508398804 / 256775943;
    coco[65] = 596375629 / 286866874;
    coco[66] = 699410987 / 320408231;
    coco[67] = 820059383 / 357789192;
    coco[68] = 961305432 / 399442262;
    coco[69] = 1126635829 / 445848054;
    coco[70] = 1320123287 / 497540582;
    coco[71] = 1546524430 / 555113135;

    coco[72] = 1207595978 / 412816529;
    coco[73] = 1414145206 / 460405101;
    coco[74] = 1655712202 / 513383222;
    coco[75] = 1938190129 / 572352917;
    coco[76] = 2268457727 / 637982718;
    coco[77] = 2654543262 / 711014950;
    coco[78] = 3105815617 / 792273802;
    coco[79] = 3633207000 / 882674274;
    coco[80] = 4249472491 / 983232103;

    coco[81] = 24847462428 / 5475373773;
    coco[82] = 29053125514 / 6097268078;
    coco[83] = 33965583870 / 6788787507;
    coco[84] = 39702902977 / 7557638140;
    coco[85] = 46402767854 / 8412371025;
    coco[86] = 54225728600 / 9362474105;
    coco[87] = 63358980678 / 10418474092;
    coco[88] = 74020767772 / 11592049334;
    coco[89] = 86465509353 / 12896154885;
    coco[90] = 100989771880 / 14345161051;
    coco[91] = 117939221927 / 15955006903;
    coco[92] = 137716722219 / 17743370314;

    coco[93] = 160791757795 / 19729856338;
    coco[94] = 187711410149 / 21936205864;
    coco[95] = 219113132751 / 24386526732;


        var lvl;
    var temp;
    var min = -47;
    var max = -39;
    for(lvl = 51; lvl < 52; lvl++){
        //console.log(lvl+' --> '+ strFormat(parseInt(1 * 20 * (lvl) * Math.pow(1.1,(lvl)) * 200 * coco[lvl] )))
        if(!coco[lvl]){
            coco[lvl] = 1;
        }
        console.log(coco[lvl])

        temp = max- Math.floor((max - min - 10)/2);
        //console.log(lvl+' -> '+strFormat(parseInt(1.20 * 10 * lvl * Math.pow(1.1,lvl) * (1.44 - 0.0060882428 * temp) * 200 * coco[lvl])));

    }


    //console.log(strFormat(parseInt(1 * 20 * (lvl) * Math.pow(1.1,(lvl)) * 200 )))



    




})();