Raw Source
Le_Mulet / easy farm

// ==UserScript==
// @name         easy farm
// @namespace    https://openuserjs.org/users/Le_Mulet
// @license MIT
// @version      0.2
// @description  try to take over the world!
// @author       You
// @copyright 2023, Le_Mulet (https://openuserjs.org/users/Le_Mulet)
// @match        https://*.ogame.gameforge.com/game/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gameforge.com
// @updateURL 		https://openuserjs.org/install/Le_Mulet/easy_farm.min.user.js
// @downloadURL		https://openuserjs.org/install/Le_Mulet/easy_farm.min.user.js
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';
    /*css*/
    const ef_css =
 `
 #easy_farm_table {
    right: -120px;
    background: rgb(13, 16, 20);
    padding-bottom: 40px;
    text-align: center;
 }

 .easy_farm_title {
    font-weight: 700;
    font-size: 11px;
    color: rgb(161, 161, 161);
 }

 .easy_farm_target {
     margin-top: 7px;
 }

 .target_yes {
   color: green !important;
 }

 .target_no {
   color: red !important;
 }

 .target_maybe {
   color: yellow !important;
 }

 div#spy_report_overview {
    text-align: center;
    margin: 5px 0;
    width: 626px;
    overflow: auto;
}
.easy_farm_attack_link {
color:yellow !important;
}

#ef_menu {
    position: relative;
    z-index: 2;
    margin-top: 2px;
    margin-bottom: 5px;
    width: 667px;
    background-color: #0d1014;
    border: 1px solid #000000;
    float: left;
}

#ef_menu_header {
    background: url(https://gf1.geo.gfsrv.net/cdn63/10e31cd5234445e4084558ea3506ea.gif) no-repeat 0 0 #0d1014;
}

.ef_menu_header_title {
    padding: 0;
    text-align: center;
    color: #6f9fc8;
    font-size: 13px;
    font-weight: 700;
    line-height: 28px;
}

#ef_menu_header_credit {
    font-size: 10px;
    font-style: italic;
    font-weight: 200;
    color: rgb(253, 138, 28) !important;
}

#ef_menu_header_button {
    padding: 10px 0 25px;
    height: 30px;
}

#ef_menu_header_button a.ef_menu_button {
    padding: 3px 5px;
}

#ef_btn_cancel {
    float:left;
    width:30%;
}

#ef_btn_save {
    float:right;
    width:30%;
}

.ef_menu_section_header {
    font-weight: 700;
    color: #6f9fc8;
    height: 22px;
    line-height: 22px;
    margin-bottom: 2px;
    border: 1px solid #000000;
    border-radius: 5px;
    background: #161a1f;
    text-align: center;
}

.ef_ship_icon {
width: 26px;
height: 26px;
min-width: 26px;
background-position-y: -3441px;
}

.ef_menu_section_ships_container {
    display:flex;
    margin: 10px;
    margin-left: 5%;
}

.flex {
    display:flex;
}

.ef_input {
    margin: 10px;
}

.ef_input_description {
    line-height: 45px;
    margin-left: 5%;
}

.ef_spy_table_row {
display: flex;
}

.ef_link_container {
display: flex;
justify-content: space-around;
width: -webkit-fill-available;
}

.ef_link_container>a {
line-height: 26px;
}

 `
    GM_addStyle(ef_css);
    var user_id = document.querySelector('head meta[name="ogame-player-id"]').getAttribute('content');
    var options = GM_getValue(window.location.host+user_id+'options') || {
        ships: {
            202: {activated: false, speed: 10, id:202},
            203: {activated: false, speed: 10, id:203},
            204: {activated: false, speed: 10, id:204},
            205: {activated: false, speed: 10, id:205},
            206: {activated: false, speed: 10, id:206},
            207: {activated: false, speed: 10, id:207},
            210: {activated: false, speed: 10, id:210, name:'probs'},
            211: {activated: false, speed: 10, id:211},
            213: {activated: false, speed: 10, id:213},
            214: {activated: false, speed: 10, id:214},
            215: {activated: false, speed: 10, id:215},
            218: {activated: false, speed: 10, id:218},
            219: {activated: false, speed: 10, id:219}
        },
        min_plunder: 10000,
        min_fleet: 10000
    };
    // set up easy farm buttons -> open options menu
    {
        function closeEfOptions () {
            document.querySelector('#ef_menu').remove();
            let middle_childs = document.querySelector('#middle').childNodes;
            for (let node of middle_childs) {
                node.hidden = false;
            }
        }
        function saveEfOptions () {
            options.min_plunder = +document.querySelector('#af_option_min_plunder_input').value;
            let ships = document.querySelectorAll('.ef_menu_section_ships_container');
            for (let s of ships) {
                let id = s.getAttribute('data-id');
                options.ships[id].activated = s.querySelector('input').checked;
                options.ships[id].speed = +s.querySelector('select').value;
            }
            GM_setValue(window.location.host+user_id+'options', options);
            document.querySelector('#ef_menu').remove();
            let middle_childs = document.querySelector('#middle').childNodes;
            for (let node of middle_childs) {
                node.hidden = false;
            }
        }
        function openEfOptions () {
            let middle_childs = document.querySelector('#middle').childNodes;
            for (let node of middle_childs) {
                node.hidden = true;
            }
            let option_container = document.createElement('div');
            option_container.id = 'ef_menu';
            document.querySelector('#middle').insertBefore(option_container, document.querySelector('#middle').firstChild);

            let container_header = document.createElement('div');
            container_header.id = 'ef_menu_header';
            option_container.appendChild(container_header);

            let menu_header_title = document.createElement('div');
            menu_header_title.classList.add('ef_menu_header_title');
            menu_header_title.innerText = "Options Easy Farm - "+GM_info.script.version;
            container_header.appendChild(menu_header_title);

            let menu_header_credit = document.createElement('div');
            menu_header_credit.id = 'ef_menu_header_credit';
            menu_header_credit.innerText = 'by Le Mulet';
            menu_header_title.appendChild(menu_header_credit);

            let menu_header_button = document.createElement('div');
            menu_header_button.id = 'ef_menu_header_button';
            container_header.appendChild(menu_header_button);

            let btn_cancel = document.createElement('a');
            btn_cancel.id = 'ef_btn_cancel';
            btn_cancel.classList.add('btn_blue');
            btn_cancel.classList.add('ef_menu_button');
            btn_cancel.innerText = 'Cancel';
            btn_cancel.onclick = function () {closeEfOptions();};
            btn_cancel.href = "javascript:void(0)";
            menu_header_button.appendChild(btn_cancel);

            let btn_save = document.createElement('a');
            btn_save.id = 'ef_btn_save';
            btn_save.classList.add('btn_blue');
            btn_save.classList.add('ef_menu_button');
            btn_save.innerText = 'Save';
            btn_save.onclick = function () {saveEfOptions();};
            btn_save.href = "javascript:void(0)";
            menu_header_button.appendChild(btn_save);

            let menu_content = document.createElement('div');
            option_container.appendChild(menu_content);

            let menu_section_general = document.createElement('div');
            menu_section_general.id = 'menu_section_general';
            menu_content.appendChild(menu_section_general);

            let menu_section_general_header = document.createElement('div');
            menu_section_general_header.classList.add('ef_menu_section_header');
            menu_section_general_header.innerText = 'General';
            menu_section_general.appendChild(menu_section_general_header);

            let min_plunder_container = document.createElement('div');
            min_plunder_container.classList.add('flex');
            menu_section_general.appendChild(min_plunder_container);

            let min_plunder_text = document.createElement('div');
            min_plunder_text.classList.add('ef_input_description');
            min_plunder_text.innerText = 'min plunder';
            min_plunder_container.appendChild(min_plunder_text);

            let min_plunder_input = document.createElement('input');
            min_plunder_input.id = 'af_option_min_plunder_input';
            min_plunder_input.classList.add('ef_input');
            min_plunder_input.type = 'text';
            min_plunder_input.value = options.min_plunder ? options.min_plunder : 10000;
            min_plunder_container.appendChild(min_plunder_input);

            let menu_section_ship = document.createElement('div');
            menu_section_ship.id = 'menu_section_ship';
            menu_content.appendChild(menu_section_ship);

            let menu_section_ship_header = document.createElement('div');
            menu_section_ship_header.classList.add('ef_menu_section_header');
            menu_section_ship_header.innerText = 'Ships';
            menu_section_ship.appendChild(menu_section_ship_header);

            for (let id in options.ships) {
                let s = options.ships[id];
                let ship_container = document.createElement('div');
                ship_container.classList.add('ef_menu_section_ships_container');
                ship_container.setAttribute('data-id', s.id);
                menu_section_ship.appendChild(ship_container);

                let checkbox = document.createElement('input');
                checkbox.type = 'checkbox';
                checkbox.checked = s.activated;
                ship_container.appendChild(checkbox);

                let img = document.createElement('div');
                img.classList.add('sprite');
                img.classList.add('ef_ship_icon');
                console.log((s.id - 202));
                img.style.backgroundPositionX = ((s.id>215 ? s.id-2 : s.id) - 202) * (-28)+'px';
                ship_container.appendChild(img);

                let speed = document.createElement('select');
                ship_container.appendChild(speed);

                for (let i = 10; i > 0; --i) {
                    let speed_option = document.createElement('option');
                    speed_option.value = i;
                    speed_option.selected = s.speed == i;
                    speed_option.innerText = i*10+'%';
                    speed.appendChild(speed_option);
                }

                /*let name = document.createElement('div');
                name.innerText = fleetDispatcher.fleetHelper.shipsData[s.id].name;
                ship_container.appendChild(name);*/
            }
        }

        let easy_farm_btn_container = document.createElement('li');
        let easy_farm_btn = document.createElement('a');
        let easy_farm_btn_txt = document.createElement('span');
        let easy_farm_icon = document.createElement('span');
        easy_farm_icon.classList.add('menu_icon');
        easy_farm_btn_txt.classList.add('textlabel');
        easy_farm_btn_txt.innerText = 'Easy Farm';
        easy_farm_btn.href = "javascript:void(0)";
        easy_farm_btn.onclick = function () { openEfOptions(); };
        easy_farm_btn.classList.add('menubutton');
        easy_farm_btn.appendChild(easy_farm_btn_txt);
        easy_farm_btn_container.appendChild(easy_farm_icon);
        easy_farm_btn_container.appendChild(easy_farm_btn);
        document.querySelector('#menuTableTools').appendChild(easy_farm_btn_container);
    }

    let data = {};
    data.page = new URL(window.location.href).searchParams.get('component') || new URL(window.location.href).searchParams.get('page');
    let user_coord = (document.querySelector('.smallplanet.hightlightPlanet') || document.querySelector('.smallplanet.hightlightMoon') || document.querySelector('.smallplanet')).querySelector('.planetlink .planet-koords').textContent.slice(1,-1).replaceAll(':','_');
    let targets = GM_getValue(window.location.host+user_id+'targets') || {};
    targets[user_coord] = targets[user_coord] ? targets[user_coord] : {};
    let nowDate = new Date();
    if (data.page == 'fleetdispatch') GM_setValue(window.location.host+user_id+'shipsData', fleetDispatcher.fleetHelper.shipsData);
    data.shipsData = GM_getValue(window.location.host+user_id+'shipsData') || {};
    function addTargetorChangeTargetStatus (coord, spyed=0, attacked=0) {
        if (targets[user_coord][coord] === undefined) targets[user_coord][coord] = {status:1,spyed:spyed,attacked:attacked};
        else if (targets[user_coord][coord].status == -1) delete targets[user_coord][coord];
        else targets[user_coord][coord].status = (targets[user_coord][coord].status+2)%3-1;
        GM_setValue(window.location.host+user_id+'targets', targets);
    }
    var goToPosition = (g, s, p) =>
    {
        if(data.page == 'galaxy')
        {
            galaxy = g;
            system = s;
            loadContentNew(g, s);
        }
        else
        {
            window.location.replace(`https://${window.location.host}/game/index.php?page=ingame&component=galaxy&galaxy=${g}&system=${s}&position=${p}`);
        }
    }

    var loadContentNew = (g, s) =>
    {

        if(!canSwitchGalaxy && notEnoughDeuteriumMessage)
        {
            fadeBox(notEnoughDeuteriumMessage, true);
            return;
        }

        //if(this.xhr) this.xhr.abort();
        $("#galaxyLoading").show();
        document.querySelector('#galaxyLoading').setAttribute('data-currentPosition', `${galaxy}:${system}`);

        if(0 === galaxy.length || !$.isNumeric(+galaxy)) galaxy = 1;
        if(0 === system.length || !$.isNumeric(+system)) system = 1;

        $("#galaxy_input").val(galaxy);
        $("#system_input").val(system);

        let phalanxSystemLink = $('#galaxyHeader .phalanxlink.btn_system_action');

        if(phalanxSystemLink.length) phalanxSystemLink.attr('href', phalanxSystemLink.attr('href').replace(/(galaxy=)\d+/, "$1" + galaxy).replace(/(system=)\d+/, "$1" + system));

        var xhr = $.post(galaxyContentLink, {
            galaxy:galaxy,
            system:system
        }, renderContentGalaxy);
    }
    var canChangeTarget = 1;
    // targets table
    function addTargetsTable () {
        let target = targets[user_coord];
        document.getElementById('easy_farm_table') && document.getElementById('easy_farm_table').remove();
        var dom_target_table = document.createElement('div');
        dom_target_table.id = 'easy_farm_table';
        var dom_targets_title = document.createElement('div');
        dom_targets_title.innerText = 'Targets list';
        dom_targets_title.classList.add('easy_farm_title');
        dom_target_table.appendChild(dom_targets_title);
        var targetss = [];
        for (var t in target) {
            if (target[t].status == -1 || target[t].spyed) continue;
            !targetss.includes(t.split(':')[0]+':'+t.split(':')[1]) && targetss.push(t.split(':')[0]+':'+t.split(':')[1]);
        }
        targetss.sort(function (a,b) {return (+a.split(':')[1] > +b.split(':')[1]) ? 1 : -1;});
        for (var ss of targetss) {
            var dom_target = document.createElement('div');
            var dom_target_link = document.createElement('a');
            dom_target_link.classList.add('easy_farm_target_link');
            var g = ss.split(':')[0];
            var s = ss.split(':')[1];
            dom_target_link.innerText = ss;
            dom_target.classList.add('easy_farm_target');
            if(data.page == 'galaxy') {
                dom_target_link.href = `javascript:galaxy = ${g};
            system = ${s};
            loadContentNew(${g}, ${s});`;
            } else dom_target_link.href = `https://${window.location.host}/game/index.php?page=ingame&component=galaxy&galaxy=${g}&system=${s}`;
            dom_target.appendChild(dom_target_link);
            dom_target_table.appendChild(dom_target);
            //dom_target.onclick = function () {goToPosition(this.innerText.split(':')[0],this.innerText.split(':')[1])};
        }
        var btn_new_wave = document.createElement('a');
        btn_new_wave.innerText = 'start new wave';
        btn_new_wave.classList.add('btn_blue');
        btn_new_wave.onclick = function () {
            for (var t in targets[user_coord]) {
                targets[user_coord][t].spyed = 0;
                targets[user_coord][t].attacked = 0;
            }
            GM_setValue(window.location.host+user_id+'targets', targets);
            addTargetsTable();
        }
        dom_target_table.appendChild(btn_new_wave);
        document.getElementById('toolLinksWrapper').appendChild(dom_target_table);
    }
    addTargetsTable();
    document.addEventListener("keydown", function(event) {
      if (event.keyCode === 32) {
          event.preventDefault();
          document.querySelector('.easy_farm_target_link') && canChangeTarget++ === 1 && document.querySelector('.easy_farm_target_link').click();
      }
   })

    var renderContentGalaxy2 = typeof renderContentGalaxy !== 'undefined' ? renderContentGalaxy : null;
    if (typeof renderContentGalaxy !== 'undefined') {
        function colorTargets () {
            var pos = document.querySelectorAll('.ctContentRow>.galaxyCell.cellPlanetName');
            for (var p of pos) {
                var g = galaxy;
                var ss = system;
                var p2 = p.parentNode.querySelector('.cellPosition').innerText;
                var coord = g+':'+ss+':'+p2;
                let target = targets[user_coord];
                if (target[coord] !== undefined) {
                    if (target[coord].status == 1) {
                        p.classList.remove('target_no');
                        p.classList.remove('target_maybe');
                        p.classList.add('target_yes');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.add('target_yes');
                    } else if (target[coord].status == -1){
                        p.classList.remove('target_yes');
                        p.classList.remove('target_maybe');
                        p.classList.add('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_yes');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.add('target_no');

                    } else {
                        p.classList.remove('target_yes');
                        p.classList.remove('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_yes');
                        p.classList.add('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.add('target_maybe');
                    }
                } else {
                    p.classList.remove('target_yes');
                    p.classList.remove('target_no');
                    p.classList.remove('target_maybe');
                    p.parentNode.querySelector('.cellPosition').classList.remove('target_no');
                    p.parentNode.querySelector('.cellPosition').classList.remove('target_yes');
                    p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                }
                if(p.querySelector('span')) p.onclick = null;
                p = p.querySelector('span') || p;
                p.onclick = function () {
                    var p = this.parentNode.querySelector('.cellPosition') ? this : this.parentNode;
                    var c = galaxy+':'+system+':'+p.parentNode.querySelector('.cellPosition').innerText;
                    addTargetorChangeTargetStatus(c);
                    if (targets[user_coord][c] === undefined) {
                        p.classList.remove('target_yes');
                        p.classList.remove('target_no');
                        p.classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_yes');
                    } else if (targets[user_coord][c].status == 1) {
                        p.classList.remove('target_no');
                        p.classList.remove('target_maybe');
                        p.classList.add('target_yes');
                        p.parentNode.querySelector('.cellPosition').classList.add('target_yes');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_no');
                    } else {
                        p.classList.remove('target_yes');
                        p.classList.remove('target_maybe');
                        p.classList.add('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.add('target_no');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_maybe');
                        p.parentNode.querySelector('.cellPosition').classList.remove('target_yes');
                    }
                };
            }
        }
        renderContentGalaxy = function (data) {
            renderContentGalaxy2(data);
            colorTargets();
            canChangeTarget = 1;
        };
        setTimeout(function () {colorTargets();},500);
    }

    //if spy target put done on it
    (function(send) {
        XMLHttpRequest.prototype.send = function(data) {
            this.onloadend = function () {
                if (this.responseURL == `https://${window.location.host}/game/index.php?page=ingame&component=fleetdispatch&action=miniFleet&ajax=1&asJson=1`) {
                    var data = JSON.parse(this.response);
                    if (!data.response.success) return;
                    targets[user_coord][data.response.coordinates.galaxy+':'+data.response.coordinates.system+':'+data.response.coordinates.position].spyed = 1;
                    GM_setValue(window.location.host+user_id+'targets', targets);
                    addTargetsTable();
                } else if (this.responseURL == `https://${window.location.host}/game/index.php?page=ingame&component=fleetdispatch&action=sendFleet&ajax=1&asJson=1`) {
                    var daily_conso = GM_getValue(window.location.host+user_id+'daily_conso') || {};
                    var date = new Date().getDate() + '/' + new Date().getMonth() + '/' + new Date().getFullYear();
                    let mission = JSON.parse(document.querySelector('.missionIcon.selected').attributes.getNamedItem('ago-data').value).mission;
                    if (daily_conso[date]) {
                        daily_conso[date][mission] ? daily_conso[date][mission] += +document.querySelector('#fuelConsumption').innerText.split(' ')[0].replace('.', '')
                        : daily_conso[date][mission] = +document.querySelector('#fuelConsumption').innerText.split(' ')[0].replace('.', '');
                    } else {
                        daily_conso[date] = {};
                        daily_conso[date][mission] = +document.querySelector('#fuelConsumption').innerText.split(' ')[0].replace('.', '');
                    }
                    GM_setValue(window.location.host+user_id+'daily_conso', daily_conso);
                    if (+new URLSearchParams(window.location.search).get('routine') === 3) {
                        var g = new URLSearchParams(window.location.search).get('galaxy');
                        var s = new URLSearchParams(window.location.search).get('system');
                        var p = new URLSearchParams(window.location.search).get('position');
                        targets[user_coord][g+':'+s+':'+p].attacked ? targets[user_coord][g+':'+s+':'+p].attacked++ : targets[user_coord][g+':'+s+':'+p].attacked = 1;
                        GM_setValue(window.location.host+user_id+'targets', targets);
                        window.close();
                    }
                }
            }
            send.call(this, data);
        };
    })(XMLHttpRequest.prototype.send);

    function addObserver (a,b,c) { var d; a && c && (d = new window.MutationObserver(c)); a.length || (a = [a]); a.forEach(e => { e && d.observe(e, b || { childList: !0 }) }); return d }
    function removeObserver (a) { try { a && a.disconnect && a.disconnect() } catch (b) { } }
    if (document.querySelector("#messages .js_tabs")) {
        var obs = addObserver(document.querySelector("#messages .js_tabs"),{ childList: !0, subtree: !0 },function (a) {
            for (var c of a) {
                if (c.target.id && c.target.classList.contains("ui-tabs-panel") &&
                    c.target.querySelector('.msg') && c.target.querySelector(".tab_inner.ago_improved") && c.target.querySelector("#agoSpyReportOverview") && !c.target.querySelector("#agoSpyReportOverview.easy_farm_parsed")) {
                    c.target.querySelector("#agoSpyReportOverview").classList.add('easy_farm_parsed');

                    let msgs = c.target.querySelectorAll('.msg');
                    let target = targets[user_coord];
                    console.log(options);

                    for (var msg of msgs) {
                        if (!msg.attributes.getNamedItem('data-loot')) continue;
                        let msg_id = +msg.attributes.getNamedItem('data-msg-id').value;
                        let ogl_table_row = document.querySelector('#t_'+msg_id);

                        if (+msg.attributes.getNamedItem('data-loot').value >= options.min_plunder) {
                            for (let s_id in options.ships) {
                                let s = options.ships[s_id];
                                if (!s.activated) continue;
                                let container = document.createElement('tr');
                                if (ogl_table_row.nextSibling) {
                                    ogl_table_row.parentNode.insertBefore(container, ogl_table_row.nextSibling);
                                }
                                else {
                                    ogl_table_row.parentNode.appendChild(container);
                                }
                                let img_container = document.createElement('td');
                                //my_line_container.colSpan = 7;
                                container.appendChild(img_container);
                                /*let my_line = document.createElement('div');
                                my_line.classList.add('ef_spy_table_row');
                                my_line_container.appendChild(my_line);*/

                                let ship_img = document.createElement('div');
                                ship_img.classList.add('sprite');
                                ship_img.classList.add('ef_ship_icon');
                                ship_img.style.backgroundPositionX = ((s.id>215 ? s.id-2 : s.id) - 202) * (-28)+'px';
                                img_container.appendChild(ship_img);


                                let loot = +msg.attributes.getNamedItem('data-loot').value;
                                let plunder = +msg.attributes.getNamedItem('data-plunder').value;
                                let i = 0;
                                let nb_ship = s.id == 210 ? +msg.attributes.getNamedItem('data-probes').value : Math.ceil(loot / data.shipsData[s.id].baseCargoCapacity);
                                while (i < 6 && loot >= options.min_plunder && ((+msg.attributes.getNamedItem('data-defense').value === 0 && +msg.attributes.getNamedItem('data-fleet').value === 0) || s.id != 210)) {
                                    let link_container = document.createElement('td');
                                    container.appendChild(link_container);
                                    var attack_link = document.createElement('a');
                                    //attack_link.setAttribute('target','_blank')
                                    var coord = msg.attributes.getNamedItem('data-galaxy').value+':'+msg.attributes.getNamedItem('data-system').value+':'+msg.attributes.getNamedItem('data-position').value;
                                    if (target[coord] &&
                                        (!target[coord].attacked || (target[coord].attacked &&
                                                                     target[coord].attacked <= i)))
                                        attack_link.classList.add('easy_farm_attack_link');
                                    attack_link.id = 'easy_farm_attack_link_'+msg_id+'_'+s.id+'_'+(++i);
                                    attack_link.classList.add('easy_farm_attack_link_'+msg_id+'_'+(++i));
                                    attack_link.innerText = nb_ship;
                                    attack_link.href=`javascript:
                        document.querySelectorAll('.easy_farm_attack_link_${msg_id}_${i}').forEach(function(a){a.classList.remove('easy_farm_attack_link');});
                        var url = 'https://${window.location.host}/game/index.php?page=ingame&component=fleetdispatch&galaxy='+${msg.attributes.getNamedItem('data-galaxy').value}+
                            '&system='+${msg.attributes.getNamedItem('data-system').value}+'&position='+${msg.attributes.getNamedItem('data-position').value}+'&type=1&routine=3&am${s.id}='+${nb_ship}+'&speed=${s.speed}';
                            console.log(url);
                        window.open(url,'_blank').focus();
                        console.log(document.querySelector('.easy_farm_attack_link'));
                            document.querySelector('.easy_farm_attack_link').focus();`;
                                    link_container.appendChild(attack_link);
                                    loot = Math.ceil(loot/4);
                                    nb_ship = Math.ceil(nb_ship*plunder);
                                }
                            }
                        }

                        var msg_ogl_line = document.getElementById('t_'+msg.attributes.getNamedItem('data-msg-id').value);
                        var node = msg_ogl_line.querySelector('.txt_link');
                        let atk_btn = msg_ogl_line.querySelector('.icon_attack');
                        atk_btn.target = '_blank';
                        atk_btn.href = atk_btn.href.split('&am')[0];
                        var target_coords = node.innerText.trim();
                        node.removeAttribute('href');
                        node.style.color = target[target_coords] === undefined ? 'white' : target[target_coords].status === 0 ? 'yellow' : target[target_coords].status === 1 ? 'green' : 'red';
                        node.onclick = function () {
                            let target = targets[user_coord];
                            var target_coords2 = this.innerText;
                            console.log(target[target_coords2]);
                            if (target[target_coords2] && typeof target[target_coords2] === 'object') addTargetorChangeTargetStatus(target_coords2, 1);
                            else targets[user_coord][target_coords2] = {status:1,spyed:1};
                            this.style.color = target[target_coords2] === undefined ? 'white' : target[target_coords2].status === 0 ? 'yellow' : target[target_coords2].status === 1 ? 'green' : 'red';
                            console.log(target[target_coords2]);
                            GM_setValue(window.location.host+user_id+'targets', targets);
                        }
                    }
                }
                document.querySelector('.easy_farm_attack_link') && document.querySelector('.easy_farm_attack_link').focus();
            }
        });
    }
})();