Valmone / Make Looting Great Again

// ==UserScript==
// @name         Make Looting Great Again
// @namespace   https://openuserjs.org/user/Valmone
// @description  Récapitulatif de rentabilité pillage/raide/expedition Ogame
// @copyright    2018, Valmone (https://openuserjs.org/users/Valmone)
// @license    MIT
// @include      *.ogame*gameforge.com/game/*
// @version    1.5.0
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @updateURL    https://openuserjs.org/meta/Valmone/Make_Looting_Great_Again.meta.js
// ==/UserScript==

// ==OpenUserJS==
// @author       Valmone
// @testeur      Kate, Sospyne, Galoup
// ==/OpenUserJS==

"use strict";

var script = setInterval(function() {
    //console.clear();
    //console.log("------------------\n\nMake Looting Great Again\n\n------------------ ");

    var pays = document.getElementsByName("ogame-language")[0].getAttribute("content"),
        version = "1.5.0";
	    if (pays.search("es") >= 0) {	// espagnol
			var chargement = "Cargando...",
				fini = "Terminado",
				recuperer = "Cargar",
				reset_rc = "Vaciar",
				nbr_de_rc = "Número de CR",
				all_pillage = "Saqueo total",
				all_recyclage = "Total Débris Field",
				all_expedition = "Total Expedition",
				somme_total = "Σ Total",
				moyenne_par_rc = "Promedio por CR",
				moyenne_par_expe = "Promedio por Expedition",
				degat_realise = "Destruidas",
				pertes_subit = "Perdidas",
				benefices_totaux = "Beneficios totales",
				mauvais_menu_messages = "No API here";
		} else if (pays.search("fr") >= 0) {	// français
			var chargement = "Patientez",
				fini = "Terminé",
				recuperer = "Récupérer",
				reset_rc = "Validé",
				nbr_de_rc = "Nombre de RC",
				all_pillage = "Total Pillages",
				all_recyclage = "Total Recyclage",
				all_expedition = "Total Expedition",
				somme_total = "Σ Total",
				moyenne_par_rc = "Moyenne par RC",
				moyenne_par_expe = "Moyenne par Expedition",
				degat_realise = "Dégâts",
				pertes_subit = "Pertes",
				benefices_totaux = "Bénéfices Totaux",
				mauvais_menu_messages = "Pas d'API ici";
		} else {	// anglais
			var chargement = "Loading",
				fini = "Finish",
				recuperer = "Save",
				reset_rc = "Ok",
				nbr_de_rc = "Number of CR",
				all_pillage = "Total Looting",
				all_recyclage = "Total Débris Field",
				all_expedition = "Total Expedition",
				somme_total = "Σ Total",
				moyenne_par_rc = "Average per CR",
				moyenne_par_expe = "Average per Expedition",
				degat_realise = "Damages",
				pertes_subit = "Losses",
				benefices_totaux = "Total Benefits",
				mauvais_menu_messages = "No API here";
		}

	function maj_stockage() {
		let tablo_nul = new Array(0);
		if (!GM_getValue("conteneur"+univers)) {
            GM_setValue("conteneur"+univers, new conteneur(tablo_nul, tablo_nul, tablo_nul, 0, tablo_nul, tablo_nul, tablo_nul));
		} else if (!GM_getValue("conteneur"+univers).expedition) {
			GM_setValue("conteneur"+univers, new conteneur(GM_getValue("conteneur"+univers).api_rc, GM_getValue("conteneur"+univers).api_cdr, tablo_nul, 0, GM_getValue("conteneur"+univers).combats, GM_getValue("conteneur"+univers).recyclage, tablo_nul));
		}

		if (GM_getValue("nbrRC_"+univers)) {
			if (GM_getValue("nbrRC_"+univers) > GM_getValue("conteneur"+univers).nbrRC) {
				let a = GM_getValue("conteneur"+univers);
				a.api_rc = GM_getValue("api_dernier_rc"+univers);
				a.api_cdr = GM_getValue("api_dernier_cdr"+univers);
				a.api_expe = tablo_nul
				a.nbrRC = GM_getValue("nbrRC_"+univers);
				a.combats = GM_getValue("rapport_combat"+univers);
				a.recyclage = GM_getValue("rapport_recyclage"+univers);
				a.expedition = tablo_nul;
				GM_setValue("conteneur"+univers, a);
			}
		}
		//console.table(GM_getValue("nbrRC_"+univers), GM_getValue("conteneur"+univers));
	}

	function conteneur(z, x, y, a, b, c, d) {
		this.api_rc = z;
		this.api_cdr = x;
		this.api_expe = y;
		this.nbrRC = a;
		this.combats = b;
		this.recyclage = c;
		this.expedition = d;
	}

	function rapport_combat(api, metal, cristal, deut, degats, pertes, date) {
		this.api = api;
		this.metal = metal;
		this.cristal = cristal;
		this.deut = deut;
		this.degats = degats;
		this.pertes = pertes;
		this.date = date;
	}

	function rapport_recyclage(api, metal, cristal, date) {
		this.api = api;
		this.metal = metal;
		this.cristal = cristal;
		this.date = date;
	}

	function rapport_expe(api, metal, cristal, deut, date) {
		this.api = api;
		this.metal = metal;
		this.cristal = cristal;
		this.deut = deut;
		this.date = date;
	}

	function ana(val) {
		if (isNaN(parseInt(val))) {
			return parseInt(0);
		} else {
			return parseInt(val);
		}
	}

    function envoi_pillages(univers) {
    	function trim(string){
		    return string.replace(/(^\s*)|(\s*$)/g, '');
		}
		document.getElementById("EnvoiRC_MLGA").textContent = chargement;
		var DDD = document.getElementsByClassName("msg")[0].getElementsByClassName('msg_date')[0].textContent,
			datess = trim(DDD).split(' '),
			dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1],
			tab = new Array(),
			tab = GM_getValue("conteneur"+univers).api_rc,
			tablo = new Array(),
			tablo = GM_getValue("conteneur"+univers).combats,
			o = 0,
			msg = $('.msg'),
			taille = msg.length,
			pseudo_joueur = document.getElementsByName('ogame-player-name')[0].content;

		getcr(0, 125);
		$("#total_recup").eq(0).text("/"+ taille);

		function getcr(i, time) {
			setTimeout(function() {
				$("#EnvoiRC_MLGA").text(Math.trunc((i *100) /taille) +"%");
				i = parseInt(i);
				//console.log("i: "+ i);
				if (i < parseInt(taille)) {
					if (msg[i].getElementsByClassName("icon_nf icon_apikey")[0]) {
						var id_msg = msg[i].getAttribute('data-msg-id');
						var api_key = msg[i].getElementsByClassName("icon_nf icon_apikey")[0].getAttribute("title");
						api_key = ""+api_key+"";
						api_key = api_key.split(": ")[1];
						var api_key2 = msg[i].getElementsByClassName("icon_nf icon_apikey")[0].getAttribute("title");
						api_key2 = ""+api_key2+"";
						if (api_key2.split("value='")[1]) {
							api_key2 = api_key2.split("value='")[1];
							api_key2 = api_key2.split("' ")[0];
							$("#total_recup").eq(0).text("/"+ (parseInt($("#total_recup").eq(0).text().split("/")[1])-1));
							if (typeof(api_key) == "undefined" && typeof(api_key2) != "undefined") {
								api_key = api_key2;
							}
						}
						//console.log(api_key);
						if (tab.indexOf(api_key) >= 0 || tab.indexOf(id_msg) >= 0) {
							//console.log("On stop: api dans le tableau");
							$("#total_recup").eq(0).text("/"+ (parseInt($("#total_recup").eq(0).text().split("/")[1])-1));
							//i = document.getElementsByClassName("msg").length;
						} else if (typeof(api_key) == "undefined" || typeof(id_msg) == "undefined") {
							getcr(i, 50);
						} else {
							if ((msg[i].getElementsByClassName('combatLeftSide')[0] !==  undefined) && (api_key.search("cr-") >= 0)) {
								tab.push(id_msg);
								var	loots = msg[i].getElementsByClassName('combatLeftSide')[0].getElementsByClassName('msg_ctn msg_ctn3 tooltipLeft')[0].title.split(':');
								var	pertes = msg[i].getElementsByClassName("combatRightSide")[0].getElementsByTagName('span')[0].title;
								var	degats = msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByTagName('span')[0].title;
								pertes = parseInt(pertes.replace(/[.]/g, ''));
								degats = parseInt(degats.replace(/[.]/g, ''));
								if (loots[3]) {
									loots[1] = parseInt(loots[1].replace(/[^0-9]/g, ''));
								    loots[2] = parseInt(loots[2].replace(/[^0-9]/g, ''));
								    loots[3] = parseInt(loots[3].replace(/[^0-9]/g, ''));
								    if (typeof(msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 middlemark tooltipLeft")[0]) !== "undefined") {
									    var nom_attaquant = msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 middlemark tooltipLeft")[0].textContent;
									    var nom_def = msg[i].getElementsByClassName("combatRightSide")[0].getElementsByClassName("msg_ctn msg_ctn2 middlemark tooltipRight")[0].textContent;
									} else if (typeof(msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 undermark tooltipLeft")[0]) !== "undefined") {
								    	var nom_attaquant = msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 undermark tooltipLeft")[0].textContent;
								    	var nom_def = msg[i].getElementsByClassName("combatRightSide")[0].getElementsByClassName("msg_ctn msg_ctn2 overmark tooltipRight")[0].textContent;
									} else if (typeof(msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 overmark tooltipLeft")[0]) !== "undefined") {
										var nom_attaquant = msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByClassName("msg_ctn msg_ctn2 overmark tooltipLeft")[0].textContent;
										var nom_def = msg[i].getElementsByClassName("combatRightSide")[0].getElementsByClassName("msg_ctn msg_ctn2 undermark tooltipRight")[0].textContent;
									} else {}

									if (/\(([^\)]+)\)/.test(nom_attaquant)) {
									    var attaquant = /\(([^\)]+)\)/.exec(nom_attaquant)[1];
									    var defenseur = /\(([^\)]+)\)/.exec(nom_def)[1];
									    //console.log(attaquant, pseudo_joueur);
									   	if (attaquant != pseudo_joueur) {
									   		var je_suis_attaquant = 0;
									       	var tampon = degats;
									       	degats = pertes;
									       	pertes = tampon;
									    } else if (attaquant == pseudo_joueur) {
									   		var je_suis_attaquant = 1;
									    } else {
									    	var je_suis_attaquant = -1;
									    }
									} else {}
								} else {
									//console.log("On stop: pas de pillage");
								}
								var DDD = document.getElementsByClassName("msg")[i].getElementsByClassName('msg_date')[0].textContent;
								var datess = trim(DDD).split(' ');
								var dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1];

								//console.log("----------------------\n"+ tab.indexOf(api_key) +"\n----------------------");
								if (je_suis_attaquant > 0) {
									o++;
									var rc = new rapport_combat(api_key, loots[1], loots[2], loots[3], pertes, degats, dateFormat);
									tablo.push(rc);
								} else if (je_suis_attaquant == 0) {
									loots[1] = parseInt(loots[1]) *-1;
									loots[2] = parseInt(loots[2]) *-1;
									loots[3] = parseInt(loots[3]) *-1;
									o++;
									var rc = new rapport_combat(api_key, loots[1], loots[2], loots[3], pertes, degats, dateFormat);
									tablo.push(rc);
								} else {}
							} else {
								//console.log("On stop: mauvais rapport/api");
							}
						}
					} else if (msg[i].getElementsByClassName("combatLeftSide")[0]) {
					    //console.log("ok");
					    var id_msg = msg[i].getAttribute('data-msg-id');

					    if (tab.indexOf(id_msg) >= 0) {
							//console.log("On stop: id_msg dans le tableau");
							$("#total_recup").eq(0).text("/"+ (parseInt($("#total_recup").eq(0).text().split("/")[1])-1));
							//i = document.getElementsByClassName("msg").length;
						} else if (typeof(id_msg) == "undefined") {
							getcr(i, 50);
						} else {

						    var pertes = msg[i].getElementsByClassName("combatRightSide")[0].getElementsByTagName('span')[0].getAttribute('title').replace(/[^0-9]/g, '');
						    var degats = msg[i].getElementsByClassName("combatLeftSide")[0].getElementsByTagName('span')[0].getAttribute('title').replace(/[^0-9]/g, '');

						    var DDD = document.getElementsByClassName("msg")[i].getElementsByClassName('msg_date')[0].textContent;
						    var datess = trim(DDD).split(' ');
						    var dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1];

						    //console.log(degats, pertes);

							o++;
							var rc = new rapport_combat(0, 0, 0, 0, degats, pertes, dateFormat);
							tablo.push(rc);
							tab.push(id_msg);
						}
					} else {				
						//console.log("On stop: pas d'api détecté")
					}					
					$("#avance_recup").eq(0).text(o);
					getcr(i+1, 50);
				} else {
					//$("#avance_recup").eq(0).text(i);
					//console.log(tab);
					//console.log(tablo);
					let a = GM_getValue("conteneur"+univers);
					a.api_rc = tab;
					a.combats = tablo;
					a.nbrRC = a.nbrRC +o;
					GM_setValue("conteneur"+univers, a);
					document.getElementById("EnvoiRC_MLGA").textContent = fini;
					setTimeout(function(){
						document.getElementById("EnvoiRC_MLGA").textContent = recuperer;
					}, 1000);
				}
			}, time);
		}
	}

    function envoi_expe(univers) {
		function trim(string){
		    return string.replace(/(^\s*)|(\s*$)/g, '');
		}
		document.getElementById("EnvoiRC_MLGA").textContent = chargement;
		var DDD = document.getElementsByClassName("msg")[0].getElementsByClassName('msg_date')[0].textContent,
			datess = trim(DDD).split(' '),
			dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1],
			tab = new Array(),
			tab = GM_getValue("conteneur"+univers).api_expe,			
			tablo = new Array(),
			tablo = GM_getValue("conteneur"+univers).expedition,
			o = 0,
			msg = $('.msg'),
			taille = msg.length,
			regExpedition = new RegExp("\[[0-9]+:[0-9]+:16\]", ""),
			ress_gain = new Array("L`attaquant obtient Métal", "L`attaquant obtient Cristal", "L`attaquant obtient Deutérium");

		$("#total_recup").eq(0).text("");
		$("#avance_recup").eq(0).text(msg.length);
		getexpe(0, 125);		
		function getexpe(i, time) {
			setTimeout(function() {
				$("#EnvoiRC_MLGA").text(Math.trunc((i *100) /taille) +"%");
				i = parseInt(i);
				//console.log("i: "+ i);
				if (i < parseInt(taille)) {
					if (regExpedition.test(msg[i].getElementsByClassName('msg_title')[0].textContent)) {
						//console.log("présent");
						var id_msg = msg[i].getAttribute('data-msg-id');
						//console.log(id_msg);
						if (tab.indexOf(id_msg) >= 0) {							
							//console.log("On stop: api dans le tableau");
						} else if (typeof(id_msg) == "undefined") {
							getexpe(i, 50);
						} else {
							var DDD = msg[i].getElementsByClassName('msg_date')[0].textContent,
								datess = trim(DDD).split(' '),
								dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1],
								msg_content = msg[i].getElementsByClassName('msg_content')[0].textContent,
								id_msg = msg[i].getAttribute('data-msg-id');
							if (msg_content.search(ress_gain[0]) >= 0) {
								tab.push(id_msg);
								var expe = new rapport_expe(id_msg, msg_content.replace(/[^0-9]/g, ''), 0, 0, dateFormat);
								o++;
								tablo.push(expe);
							}
							if (msg_content.search(ress_gain[1]) >= 0) {
								tab.push(id_msg);
								var expe = new rapport_expe(id_msg, 0, msg_content.replace(/[^0-9]/g, ''), 0, dateFormat);
								o++;
								tablo.push(expe);
							}
							if (msg_content.search(ress_gain[2]) >= 0) {
								tab.push(id_msg);
								var expe = new rapport_expe(id_msg, 0, 0, msg_content.replace(/[^0-9]/g, ''), dateFormat);
								o++;
								tablo.push(expe);
							}
				        }
					} else {
						//console.log("absent");
					}
					$("#avance_recup").eq(0).text(parseInt($("#avance_recup").eq(0).text()) -1);
					getexpe(i+1, 50);
				} else {
					//console.log(tablo);
					let a = GM_getValue("conteneur"+univers);
					a.api_expe = tab;
					a.expedition = tablo;
					GM_setValue("conteneur"+univers, a);
					document.getElementById("EnvoiRC_MLGA").textContent = fini;
					setTimeout(function(){
						document.getElementById("EnvoiRC_MLGA").textContent = recuperer;
					}, 1000);
				}
			}, time);
		}
    }

    function envoi_cdr(univers) {
		function trim(string){
		    return string.replace(/(^\s*)|(\s*$)/g, '');
		}
		document.getElementById("EnvoiRC_MLGA").textContent = chargement;
		var DDD = document.getElementsByClassName("msg")[0].getElementsByClassName('msg_date')[0].textContent,
			datess = trim(DDD).split(' '),
			dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1],
			tab = new Array(),
			tab = GM_getValue("conteneur"+univers).api_cdr,			
			tablo = new Array(),
			tablo = GM_getValue("conteneur"+univers).recyclage,
			o = 0,
			msg = $('.msg'),
			taille = msg.length,
			metal_real = 0,
			cristal_real = 0;

		$("#total_recup").eq(0).text("");
		$("#avance_recup").eq(0).text(msg.length);
		getdf(0, 125);		
		function getdf(i, time) {
			setTimeout(function() {
				$("#EnvoiRC_MLGA").text(Math.trunc((i *100) /taille) +"%");
				i = parseInt(i);
				//console.log("i: "+ i);
				if (i < parseInt(taille)) {
					if (msg[i].getElementsByClassName("icon_nf icon_apikey tooltipCustom")[0]) {
						//console.log("présent");
						var api_key = msg[i].getElementsByClassName("icon_nf icon_apikey tooltipCustom")[0].getAttribute("title");
						api_key = api_key.split("value='")[1];
						api_key = api_key.split("' ")[0];
						var api_key2 = msg[i].getElementsByClassName("icon_nf icon_apikey")[0].getAttribute("title");
						api_key2 = ""+api_key2+"";
						if (api_key2.split("value='")[1]) {
							api_key2 = api_key2.split("value='")[1];
							api_key2 = api_key2.split("' ")[0];
							if (typeof(api_key) == "undefined" && typeof(api_key2) != "undefined") {
								api_key = api_key2;
							}
						}
						//console.log(api_key);
						if (tab.indexOf(api_key) >= 0) {							
							//console.log("On stop: api dans le tableau");
							//i = api.length;
						} else if (typeof(api_key) == "undefined") {
							getdf(i, 50);
						} else if (api_key.search("rr-") >= 0){
							var DDD = document.getElementsByClassName("msg")[i].getElementsByClassName('msg_date')[0].textContent,
								datess = trim(DDD).split(' '),
								dateFormat = datess[0].split('.')[2] + '-' + datess[0].split('.')[1] + '-' + datess[0].split('.')[0] + ' ' + datess[1];
							var titre = msg[i].getElementsByClassName("msg_content")[0].textContent;
							titre = titre.match(/((\d)*(\.)*(\d))+/g);
							var cristal = parseInt(titre[titre.length-1].replace(/\./g,""));
				        	var metal = parseInt(titre[titre.length-2].replace(/\./g,""));
				        	var cdr = new rapport_recyclage(api_key, parseInt(metal), parseInt(cristal), dateFormat);
				        	tab.push(api_key);
				        	tablo.push(cdr);
				        	o++;
				        } else {}
					} else {
						//console.log("absent");
					}
					$("#avance_recup").eq(0).text(parseInt($("#avance_recup").eq(0).text()) -1);
					getdf(i+1, 50);
				} else {
					//console.log(tablo);
					let a = GM_getValue("conteneur"+univers);
					a.api_cdr = tab;
					a.recyclage = tablo;
					//a.nbrRc = a.nbrRc +o;
					GM_setValue("conteneur"+univers, a);
					document.getElementById("EnvoiRC_MLGA").textContent = fini;
					setTimeout(function(){
						document.getElementById("EnvoiRC_MLGA").textContent = recuperer;
					}, 1000);
				}
			}, time);
		}
	}

    function affichageRC(univers) {

    	maj_stockage();
    	function resetRC(univers) {
    		let tablo_nul = new Array(0);	
			
			GM_setValue("conteneur"+univers, new conteneur(tablo_nul, tablo_nul, tablo_nul, 0, tablo_nul, tablo_nul, tablo_nul));
			GM_setValue("nbrRC_"+univers, 0);
			GM_setValue("api_dernier_rc"+univers, tablo_nul);
			GM_setValue("api_dernier_cdr"+univers, tablo_nul);

			GM_setValue("rapport_combat"+univers, tablo_nul);
			GM_setValue("rapport_recyclage"+univers, tablo_nul);

			document.getElementById("resetRC").textContent = reset_rc;
			document.getElementById("nbrRC_").textContent = 0;
			document.getElementById("metal total").textContent = 0;
			document.getElementById("crystal total").textContent = 0;
			document.getElementById("deut total").textContent = 0;
			document.getElementById("metal_cdr total").textContent = 0;
			document.getElementById("crystal_cdr total").textContent = 0;
			document.getElementById("somme total").textContent = 0;
			//document.getElementById("somme total simpli").textContent = 0;			
			document.getElementById("moyenne rc").textContent = 0;
			document.getElementById("degats total").textContent = 0;
			document.getElementById("pertes total").textContent = 0;
			document.getElementById("benefices totaux").textContent = 0;
    	}

    	function simpli(x){	
			var result = 0,
				round = 0;
			for (var i = 0; x >= 1000 ; i++) {
				var z = (x/1000);				//	1928.302
				z = Math.floor(z);				//	1928
				z = z *1000;					//	1928000
				z = x-z;						//	302
				if (z < 1) {
					z = "000";
				} else if (z < 10) {
					z = "00"+ z;
				} else if (z < 100) {
					z = "0"+ z;
				} else {}
				if (round > 0) {
					result = z +"."+ result;
				} else {
					result = z;
					round++;
				}
				//console.log(z);
				x = (x-z) /1000;				//	1928
			}
			z = (x/1000);				//	1928.302
			z = Math.floor(z);				//	1928
			z = z *1000;					//	1928000
			z = x-z;
			if (round > 0) {
				result = z +"."+ result;
			} else {
				result = z;
				round++;
			}
			//console.log("resultat: "+ result);
			return result;
		}

		function create_date(j, m, a) {
			let result = new Date(parseInt(a), parseInt(m)-1, parseInt(j));
			return result;
		}

		function mlga_choix_24h() {
			var rcs = new Array(),
				cdrs = new Array(),
				expes = new Array(),
				metal = 0,
				cristal = 0,
				deut = 0,
				metal_cdr = 0,
				cristal_cdr = 0,
				metal_expe = 0,
				cristal_expe = 0,
				deut_expe = 0,
				degats = 0,
				pertes = 0,
				nbr_rapport = 0,
				date = $(".OGameClock").text().split(" ")[0],
				jour = parseInt(date.split(".")[0]),
				mois = parseInt(date.split(".")[1]),
				annee = parseInt(date.split(".")[2]);

			var i_rcs = 0,
				i_cdrs = 0,
				i_expes = 0;
			
			if (GM_getValue("conteneur"+univers).combats != 0) {
				rcs = GM_getValue("conteneur"+univers).combats;
				for (var i = 0; i < rcs.length; i++) {
					var date_rc = rcs[i].date.split(" ")[0].split("-");
					if (parseInt(jour) == parseInt(date_rc[2]) && parseInt(mois) == parseInt(date_rc[1]) && parseInt(annee) == parseInt(date_rc[0])) {
						i_rcs++;
						nbr_rapport++;
						metal = metal + ana(parseInt(rcs[i].metal));
						cristal = cristal + ana(parseInt(rcs[i].cristal));
						deut = deut + ana(parseInt(rcs[i].deut));
						degats = degats + ana(parseInt(rcs[i].degats));
						pertes = pertes + ana(parseInt(rcs[i].pertes));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).recyclage != 0) {
				cdrs = GM_getValue("conteneur"+univers).recyclage;
				for (var i = 0; i < cdrs.length; i++) {
					var date_cdr = cdrs[i].date.split(" ")[0].split("-");
					if (parseInt(jour) == parseInt(date_cdr[2]) && parseInt(mois) == parseInt(date_cdr[1]) && parseInt(annee) == parseInt(date_cdr[0])) {
						i_cdrs++;
						metal_cdr = metal_cdr + ana(parseInt(cdrs[i].metal));
						cristal_cdr = cristal_cdr + ana(parseInt(cdrs[i].cristal));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).expedition != 0) {
				expes = GM_getValue("conteneur"+univers).expedition;
				for (var i = 0; i < expes.length; i++) {
					var date_expe = expes[i].date.split(" ")[0].split("-");
					if (parseInt(jour) == parseInt(date_expe[2]) && parseInt(mois) == parseInt(date_expe[1]) && parseInt(annee) == parseInt(date_expe[0])) {
						i_expes++;
						metal_expe = metal_expe + ana(parseInt(expes[i].metal));
						cristal_expe = cristal_expe + ana(parseInt(expes[i].cristal));
						deut_expe = deut_expe + ana(parseInt(expes[i].deut));
					}
				}
			}

			var benef = metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe - pertes,
				total = simpli(metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe);
			metal = simpli(metal);
			cristal = simpli(cristal);
			deut = simpli(deut);
			metal_cdr = simpli(metal_cdr);
			cristal_cdr = simpli(cristal_cdr);
			metal_expe = simpli(metal_expe);
			cristal_expe = simpli(cristal_expe);
			deut_expe = simpli(deut_expe);
			degats = simpli(degats);
			pertes = simpli(pertes);

			if (benef < 0) {
				var moyenne = benef / ana(nbr_rapport);
				benef = "-"+ simpli(benef *(-1));
				moyenne = "-"+ simpli(Math.round(moyenne *(-1)));
			} else {
				var moyenne = benef / ana(nbr_rapport);
				benef = simpli(benef);
				moyenne = simpli(Math.round(moyenne));
			}
			//console.log(metal, cristal, deut, metal_expe, cristal_expe, deut_expe, metal_cdr, cristal_cdr, total, moyenne, degats, pertes, benef);

			//document.getElementById("nbrRC_").textContent = nbr_rapport;
			document.getElementById("metal total").textContent = metal;
			document.getElementById("crystal total").textContent = cristal;
			document.getElementById("deut total").textContent = deut;
			document.getElementById("metal_cdr total").textContent = metal_cdr;
			document.getElementById("crystal_cdr total").textContent = cristal_cdr;
			document.getElementById("metal_expe total").textContent = metal_expe;
			document.getElementById("crystal_expe total").textContent = cristal_expe;
			document.getElementById("deut_expe total").textContent = deut_expe;
			document.getElementById("somme total").textContent = total;
			document.getElementById("moyenne rc").textContent = moyenne;
			document.getElementById("degats total").textContent = degats;
			document.getElementById("pertes total").textContent = "-"+ pertes;
			document.getElementById("benefices totaux").textContent = benef;

			$(".nbr_rap_rcs").html("&nbsp;&nbsp;("+ i_rcs +")");
			$(".nbr_rap_cdrs").html("&nbsp;&nbsp;("+ i_cdrs +")");
			$(".nbr_rap_expes").html("&nbsp;&nbsp;("+ i_expes +")");
		}

		function mlga_choix_7j() {
			var rcs = new Array(),
				cdrs = new Array(),
				expes = new Array(),
				metal = 0,
				cristal = 0,
				deut = 0,
				metal_cdr = 0,
				cristal_cdr = 0,
				metal_expe = 0,
				cristal_expe = 0,
				deut_expe = 0,
				degats = 0,
				pertes = 0,
				nbr_rapport = 0,
				date = $(".OGameClock").text().split(" ")[0],
				date2 = date,
				jour = parseInt(date.split(".")[0]),
				mois = parseInt(date.split(".")[1]),
				annee = parseInt(date.split(".")[2]);
			date = create_date(jour, mois, annee);
			date2 = create_date(jour -7, mois, annee);

			var i_rcs = 0,
				i_cdrs = 0,
				i_expes = 0;

			if (GM_getValue("conteneur"+univers).combats != 0) {
				rcs = GM_getValue("conteneur"+univers).combats;
				for (var i = 0; i < rcs.length; i++) {
					var date_rc = rcs[i].date.split(" ")[0].split("-");
					date_rc = create_date(date_rc[2], date_rc[1], date_rc[0]);
					if (date_rc <= date && date_rc >= date2) {
						i_rcs++;
						nbr_rapport++;
						metal = metal + ana(parseInt(rcs[i].metal));
						cristal = cristal + ana(parseInt(rcs[i].cristal));
						deut = deut + ana(parseInt(rcs[i].deut));
						degats = degats + ana(parseInt(rcs[i].degats));
						pertes = pertes + ana(parseInt(rcs[i].pertes));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).recyclage != 0) {
				cdrs = GM_getValue("conteneur"+univers).recyclage;
				for (var i = 0; i < cdrs.length; i++) {
					var date_cdr = cdrs[i].date.split(" ")[0].split("-");
					date_cdr = create_date(date_cdr[2], date_cdr[1], date_cdr[0]);
					if (date_cdr <= date && date_cdr >= date2) {
						i_cdrs++;
						metal_cdr = metal_cdr + ana(parseInt(cdrs[i].metal));
						cristal_cdr = cristal_cdr + ana(parseInt(cdrs[i].cristal));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).expedition != 0) {
				expes = GM_getValue("conteneur"+univers).expedition;
				for (var i = 0; i < expes.length; i++) {
					var date_expe = expes[i].date.split(" ")[0].split("-");
					date_expe = create_date(date_expe[2], date_expe[1], date_expe[0]);
					if (date_expe <= date && date_expe >= date2) {
						i_expes++;
						metal_expe = metal_expe + ana(parseInt(expes[i].metal));
						cristal_expe = cristal_expe + ana(parseInt(expes[i].cristal));
						deut_expe = deut_expe + ana(parseInt(expes[i].deut));
					}
				}
			}

			var benef = metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe - pertes,
				total = simpli(metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe);
			metal = simpli(metal);
			cristal = simpli(cristal);
			deut = simpli(deut);
			metal_cdr = simpli(metal_cdr);
			cristal_cdr = simpli(cristal_cdr);
			metal_expe = simpli(metal_expe);
			cristal_expe = simpli(cristal_expe);
			deut_expe = simpli(deut_expe);
			degats = simpli(degats);
			pertes = simpli(pertes);

			if (benef < 0) {
				var moyenne = benef / ana(nbr_rapport);
				benef = "-"+ simpli(benef *(-1));
				moyenne = "-"+ simpli(Math.round(moyenne *(-1)));
			} else {
				var moyenne = benef / ana(nbr_rapport);
				benef = simpli(benef);
				moyenne = simpli(Math.round(moyenne));
			}
			//console.clear();
			//console.log(metal, cristal, deut, metal_expe, cristal_expe, deut_expe, metal_cdr, cristal_cdr, total, moyenne, degats, pertes, benef);

			//document.getElementById("nbrRC_").textContent = nbr_rapport;
			document.getElementById("metal total").textContent = metal;
			document.getElementById("crystal total").textContent = cristal;
			document.getElementById("deut total").textContent = deut;
			document.getElementById("metal_cdr total").textContent = metal_cdr;
			document.getElementById("crystal_cdr total").textContent = cristal_cdr;
			document.getElementById("metal_expe total").textContent = metal_expe;
			document.getElementById("crystal_expe total").textContent = cristal_expe;
			document.getElementById("deut_expe total").textContent = deut_expe;
			document.getElementById("somme total").textContent = total;
			document.getElementById("moyenne rc").textContent = moyenne;
			document.getElementById("degats total").textContent = degats;
			document.getElementById("pertes total").textContent = "-"+ pertes;
			document.getElementById("benefices totaux").textContent = benef;

			$(".nbr_rap_rcs").html("&nbsp;&nbsp;("+ i_rcs +")");
			$(".nbr_rap_cdrs").html("&nbsp;&nbsp;("+ i_cdrs +")");
			$(".nbr_rap_expes").html("&nbsp;&nbsp;("+ i_expes +")");
		}

		function mlga_choix_1m() {
			var rcs = new Array(),
				cdrs = new Array(),
				expes = new Array(),
				metal = 0,
				cristal = 0,
				deut = 0,
				metal_cdr = 0,
				cristal_cdr = 0,
				metal_expe = 0,
				cristal_expe = 0,
				deut_expe = 0,
				degats = 0,
				pertes = 0,
				nbr_rapport = 0,
				date = $(".OGameClock").text().split(" ")[0],
				date2 = date,
				jour = parseInt(date.split(".")[0]),
				mois = parseInt(date.split(".")[1]),
				annee = parseInt(date.split(".")[2]);
			date = create_date(jour, mois, annee);
			date2 = create_date(jour, mois -1, annee);

			var i_rcs = 0,
				i_cdrs = 0,
				i_expes = 0;

			if (GM_getValue("conteneur"+univers).combats != 0) {
				rcs = GM_getValue("conteneur"+univers).combats;
				for (var i = 0; i < rcs.length; i++) {
					var date_rc = rcs[i].date.split(" ")[0].split("-");
					date_rc = create_date(date_rc[2], date_rc[1], date_rc[0]);
					if (date_rc <= date && date_rc >= date2) {
						i_rcs++;
						nbr_rapport++;
						metal = metal + ana(parseInt(rcs[i].metal));
						cristal = cristal + ana(parseInt(rcs[i].cristal));
						deut = deut + ana(parseInt(rcs[i].deut));
						degats = degats + ana(parseInt(rcs[i].degats));
						pertes = pertes + ana(parseInt(rcs[i].pertes));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).recyclage != 0) {
				cdrs = GM_getValue("conteneur"+univers).recyclage;
				for (var i = 0; i < cdrs.length; i++) {
					var date_cdr = cdrs[i].date.split(" ")[0].split("-");
					date_cdr = create_date(date_cdr[2], date_cdr[1], date_cdr[0]);
					if (date_cdr <= date && date_cdr >= date2) {
						i_cdrs++;
						metal_cdr = metal_cdr + ana(parseInt(cdrs[i].metal));
						cristal_cdr = cristal_cdr + ana(parseInt(cdrs[i].cristal));
					}
				}
			}
			if (GM_getValue("conteneur"+univers).expedition != 0) {
				expes = GM_getValue("conteneur"+univers).expedition;
				for (var i = 0; i < expes.length; i++) {
					var date_expe = expes[i].date.split(" ")[0].split("-");
					date_expe = create_date(date_expe[2], date_expe[1], date_expe[0]);
					if (date_expe <= date && date_expe >= date2) {
						i_expes++;
						metal_expe = metal_expe + ana(parseInt(expes[i].metal));
						cristal_expe = cristal_expe + ana(parseInt(expes[i].cristal));
						deut_expe = deut_expe + ana(parseInt(expes[i].deut));
					}
				}
			}

			var benef = metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe - pertes,
				total = simpli(metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe);
			metal = simpli(metal);
			cristal = simpli(cristal);
			deut = simpli(deut);
			metal_cdr = simpli(metal_cdr);
			cristal_cdr = simpli(cristal_cdr);
			metal_expe = simpli(metal_expe);
			cristal_expe = simpli(cristal_expe);
			deut_expe = simpli(deut_expe);
			degats = simpli(degats);
			pertes = simpli(pertes);

			if (benef < 0) {
				var moyenne = benef / ana(nbr_rapport);
				benef = "-"+ simpli(benef *(-1));
				moyenne = "-"+ simpli(Math.round(moyenne *(-1)));
			} else {
				var moyenne = benef / ana(nbr_rapport);
				benef = simpli(benef);
				moyenne = simpli(Math.round(moyenne));
			}
			//console.clear();
			//console.log(metal, cristal, deut, metal_expe, cristal_expe, deut_expe, metal_cdr, cristal_cdr, total, moyenne, degats, pertes, benef);

			//document.getElementById("nbrRC_").textContent = nbr_rapport;
			document.getElementById("metal total").textContent = metal;
			document.getElementById("crystal total").textContent = cristal;
			document.getElementById("deut total").textContent = deut;
			document.getElementById("metal_cdr total").textContent = metal_cdr;
			document.getElementById("crystal_cdr total").textContent = cristal_cdr;
			document.getElementById("metal_expe total").textContent = metal_expe;
			document.getElementById("crystal_expe total").textContent = cristal_expe;
			document.getElementById("deut_expe total").textContent = deut_expe;
			document.getElementById("somme total").textContent = total;
			document.getElementById("moyenne rc").textContent = moyenne;
			document.getElementById("degats total").textContent = degats;
			document.getElementById("pertes total").textContent = "-"+ pertes;
			document.getElementById("benefices totaux").textContent = benef;

			$(".nbr_rap_rcs").html("&nbsp;&nbsp;("+ i_rcs +")");
			$(".nbr_rap_cdrs").html("&nbsp;&nbsp;("+ i_cdrs +")");
			$(".nbr_rap_expes").html("&nbsp;&nbsp;("+ i_expes +")");
		}

		if (document.getElementById("newSpan")) {
			var el = document.getElementById("newSpan");
    		el.parentNode.removeChild(el);
		} else {

			var rcs = new Array(),
				cdrs = new Array(),
				expes = new Array(),
				metal = 0,
				cristal = 0,
				deut = 0,
				metal_cdr = 0,
				cristal_cdr = 0,
				metal_expe = 0,
				cristal_expe = 0,
				deut_expe = 0,
				degats = 0,
				pertes = 0;

			if (GM_getValue("conteneur"+univers).combats != 0) {
				rcs = GM_getValue("conteneur"+univers).combats;
				for (var i = 0; i < rcs.length; i++) {
					//console.log(rcs[i].date);
					metal = metal + ana(parseInt(rcs[i].metal));
					cristal = cristal + ana(parseInt(rcs[i].cristal));
					deut = deut + ana(parseInt(rcs[i].deut));
					degats = degats + ana(parseInt(rcs[i].degats));
					pertes = pertes + ana(parseInt(rcs[i].pertes));
				}
			}
			if (GM_getValue("conteneur"+univers).recyclage != 0) {
				cdrs = GM_getValue("conteneur"+univers).recyclage;
				for (var i = 0; i < cdrs.length; i++) {
					metal_cdr = metal_cdr + ana(parseInt(cdrs[i].metal));
					cristal_cdr = cristal_cdr + ana(parseInt(cdrs[i].cristal));
				}
			}
			if (GM_getValue("conteneur"+univers).expedition != 0) {
				expes = GM_getValue("conteneur"+univers).expedition;
				for (var i = 0; i < expes.length; i++) {
					metal_expe = metal_expe + ana(parseInt(expes[i].metal));
					cristal_expe = cristal_expe + ana(parseInt(expes[i].cristal));
					deut_expe = deut_expe + ana(parseInt(expes[i].deut));
				}
			}

			var benef = metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe - pertes,
				total = simpli(metal + cristal + deut + metal_cdr + cristal_cdr + metal_expe + cristal_expe + deut_expe);
			metal = simpli(metal);
			cristal = simpli(cristal);
			deut = simpli(deut);
			metal_cdr = simpli(metal_cdr);
			cristal_cdr = simpli(cristal_cdr);
			metal_expe = simpli(metal_expe);
			cristal_expe = simpli(cristal_expe);
			deut_expe = simpli(deut_expe);
			degats = simpli(degats);
			pertes = simpli(pertes);

			if (benef < 0) {
				var moyenne = benef / ana(GM_getValue("conteneur"+univers).nbrRC);
				benef = "-"+ simpli(benef *(-1));
				moyenne = "-"+ simpli(Math.round(moyenne *(-1)));
			} else {
				var moyenne = benef / ana(GM_getValue("conteneur"+univers).nbrRC);
				benef = simpli(benef);
				moyenne = simpli(Math.round(moyenne));
			}

			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 ($("#middle")[0]) {
				var sp2 = $("#middle")[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 = `<span id="version">`+ version +`</span><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;">Make Looting Great Again</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:165px;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 class="ogi" style="width: 100%;">
												<thead>
												<tr>
													<th>&nbsp;</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="resourceIcon metal" style="visibility: visible; float: right;"></div>
													</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="resourceIcon crystal" style="visibility: visible; float: right;"></div>
													</th>
													<th width="120" style="visibility: visible; padding: 4px;">
														<div class="resourceIcon deuterium" style="visibility: visible; float: right;"></div>
													</th>
													<th width="1"></th>
												</tr>
											</thead>
											<tbody>
												<tr class="summary alt">
													<td>
														<span class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-weight: 800;">`+ all_pillage +`</span>
														<span class="nbr_rap_rcs" style="font-size: 10px; font-weight: 800; color: grey;">&nbsp;&nbsp;(`+ rcs.length +`)</span>
													</td>
													<td class="bold">
														<span id="metal total" style="visibility: visible; color: #c6556c; font: 12px; float: right;">`+ metal +`</span>
													</td>
													<td class="bold">
														<span id="crystal total" style="visibility: visible; color: #00bfff; font: 12px; float: right;">`+ cristal +`</span>
													</td>
													<td class="bold">
														<span id="deut total" style="visibility: visible; color: #6495e2; font: 12px; float: right;">`+ deut +`</span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr>
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
												<tr class="summary alt">
													<td>
														<span class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-weight: 800;">`+ all_recyclage +`</span>
														<span class="nbr_rap_cdrs" style="font-size: 10px; font-weight: 800; color: grey;">&nbsp;&nbsp;(`+ cdrs.length +`)</span>
													</td>
													<td class="bold">
														<span id="metal_cdr total" style="visibility: visible; color: #c6556c; font: 12px; float: right;">`+ metal_cdr +`</span>
													</td>
													<td class="bold">
														<span id="crystal_cdr total" style="visibility: visible; color: #00bfff; font: 12px; float: right;">`+ cristal_cdr +`</span>
													</td>
													<td class="bold">
														<span id="deut_cdr total" style="visibility: visible; color: #6495e2; font: 12px; float: right;"></span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr>
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
												<tr class="summary alt">
													<td>
														<span class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-weight: 800;">`+ all_expedition +`</span>
														<span class="nbr_rap_expes" style="font-size: 10px; font-weight: 800; color: grey;">&nbsp;&nbsp;(`+ expes.length +`)</span>
													</td>
													<td class="bold">
														<span id="metal_expe total" style="visibility: visible; color: #c6556c; font: 12px; float: right;">`+ metal_expe +`</span>
													</td>
													<td class="bold">
														<span id="crystal_expe total" style="visibility: visible; color: #00bfff; font: 12px; float: right;">`+ cristal_expe +`</span>
													</td>
													<td class="bold">
														<span id="deut_expe total" style="visibility: visible; color: #6495e2; font: 12px; float: right;">`+ deut_expe +`</span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr>
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
												<tr class="summary alt">
													<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">`+ somme_total +`</td>
													<td class="bold">&nbsp;</td>
													<td class="bold">&nbsp;</td>
													<td class="bold">
														<span id="somme total" style="visibility: visible; color: green; font: 12px; font-size: 15px; float: right;">`+ total +`</span>
													</td>
													<td class="bold"></td>
												</tr>
												<tr>
													<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
													<td class="bold">
													</td>
													<!--
														<td>
															<span id="somme total simpli" style="visibility: visible; text-align: right; color: orange; font-weight: 800;"></span>
														</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:116px;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 class="ogi" style="width: 100%;">
										<thead>
											<tr>
												<th>&nbsp;</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="resourceIcoon metal" style="visibility: visible; float: right;"></div>
												</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="resourceIcoon crystal" style="visibility: visible; float: right;"></div>
												</th>
												<th width="120" style="visibility: visible; padding: 4px;">
													<div class="resourceIcoon deuterium" style="visibility: visible; float: right;"></div>
												</th>
												<th width="1"></th>
											</tr>
										</thead>
										<tbody>
											<tr class="summary alt">
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">`+ moyenne_par_rc +`</td>
												<td class="bold">&nbsp;</td>
												<td class="bold">
													<span id="moyenne rc" style="visibility: visible; color: none; font: 12px; font-size: 15px; float: right;">`+ moyenne +`</span>
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold"></td>
											</tr>
											<tr>
												<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											<tr>
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">`+ degat_realise +`</td>
												<td class="bold">&nbsp;</td>
												<td class="bold">
													<span id="degats total" style="visibility: visible; color: green; font: 12px; font-size: 15px; float: right;">`+ degats +`</span>
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold"></td>
											</tr>
											<tr>
												<td class="label" style="visibility: visible; text-align: left;">&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											<tr class="summary alt">
												<td class="label bold-hard" style="visibility: visible; text-align: left; color: grey; font-size: 15px; font-weight: 800;">`+ pertes_subit +`</td>
												<td class="bold">&nbsp;</td>
												<td class="bold">
													<span id="pertes total" style="visibility: visible; color: red; font: 12px; font-size: 15px; float: right;">-`+ pertes +`</span>
												</td>
												<td class="bold">&nbsp;</td>
												<td class="bold"></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;">
										<table class="ogi" style="width: 100%;">
											<thead>
												<tr>
													<th>
														<h1 style="visibility: visible; font: 14.4px; text-align: right; font-weight: bold; font-size: 20px; color: orange;">`+ benefices_totaux +`</h1>
													</th>
													<th width="120">&nbsp;</th>
													<th width="120">
														<h1 id="benefices totaux" style="visibility: visible; font: 14.4px; text-align: right; font-weight: bold; font-size: 20px;">`+ benef +`</h1>
													</th>
													<th width="120">&nbsp;</th>
													<th width="1"></th>
												</tr>
											</thead></table></div>`,
				style_choix = `<div style="text-align: center; margin-right: 10%;">
									<button style="width: 40px; height: 40px; border-radius: 50%;" id="mlga_choix_24h">
										24h
									</button>
									<button style="width: 40px; height: 40px; border-radius: 50%;" id="mlga_choix_7j">
										7j
									</button>
									<button style="width: 40px; height: 40px; border-radius: 50%;" id="mlga_choix_1m">
										1m
									</button></div>`,
				style_reset = `<span id="resetRC" class="btn_blue btn_trash ui-tabs-anchor" role="presentation" tabindex="-1" style="visibility: visible; margin: 10px; margin-right: 50%;">Reset</span>`;

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

			$("button").mouseenter(function() {
				$("#"+this.id).css("background-color", "#90A0A8");
			});
			$("button").mouseleave(function() {
				$("#"+this.id).css("background-color", "");
			});
			document.getElementById('mlga_choix_24h').addEventListener("click", function (event) {
		        mlga_choix_24h();
		    }, true);
		    document.getElementById('mlga_choix_7j').addEventListener("click", function (event) {
		        mlga_choix_7j();
		    }, true);
		    document.getElementById('mlga_choix_1m').addEventListener("click", function (event) {
		        mlga_choix_1m();
		    }, true);

			document.getElementById('resetRC').addEventListener("click", function (event) {
		        resetRC(univers);
		    }, true);	
		}
    }

    // ---------------- BUTTON MENU ---------------- //
   var img = `<span class="menu_icon">
		       <div class="menuImage shipyard"></div>
			</span>`,
    	aff_option = `
        <span class="menu_icon">` +
            img +
        `</span>
        <a class="menubutton" href="#" accesskey="" target="_self">
            <span class="textlabel">
                Make Looting
            </span>
        </a>`;

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


    var url = window.location.href,
		univers = document.getElementsByName("ogame-universe-name")[0].getAttribute("content");

	
	var waitForMessages = setInterval(function() {
	    if (url.search("messages") >= 0) {
	        var button = document.createElement("li");     // On créer le bouton de récupération des rc
	        /*button.innerHTML = `<div id="EnvoiRC_MLGA" class="btn_blue" tabindex="-1" style="visibility: visible; margin: 10px; margin-right: 60px; margin-top: -27px;">
	        						`+ recuperer +`
    							</div>
    							<br>
    							<div style="visibility: visible; margin: 10px; margin-right: 50px; text-align:center; margin-top: -27px;"><br>
    								<span id="avance_recup"></span><span id="total_recup"></span>
    							</div>`;	    
	    	$(".trash_box").append(button);*/
            $(".trash_box").append(`<div id="EnvoiRC_MLGA" class="btn_blue" tabindex="-1" style="visibility: visible; margin: 10px; margin-right: 60px; margin-top: -27px;">
	        						`+ recuperer +`
    							</div>
    							<br>
    							<div style="visibility: visible; margin: 10px; margin-right: 50px; text-align:center; margin-top: -27px;"><br>
    								<span id="avance_recup"></span><span id="total_recup"></span>
    							</div>`);
	    	$(".trash_box").append(button);
	        //document.getElementById('buttonz').getElementsByTagName('ul')[0].appendChild(button);
	        document.getElementById('EnvoiRC_MLGA').addEventListener("click", function (event) {
	            if (document.getElementById("subtabs-nfFleet21").getAttribute("aria-selected") ==  "true") {
					envoi_pillages(univers);
				} else if (document.getElementById("subtabs-nfFleet22").getAttribute("aria-selected") ==  "true") {
					envoi_expe(univers);
				}  else if (document.getElementById("subtabs-nfFleet24").getAttribute("aria-selected") ==  "true") {
					envoi_cdr(univers);
				} else {
					document.getElementById("EnvoiRC_MLGA").textContent = mauvais_menu_messages;
					setTimeout(function(){
						document.getElementById("EnvoiRC_MLGA").textContent = recuperer;
					}, 1000);
				}
	        }, true);
            clearInterval(waitForMessages);
	    } else {}
	}, 50);

	
    document.getElementById('AffichageRc').addEventListener("click", function (event) {
        affichageRC(univers);
    }, true);

    if (document.getElementById("AffichageRc")) {
    	clearInterval(script);
    } else {}
}, 800);