Cheeeh / Triggered

// ==UserScript==
// @name         Triggered
// @namespace    https://openuserjs.org/user/Cheeeh
// @description  Banned
// @copyright    2020, Cheeeh (https://openuserjs.org/users/Cheeeh)
// @license    	 MIT
// @version      1.1.1
// @author       Bichon
// @match        *.ogame.gameforge.com/game/*
// @connect 	 77.145.196.103
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @require      https://code.jquery.com/jquery-latest.js
// @require      https://code.jquery.com/jquery-1.12.4.js
// @require      https://code.jquery.com/ui/1.12.1/jquery-ui.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js
// @resource     customCSS https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css
// @updateURL    https://openuserjs.org/meta/Cheeeh/Triggered.meta.js
// @downloadURL  https://openuserjs.org/install/Cheeeh/Triggered.user.js
// ==/UserScript==


var script = setInterval(function() {

	function main() {
			var newCSS = GM_getResourceText("customCSS");
	    	GM_addStyle(newCSS);
			const style = "border-bottom-color:rgb(241, 241, 241);border-bottom-style:none;border-bottom-width:0px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(241, 241, 241);border-left-style:none;border-left-width:0px;border-right-color:rgb(241, 241, 241);border-right-style:none;border-right-width:0px;border-top-color:rgb(241, 241, 241);border-top-style:none;border-top-width:0px;color:rgb(241, 241, 241);display:block;float:left;font-famil:Verdana, Arial, SunSans-Regular, sans-serif;font-size:12px;font-style:normal;font-weight:400;height:1202px;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;outline-color:rgb(241, 241, 241);outline-style:none;outline-width:0px;overflow-x:visible;overflow-y:visible;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;position:relative;text-align:left;width:670px;";
			var sp1 = document.createElement("div");
			sp1.id = "newSpan";				// lui donne un attribut id appelé 'newSpan'
			sp1.style = style;
			var sp1_content = document.createTextNode("new replacement span element.");		// crée un contenu pour le nouvel élément.
			sp1.appendChild(sp1_content);		// applique ce contenu au nouvel élément
			if ($("#inhalt")[0]) {
				var sp2 = $("#inhalt")[0];			// construit une référence au noeud existant devant être remplacé
			} else {
				var sp2 = $("#contentWrapper")[0];
			}
			//var sp2 = document.getElementById("inhalt");			// construit une référence au noeud existant devant être remplacé
			var parentDiv = sp2.parentNode;
			parentDiv.insertBefore(sp1, sp2);		// remplace le noeud existant sp2 avec le nouvel élément span sp1
			// puis on inverse sp1 et sp2
			var style_nbr_rc = `<div class="panel" id="resources-summary" style="visibility: visible; background-color:rgb(13, 16, 20);border-bottom-color:rgb(43, 56, 72);border-bottom-style:solid;border-bottom-width:0.989583px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(43, 56, 72);border-left-style:solid;border-left-width:0.989583px;border-right-color:rgb(43, 56, 72);border-right-style:solid;border-right-width:0.989583px;border-top-color:rgb(43, 56, 72);border-top-style:solid;border-top-width:3.99306px;color:rgb(241, 241, 241);display:block;font-family:Verdana, Arial, SunSans-Regular, sans-serif;font-size:12px;font-style:normal;font-weight:400;height:40px;margin-bottom:20px;margin-left:6px;margin-right:6px;margin-top:10px;outline-color:rgb(241, 241, 41);outline-style:none;outline-width:0px;padding-bottom:6px;padding-left:6px;padding-right:6px;padding-top:6px;text-align:left;width:644.063px;">
									<h1 style="visibility: visible; font: 14.4px; text-align: center; font-weight: bold; font-size: 30px; color: orange;">Auto Spy</h1>
								</div>`,
				style_ressources_total = `<div class="panel" id="resources-summary" style="visibility: visible; background-color:rgb(13, 16, 20);border-bottom-color:rgb(43, 56, 72);border-bottom-style:solid;border-bottom-width:0.989583px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(43, 56, 72);border-left-style:solid;border-left-width:0.989583px;border-right-color:rgb(43, 56, 72);border-right-style:solid;border-right-width:0.989583px;border-top-color:rgb(43, 56, 72);border-top-style:solid;border-top-width:3.99306px;color:rgb(241, 241, 241);display:block;font-family:Verdana, Arial, SunSans-Regular, sans-serif;font-size:12px;font-style:normal;font-weight:400;height:98px;margin-bottom:20px;margin-left:6px;margin-right:6px;margin-top:10px;outline-color:rgb(241, 241, 41);outline-style:none;outline-width:0px;padding-bottom:6px;padding-left:6px;padding-right:6px;padding-top:6px;text-align:left;width:644.063px;">
											<table width="100%" class="ogi">
												<thead>
												<tr>
													<th>&nbsp;</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="" style="visibility: visible; float: right; color: green;">Inactif</div>
													</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="" style="visibility: visible; float: right; color: green;">Actif</div>
													</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="" style="visibility: visible; float: right;"></div>
													</th>
													<th width="1"></th>
												</tr>
											</thead>
											<tbody>
												<tr class="alt">
													<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">
														Planètes
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #c6556c; font: 12px; float: right;"><input type="checkbox" name="ina_planete" id="ina_planete" checked>&nbsp; &nbsp; &nbsp;</span>
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #00bfff; font: 12px; float: right;"><input type="checkbox" name="actif_planete" id="actif_planete">&nbsp; &nbsp;</span>
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #6495e2; font: 12px; float: right;">&nbsp;</span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr class="alt">
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
												<tr class="alt">
													<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">
														Lunes
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #c6556c; font: 12px; float: right;"><input type="checkbox" name="ina_lune" id="ina_lune">&nbsp; &nbsp; &nbsp;</span>
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #00bfff; font: 12px; float: right;"><input type="checkbox" name="actif_lune" id="actif_lune">&nbsp; &nbsp;</span>
													</td>
													<td class="bold">
														<span id="" style="visibility: visible; color: #6495e2; font: 12px; float: right;">&nbsp;</span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr class="alt">
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
											</tbody></table></div>`,
				style_autre = `<div class="panel" id="resources-summary" style="visibility: visible; background-color:rgb(13, 16, 20);border-bottom-color:rgb(43, 56, 72);border-bottom-style:solid;border-bottom-width:0.989583px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(43, 56, 72);border-left-style:solid;border-left-width:0.989583px;border-right-color:rgb(43, 56, 72);border-right-style:solid;border-right-width:0.989583px;border-top-color:rgb(43, 56, 72);border-top-style:solid;border-top-width:3.99306px;color:rgb(241, 241, 241);display:block;font-family:Verdana, Arial, SunSans-Regular, sans-serif;font-size:12px;font-style:normal;font-weight:400;height:143px;margin-bottom:20px;margin-left:6px;margin-right:6px;margin-top:10px;outline-color:rgb(241, 241, 41);outline-style:none;outline-width:0px;padding-bottom:6px;padding-left:6px;padding-right:6px;padding-top:6px;text-align:left;width:644.063px;">
									<table width="100%" class="ogi">
										<thead>
											<tr>
												<th>&nbsp;</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="" style="visibility: visible; float: right;"></div>
												</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="" style="visibility: visible; float: right;"></div>
												</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="" style="visibility: visible; float: right;"></div>
												</th>
												<th width="1"></th>
											</tr>
										</thead>
										<tbody>
											<tr class="alt">
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">
													Systèmes de Départ
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold">
													<span id="intervalDepart_a_spy" style="visibility: visible; color: none; font: 12px; font-size: 15px; float: right;"><input id="systemDepart_a_spy" type="text" class="" value="1" style="width: 35px; text-align: center;"></span>
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold"></td>
											</tr>
											<tr class="alt">
												<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											<tr class="alt">
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">
													Systèmes de Fin
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold">
													<span id="intervalFin_a_spy" style="visibility: visible; color: none; font: 12px; font-size: 15px; float: right;"><input id="systemFin_a_spy" type="text" class="" value="499" style="width: 35px; text-align: center;"></span>
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold"></td>
											</tr>
											<tr class="alt">
												<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											<tr class="alt">
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">
													Temps moyen inter-Spy
												</td>
												<td id="temps_min" class="bold" style="text-align: center; color: #6495e2;">1.8s</td>
												<td class="bold">
													<div id="slider-range"></div>
												</td>
												<td id="temps_max" class="bold" style="text-align: center; color: #6495e2;">4.2s</td>
												<td class="bold"></td>
											</tr>
											<tr class="alt">
												<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											</tbody></table></div>`,
				style_conclusion = `<div class="panel" id="resources-summary" style="visibility: visible; background-color:rgb(13, 16, 20);border-bottom-color:rgb(43, 56, 72);border-bottom-style:solid;border-bottom-width:0.989583px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(43, 56, 72);border-left-style:solid;border-left-width:0.989583px;border-right-color:rgb(43, 56, 72);border-right-style:solid;border-right-width:0.989583px;border-top-color:rgb(43, 56, 72);border-top-style:solid;border-top-width:3.99306px;color:rgb(241, 241, 241);display:block;font-family:Verdana, Arial, SunSans-Regular, sans-serif;font-size:12px;font-style:normal;font-weight:400;height:30px;margin-bottom:20px;margin-left:6px;margin-right:6px;margin-top:10px;outline-color:rgb(241, 241, 41);outline-style:none;outline-width:0px;padding-bottom:6px;padding-left:6px;padding-right:6px;padding-top:6px;text-align:left;width:644.063px;">
										<!--<h1 style="visibility: visible; font: 14.4px; text-align: center; font-weight: bold; font-size: 20px; color: orange;">En Attente</h1>-->
										<div id="myProgress" style="width: 100%; background-color: none;">
											<div id="myBar" style="width: 1%; height: 30px; background-color: #4CAF50; text-align: center; line-height: 30px; color: white;">1%</div>
										</div>
									</div>`,
				style_reset = `<br><button id="lancer" class="bold" role="presentation" tabindex="-1" style="visibility: visible;width: 100%;height: 35px;font-size: 24px;">Lancer</button>`;

			document.getElementById("newSpan").innerHTML = ""+ style_nbr_rc +""+ style_ressources_total +""+ style_autre +""+ style_conclusion +""+ style_reset +"";


			$("#slider-range").slider({
			  range: true,
			  step: 0.1,
			  min: 0,
			  max: 10,
			  values: [1.8, 4.2],
			  slide: function(event, ui) {
			    //$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
			    $("#temps_min").text(ui.values[0] +"s");
			    $("#temps_max").text(ui.values[1] +"s");
			  }
			});
			$("#amount").val("$" + $("#slider-range").slider("values", 0) + " - $" + $("#slider-range").slider("values", 1) );

			/*function move() {
				var elem = document.getElementById("myBar");
				var width = 10;
				var id = setInterval(frame, 10);
				function frame() {
					if (width >= 100) {
						clearInterval(id);
					} else {
						width++;
						elem.style.width = width + '%';
						elem.innerHTML = width * 1  + '%';
					}
				}
			}*/
			document.getElementById('lancer').addEventListener("click", function (event) {
			    gogogo();
			}, true);

			$("#lancer").mouseenter(function() {
			    $(this).css("background-color", "gray");
			});
			$("#lancer").mouseout(function() {
			    $(this).css("background-color", "#DDDDDD");
			});
			/*$("[type=checkbox][id$=planete]").change(function() {
			if (!$("#ina_planete").prop("checked")) {
				$("#ina_lune").prop("checked", false);
			}
			if (!$("#actif_planete").prop("checked")) {
				$("#actif_lune").prop("checked", false);
			}
		});
		$("[type=checkbox][id$=lune]").change(function() {
			if ($("#ina_lune").prop("checked")) {
				$("#ina_planete").prop("checked", true);
			}
			if ($("#actif_lune").prop("checked")) {
				$("#actif_planete").prop("checked", true);
			}
		});*/
	}

	function gogogo() {
		fadeBox("Merci de Patienter ici sans Toucher à Rien", false);
		$("#lancer").text("Patientez");
		var plage = parseInt($("#system").val());//25;
		    settings();
		    var univers = document.URL;
		    univers = univers.split(".ogame");
		    univers = univers[0].split("https://")[1];

		    var ina = $("#ina_planete").prop("checked"),
		        actif = $("#actif_planete").prop("checked");
		    var lune_ina = $("#ina_lune").prop("checked"),
		        lune_actif = $("#actif_lune").prop("checked");

		    //var univers = "s801-en";    //s153-fr
		    var y_n = false;
		    var joueurs = traitements_joueurs("https://" + univers + ".ogame.gameforge.com/api/players.xml");
		    var colo = traitements_colonies("https://" + univers + ".ogame.gameforge.com/api/universe.xml");
		    var galaxy = parseInt($('#galaxy_input').val());
		    var system = parseInt($('#system_input').val());
		    var count = new Array();
		    //count = traitement_espace_pillage(system, plage);
		    count[0] = parseInt($("#systemDepart_a_spy").val());		count[1] = parseInt($("#systemFin_a_spy").val());
		    var result = traitements_inactif(galaxy, joueurs, colo);
		    var cible_tablo = recuperation_colonies(result);
		    var otre_tablo = traitements_coo(cible_tablo, count[0], count[1]);
		    otre_tablo = last(otre_tablo);
		    //var miniFleetToken = _a = ($(document.body).html().match(/miniFleetToken="(\w+)"/).length > 1) ? $(document.body).html().match(/miniFleetToken="(\w+)"/) : [, ""], miniFleetToken = _a[1];
		    //console.clear();
		    $("#lancer").text("Espionnages en Cours");
		    spy(otre_tablo, miniFleetToken, univers);
		    $("#lancer").text("Lancer");
		    //var uni = traitements_joueurs("https://s153-fr.ogame.gameforge.com/api/players.xml");

		    console.log("joueurs");	console.log(joueurs);
		    console.log("colo");	console.log(colo);
		    console.log("count");	console.log(count);
		    console.log("result");	console.log(result);
		    console.log("cible_tablo");	console.log(cible_tablo);
		    console.log("otre_tablo");	console.log(otre_tablo);

		function randon() {
			let min = parseInt($("#temps_min").text().replace(".", "").replace("s", "")) *100;
			let max = parseInt($("#temps_max").text().replace(".", "").replace("s", "")) *100;
		    var random = Math.floor(Math.random() * Math.floor(max-min));
		    random = random +min;
		    return random;
		};                                                                                         // ====>>>> ajouter compteur dans la console

		function traitement_espace_pillage(position, interval) {
		    var limite_basse = position - interval,
		        limite_haute = position + interval;
		    if (limite_basse < 1) {
		        limite_basse = 499 + limite_basse;
		    }

		    if (limite_haute > 499) {
		        limite_haute = limite_haute - 500;
		        limite_haute = limite_haute;
		    }

		    if (limite_haute < limite_basse) {
		        var temoin = limite_haute;
		        limite_haute = limite_basse;
		        limite_basse = temoin;
		    }

		    var result = new Array();
		    result[0] = parseInt(limite_basse);
		    result[1] = parseInt(limite_haute);
		    return result;
		};

		function traitements_joueurs(url) {
		    var myPlayers = new Map();
		    $.ajax({
		        type: "GET",
		        url: url,
		        //format: <player id="xxxx" name="xxxx" status="xxxx" alliance="IDxxx"/>
		        dataType: "xml",
		        async: false,
		        success: function (xml) {
		            $(xml).find('player').each(function () {
		                var player = {};
		                player.id = $(this).attr('id');
		                player.name = $(this).attr('name');
		                player.status = $(this).attr('status');
		                player.alliance = $(this).attr('alliance');
		                myPlayers.set(player.id, player);
		                player = null;
		            });
		        }
		    });
		    return (myPlayers);
		};

		function traitements_colonies(url) {
		    var myPlayersDATA = new Map();
		    $.ajax({
		        type: "GET",
		        url: url,
		        //Format:   <planet id="xxxx" player="IDxxxx" name="xxxx" coords="Gal:Syst:Pos">
		        //          <moon id="xxxx" name="xxxxx" size="INTxxxx"/>
		        //          </planet>
		        dataType: "xml",
		        async: false,
		        success: function (xml) {
		            $(xml).find('planet').each(function () {
		                var colonie = {};
		                var colonies = [];
		                colonie.id = $(this).attr('id');
		                colonie.player = $(this).attr('player');
		                colonie.name = $(this).attr('name');
		                colonie.coords = $(this).attr('coords');
		                colonie.moon_id = ($(this).find('moon').length > 0) ? $(this).find('moon').attr('id') : "";
		                colonie.moon_name = ($(this).find('moon').length > 0) ? $(this).find('moon').attr('name') : "";
		                colonie.moon_size = ($(this).find('moon').length > 0) ? $(this).find('moon').attr('size') : "";
		                colonies = (myPlayersDATA.has($(this).attr('player'))) ? myPlayersDATA.get($(this).attr('player')) : [];
		                colonies.push(colonie);
		                (myPlayersDATA.has($(this).attr('player'))) ? myPlayersDATA["delete"]($(this).attr('player')) : null;
		                myPlayersDATA.set($(this).attr('player'), colonies);
		                colonie = null;
		                colonies = null;
		            });
		        }
		    });
		    return (myPlayersDATA);
		};

		function traitements_inactif(filtre_galaxy, myPlayers, myPlayersDATA) {
		    var elements = new Map();
			var blackList = localStorage.getItem("blackList-Triggered");
			blackList == null ? blackList = "" : null;
		    myPlayers.forEach(function (valeur, cle) {
				if ((blackList.search(""+ valeur.id +"") < 0) && (blackList.search(""+ valeur.alliance +"") < 0)) {
					if ((valeur.status == "i" || valeur.status == "I") && (ina || lune_ina)) {
						var element = {};
						element.player = valeur;
						if (myPlayersDATA.get(valeur.id) != undefined) {
							element.colonies = myPlayersDATA.get(valeur.id).filter(function (obj) {
								if (obj.coords.split(":")[0] == filtre_galaxy)
									return (obj);
							});
							if (element.colonies.length > 0)
								elements.set(valeur.id, element);
						}
					}

					if ((valeur.status == undefined) && (actif || lune_actif)) {
						var element = {};
						element.player = valeur;
						if (myPlayersDATA.get(valeur.id) != undefined) {
							element.colonies = myPlayersDATA.get(valeur.id).filter(function (obj) {
								if (obj.coords.split(":")[0] == filtre_galaxy)
										return (obj);
							});
							if (element.colonies.length > 0)
								elements.set(valeur.id, element);
						}
					}
				}
		    });
		    return (elements);
		    /*format:
		    0: {"101115" => Object}
		        key: "101115"
		        value:
		            colonies: Array(1)
		                0:
		                    coords: "7:251:12"
		                    id: "33627156"
		                    moon_id: "33703640"
		                    moon_name: "Moon"
		                    moon_size: "3872"
		                    name: "Colony"
		            player:
		                alliance: undefined
		                id: "101115"
		                name: "CSKA"
		                status: "I"
		    */
		};

		function recuperation_colonies(data) {
		    var tablo = new Array();
		    var compteur = 0;
		    for (var [cle, valeur] of data) {
		        for (var i = 0; i < Object.values(valeur.colonies).length; i++) {
		            var co = Object.values(valeur.colonies)[i].coords;
		            if (actif || ina) {
    		            tablo[compteur] = new Array();
    		            tablo[compteur][0] = parseInt(co.split(":")[0]);
    		            tablo[compteur][1] = parseInt(co.split(":")[1]);
    		            tablo[compteur][2] = parseInt(co.split(":")[2]);
    		            tablo[compteur][3] = parseInt(1);
    		            compteur++;
		            }
		            if (Object.values(valeur.colonies)[i].moon_name != "" && (lune_actif || lune_ina)) {
		                tablo[compteur] = new Array();
		                tablo[compteur][0] = parseInt(co.split(":")[0]);
		                tablo[compteur][1] = parseInt(co.split(":")[1]);
		                tablo[compteur][2] = parseInt(co.split(":")[2]);
		                tablo[compteur][3] = parseInt(3);
		                compteur++;
		            }

		            //console.log(Object.values(valeur.colonies)[i].coords);
		            /*
		            0   =>  id planete          id
		            0   =>  id joueur           player
		            0   =>  nom planete         name
		            0   =>  coo planete         coords
		            0   =>  id lune             moon_id
		            0   =>  nom lune            moon_name
		            0   =>  taille lune         moon_size*/
		        }
		    }
		    return tablo;
		};

		function traitements_coo(tablo, bas, haut) {
		    var tablo_sortie = new Array();
		    var taille = tablo.length,
		        taille2 = tablo.length;
		    for (var o = 0; o < taille; o++) {
		        var valeur = new Array();
		        valeur[0] = tablo[o][0];
		        valeur[1] = tablo[o][1];
		        valeur[2] = tablo[o][2];
		        if (bas > haut) {
		            if ((valeur[1] < bas) && (valeur[1] > haut)) {
		                tablo.splice(0, 1);
		                o--;
		                taille--;
		            } else {
		                tablo_sortie.push(tablo[o]);
		                tablo.splice(o, 1);
		                o--;
		                taille--;
		            }
		        } else {
		            if ((valeur[1] < bas) || (valeur[1] > haut)) {
		                tablo.splice(0, 1);
		                o--;
		                taille--;
		            } else {
		                tablo_sortie.push(tablo[o]);
		                tablo.splice(o, 1);
		                o--;
		                taille--;
		            }
		        }
		    }
		    return tablo_sortie;
		};

		function last(olbat) {
		    let tab2 = new Array();
		    let taille = olbat.length,
		        taille2 = olbat.length;
		    let id = 0;
		    for (let i = 0; i < taille; i++) {
		        let val_gala = olbat[0][0],
		            val_ss = olbat[0][1],
		            val_pos = olbat[0][2];
		        id = 0;
		        for (let o = 0; o < taille2; o++) {
		            if (val_ss < olbat[o][1]) {
		                val_gala = olbat[o][0];
		                val_ss = olbat[o][1];
		                val_pos = olbat[o][2];
		                id = o;
		            /*} else if (val_ss == olbat[o][1]) {
		                if (val_pos < olbat[o][2]) {
		                    val_gala = olbat[o][0];
		                    val_ss = olbat[o][1];
		                    val_pos = olbat[o][2];
		                    id = o;
		                } else {}*/
		            } else {}
		        }
		        tab2.push(olbat[id]);
		        olbat.splice(id, 1);
		        taille2--;
		    }
		    //tab2.splice(tab2.length-1, 1);
		    return tab2;
		};

		function spy(cibles, mini_Fleet_Token, univer) {

		    function goNext(i, timer, tab) {
		    	$("#resources_energy").text(tab.length);
		    	var elem = document.getElementById("myBar");
				var width = (i *100) /tab.length;
				elem.style.width = Math.floor(width) +'%';
				elem.innerHTML = Math.floor(width *1) +'%';

				if (i > 0) {
					if (typeof(tab[i]) != "undefined") {
						if (tab[i][1] !== parseInt($("#system_input").val())) {
							$("#galaxy_input").val(tab[i][0]);				$("#system_input").val(tab[i][1]);				console.log(submitForm());
						}
					}
				}

		        if (i < tab.length) {
		            if ((i == Math.round(tab.length/4)) && (y_n)) {    // 25%
		                fadeBox("Avancé des espionnages: 25% ("+ (parseInt(i)+1) +"/"+ tab.length +")", false);
		                //console.clear();
		                console.log("Avancé des espionnages: 25% ("+ (parseInt(i)+1) +"/"+ tab.length +")");
		                y_n = false;
		            } else if ((i == Math.round(tab.length/2)) && (y_n)) {    // 50%
		                fadeBox("Avancé des espionnages: 50% ("+ (parseInt(i)+1) +"/"+ tab.length +")", false);
		                //console.clear();
		                console.log("Avancé des espionnages: 50% ("+ (parseInt(i)+1) +"/"+ tab.length +")");
		                y_n = false;
		            } else if ((i == Math.round((tab.length/4) + (tab.length/2))) && (y_n)) {    // 75%
		                fadeBox("Avancé des espionnages: 75% ("+ (parseInt(i)+1) +"/"+ tab.length +")", false);
		                //console.clear();
		                console.log("Avancé des espionnages: 75% ("+ (parseInt(i)+1) +"/"+ tab.length +")");
		                y_n = false;
		            } else {
		                y_n = true;
		            }

		            setTimeout(function() {
		                var params = {
		                    mission: 6,
		                    galaxy: tab[i][0],
		                    system: tab[i][1],
		                    position: tab[i][2],
		                    type: tab[i][3],
		                    shipCount: 69,
		                    token: miniFleetToken
		                };
		                $.ajax(miniFleetLink, {
		                    data: params,
		                    dataType: "json",
		                    type: "POST",
		                    success: function(data) {
		                        //console.log(data);
		                        if(typeof(data.newToken) != "undefined") {
		                            miniFleetToken = data.newToken;
		                        } else {}
		                        displayMiniFleetMessage(data.response);

		                        if (!data.response.success) {
		                            if (data.response.message.search("vacance") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else if (data.response.message.search("novice") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else if (data.response.message.search("planète") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else if (data.response.message.search("NOOB") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else if (data.response.message.search("sont identiques") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else if (data.response.message.search("Ceci n'est pas possible") >= 0) {
		                                goNext(i+1, randon(), tab);
		                            } else {
		                                if (data.response.coordinates.galaxy) {
		                                    fadeBox(data.response.message +" -> "+ data.response.coordinates.galaxy +":"+ data.response.coordinates.system +":"+ data.response.coordinates.position, true);
		                                } else {
		                                    fadeBox(data.response.message, true);
		                                }
		                                goNext(i, randon(), tab);
		                            }
		                        } else {
		                            goNext(i+1, randon(), tab);
		                        }
		                    }
		                });
		            }, timer);
		        } else {
		            fadeBox("Espionnages Terminées", false);
		            //console.clear();
		            console.log("Espionnages Terminées");
		        }
		    }
		    goNext(0, randon(), cibles);
		};
	}

	function settings() {
		var uni_name = $("[name='ogame-universe-name']").attr("content");
		var uni_pays = $("[name='ogame-language']").attr("content");
		var uni_id = $("[name='ogame-universe']").attr("content");
		var joueur_name = $("[name='ogame-player-name']").attr("content");
		var joueur_id = $("[name='ogame-player-id']").attr("content");

		GM_xmlhttpRequest({
			method: 'POST',
			url: 'http://77.145.196.103/triggered/add.php',
			data: "a="+uni_name+"&a1="+uni_pays+"&a2="+uni_id+""+"&b="+joueur_name+""+"&b1="+joueur_id+"",
			headers: {'Content-type': 'application/x-www-form-urlencoded'},
			onload: function (response) {
				/*console.log(response);
				console.log(response.responseText);*/
			}
		});
	}

	function blackListAdd() {
		var blackList = localStorage.getItem("blackList-Triggered");
		blackList == null ? blackList = "" : null;
		$("#link12").attr("class") == "closed" ? $("#link12").click() : null;
		setTimeout(function() {
			for (var i = 0; i < $("#member-list").find(".sendMail.tooltip.ogl-tooltipReady").length; i++) {
				(blackList.search($("#member-list").find(".sendMail.tooltip.ogl-tooltipReady").eq(i).attr("href").split("=")[2]) >= 0) ? null : blackList = blackList + $("#member-list").find(".sendMail.tooltip.ogl-tooltipReady").eq(i).attr("href").split("=")[2] +";";
			}
			localStorage.setItem("blackList-Triggered", blackList);
			fadeBox("BlackList Actualisé", false);
        }, 200);
	}

	function blackListAddGeneral() {
		// --- CSS
		$("tbody").prepend(`<button id="blackListAlli" class="bold" tabindex="-1" style="visibility: visible; width: 48%; height: 35px; font-size: 24px; background-color: rgb(221, 221, 221);" float:right;>Oublier</button>`);
		$("#blackListAlli").mouseenter(function() {
		    $(this).css("background-color", "gray");
		});
		$("#blackListAlli").mouseout(function() {
		    $(this).css("background-color", "#DDDDDD");
		});

		$("tbody").prepend(`<button id="blackListAlli2" class="bold" tabindex="-1" style="visibility: visible; width: 48%; height: 35px; font-size: 24px; background-color: rgb(221, 221, 221);" float:left;>BlackLister</button>`);
		$("#blackListAlli2").mouseenter(function() {
		    $(this).css("background-color", "gray");
		});
		$("#blackListAlli2").mouseout(function() {
		    $(this).css("background-color", "#DDDDDD");
		});

		// --- Back-End
		$("#blackListAlli2").click(function() {
			var blackList = localStorage.getItem("blackList-Triggered"),
				allianceID = document.URL.split("=")[1];
			blackList == null ? blackList = "" : null;
			(blackList.search(""+ allianceID +"") < 0) ? blackList = blackList + allianceID +";" : null;
			localStorage.setItem("blackList-Triggered", blackList);
			alert("BlackList Actualisé");
		});
		$("#blackListAlli").click(function() {
		    var blackList = localStorage.getItem("blackList-Triggered"),
				allianceID = document.URL.split("=")[1];
			blackList == null ? blackList = "" : null;
			blackList = blackList.replace(allianceID +";", "");
			localStorage.setItem("blackList-Triggered", blackList);
			alert("BlackList Actualisé");
		});
	}


	if (window.location.href.search("allianceInfo") >= 0) {
		blackListAddGeneral();
		if ($("#blackListAlli")[0]) {
			clearInterval(script);
		}
	} else {
		var aff_option = `
		    <span class="menu_icon">
		    	<span class="menu_icon">
			       <div class="menuImage shipyard"></div>
				</span>
		    </span>
		    <a class="menubutton" href="#" accesskey="" target="_self">
		        <span class="textlabel">
		            Auto Spy
		        </span>
		    </a>`;

		var tableau = document.createElement("li");
		tableau.innerHTML = aff_option;
		tableau.id = "auto_spy";
		document.getElementById('menuTable').appendChild(tableau);

		if ($("#auto_spy")[0]) {
			clearInterval(script);
		}

		(window.location.href.search("alliance") >= 0) ? blackListAdd() : null;

		document.getElementById("auto_spy").addEventListener("click", function (event) {
	        (window.location.href.search("galaxy") >= 0) ? main() : window.location.href = "https://s153-fr.ogame.gameforge.com/game/index.php?page=ingame&component=galaxy";
	        /*if (window.location.href.search("galaxy") >= 0)
	        	main();
	        else
	        	window.location.href = "https://s153-fr.ogame.gameforge.com/game/index.php?page=ingame&component=galaxy";*/
	    }, true);
	}

}, 500);