wsmahser / Ogame easy Loot Report

// ==UserScript==
// @name       Ogame easy Loot Report
// @namespace  http://board.fr.ogame.gameforge.com/board1474-ogame-le-jeu/board641-les-cr-ations-ogamiennes/board642-logiciels-tableurs/1103607-easy-loot-report-lister-rapidement-vos-rapports-de-pillages/
// @version    1.0.3
// @description  Petit script pour ogame qui permet d'obtenir rapidement une liste des pillages réalisés \\\\\Little script that allow you to easily share your loots report on your alliance forum.
// @copyright  2014+, Webdo
// @grant		   GM_getValue
// @grant		   GM_setValue
// @grant		   GM_deleteValue
// @grant		   GM_xmlhttpRequest
// @downloadURL https://openuserjs.org/install/wsmahser/Ogame_easy_Loot_Report.user.js
// @updateURL  https://openuserjs.org/install/wsmahser/Ogame_easy_Loot_Report.user.js 
// @include *.ogame.gameforge.com/game/index.php?*page=messages*
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
function ELR_SetCrsStates(){if($(".from").length){if(typeof GM_getValue("bluelist")!=="undefined"&&GM_getValue("bluelist")!==null&&GM_getValue("bluelist")!==""){bluelist=GM_getValue("bluelist");if(bluelist===null){bluelist=""}var e=String(bluelist).split(";");e=$.grep(e,function(e){return e});for(i=0;i<e.length;i++){$("#"+e[i]).find(".combatreport_ididattack_iwon").css("color","blue")}e=""}else{bluelist="";GM_setValue("bluelist","")}}else{setTimeout(ELR_SetCrsStates,100)}}function RessConvert(e){e+="";x=e.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";var t=/(\d+)(\d{3})/;while(t.test(x1)){x1=x1.replace(t,"$1"+"."+"$2")}return x1+x2}function ELR_Generate(e){ELR_SendStats();if(typeof GM_getValue("allloots")!=="undefined"&&GM_getValue("allloots")!==null){t=GM_getValue("allloots")}else{t="";GM_setValue("allloots","")}if(t.length>=20){lootsarray=String(t).split(";");lootsarray=$.grep(lootsarray,function(e){return e});if(e===0){mif_bGreen="[b][color=limegreen]";mif_end_bColor="[/color][/b]";mif_bDarko="[b][color=darkorange]";mif_bRed="[b][color=red]";mif_b="[b]";mif_end_b="[/b]";mif_center="[center]";mif_end_center="[/center]";mif_url="[url=http://board.fr.ogame.gameforge.com/board1474-ogame-le-jeu/board641-les-cr-ations-ogamiennes/board642-logiciels-tableurs/1103607-easy-loot-report-lister-rapidement-vos-rapports-de-pillages][b][color=limegreen]"+lang.elr_generate_url+"[/color][/b][/url]"}else{mif_bGreen='<span style="font-weight:bold;color:limegreen;">';mif_end_bColor="</span>";mif_bDarko='<span style="font-weight:bold;color:darkorange;">';mif_bRed='<span style="font-weight:bold;color:red;">';mif_b='<span style="font-weight:bold;">';mif_end_b="</span>";mif_url='<span style="font-weight:bold;color:limegreen;">'+lang.elr_generate_url+"</span>";mif_center="";mif_end_center=""}asaadd=mif_center+mif_bGreen+""+lootsarray.length+" "+lang.elr_generate_loots+" : "+mif_end_bColor+"<br />";cristal=parseInt(0);metal=parseInt(0);deut=parseInt(0);for(i=0;i<lootsarray.length;i++){if(lootsarray[i].length>=10){var n=lootsarray[i].replace(/\d+([,.]\d+)?/g,function(e){return mif_bDarko+e+mif_end_bColor});var r=lootsarray[i].replace(/\d+([,.]\d+)?/g,function(e){return e});asaclean=r.replace(/[^0-9 ]/g,"").replace(/ /g,";");var s=asaclean.split(";");s=$.grep(s,function(e){return e});metal+=Number(s[0].replace(/\D/g,""));cristal+=Number(s[1].replace(/\D/g,""));deut+=Number(s[2].replace(/\D/g,""));asaadd+=n+"<br />"}}asaadd+="<br /><br/>"+mif_bGreen+lang.elr_generate_result+" :"+mif_end_bColor+"<br /><br/>"+lang.elr_generate_metal+": "+mif_b+RessConvert(metal)+mif_end_b+"<br />"+lang.elr_generate_cristal+": "+mif_b+RessConvert(cristal)+mif_end_b+"<br />"+lang.elr_generate_deut+": "+mif_b+RessConvert(deut)+mif_end_b+"<br /><br />"+lang.elr_generate_renta+" : "+mif_bRed+RessConvert(metal+cristal+deut)+mif_end_bColor+"<br /><br />"+mif_url+mif_end_center;$("#pillageliste").html(asaadd);$("#pillageliste").attr("contenteditable","true")}else{$("#pillageliste").html("<b>"+lang.elr_generate_selectpls+".</b>")}}function ELR_Bug(){$("#pillageliste").attr("contenteditable","false");var e="<b>"+lang.elr_bug_main+"";e+='<textarea id="bug_desc" style="width:500px"></textarea><br /><button id="elr_bugsubmit">'+lang.elr_bug_submit+"</button>";$("#pillageliste").html(e)}function ELR_BugSubmit(){var e="";var t="";lootsarray=String(GM_getValue("allloots")).split(";");lootsarray=$.grep(lootsarray,function(e){return e});for(i=0;i<lootsarray.length&&i<21;i++){e+="{["+i+"]["+lootsarray[i]+"]}"}bluearray=String(GM_getValue("bluelist")).split(";");bluearray=$.grep(bluearray,function(e){return e});for(i=0;i<bluearray.length&&i<21;i++){t+="{["+i+"]["+bluearray[i]+"]}"}var n="";if($("#optionIFC").length){n="|IFC|"}var r="";if($("#ago_menubutton").length){r="|AGO|"}var s="ELR DEBUG OUTPUT GENERATED ON "+date+"<br />";s+="USERAGENT:"+window.navigator.userAgent+"<br />";s+="ELR VERSION:"+version+"<br />";s+="LOOTS NUMBER: "+lootsarray.length+"<br />";if(lootsarray.length!==0){s+="LOOTS CONTENT:"+e.replace(/(\r\n|\n|\r)/gm,"")+"<br/>"}else{s+="BUG FOUND: LOOTS ARE EMPTY! MAYBE USER HAVEN'T CLICKED ON A CR??<br/>"}s+="BLUES NUMBER: "+bluearray.length+"<br />";if(bluearray.length!==0){s+="BLUELIST CONTENT:"+t.replace(/(\r\n|\n|\r)/gm,"")+"<br/>"}else{s+="BUG FOUND: BLUES ARE EMPTY! MAYBE USER HAVEN'T CLICKED ON A CR??<br/>"}if(lootsarray.length!=bluearray.length){s+="BUG FOUND: BLUES AND LOOTS ARE NOT SAME NUMBER!<br/>"}s+="Detected Scripts: "+r+n+"<br/>";s+="</div>";var o=$("#bug_desc").val();$.post("http://911concept.com/ogame/script/elr/bugsubmit.php",{date:date,bugreport:s,user:username,server:server,bug_desc:o},function(e){$("#pillageliste").html(e)})}function ELR_SendStats(){var e=$("#playerName .textBeefy").text().replace(/(\r\n|\n|\r)/gm,"").replace(/ /g,"");var t=document.title;if(GM_getValue("version_stats_sent")!=version){$.post("http://911concept.com/ogame/script/elr/stats.php",{date:date,user:e,server:t,version:version});GM_setValue("version_stats_sent",version)}}function ELR_GetCombatReport(e){if($(".summary").length>0){var n=" \n"+$(".summary table tr:nth-child(2) td:nth-child(2)").text().replace(/\s+/g," ").trim()+";";if(n.length>=40){$(".ui-dialog").hide();$(".summary table tr:nth-child(2) td:nth-child(2)").html("");if(t.indexOf(n)==-1){t+=n;bluelist+=$(e).closest("tr").attr("id")+";"}else{t=t.replace(n,"");bluelist=bluelist.replace($(e).closest("tr").attr("id")+";","");$(e).css("color","")}GM_setValue("allloots",t);GM_setValue("bluelist",bluelist);ELR_SetCrsStates();ELR_Generate(1)}else{setTimeout(function(){ELR_GetCombatReport(e)},100)}}else{setTimeout(function(){ELR_GetCombatReport(e)},100)}}function ELR_GetAllCombatReports(e){$(".combatreport_ididattack_iwon").each(function(e){load=$(this).parents("a").attr("href");$.get(load,function(e){var n=$("<div>").html(e);var r=" \n"+n.find(".summary table tr:nth-child(2) td:nth-child(2)").text().replace(/\s+/g," ").trim()+";";if(t.indexOf(r)==-1){t+=r}GM_setValue("allloots",t);n.remove();ELR_Generate(1)});bluelist+=$(this).closest("tr").attr("id")+";";GM_setValue("bluelist",bluelist)});ELR_SetCrsStates()}function ELR_Reset(){GM_setValue("allloots","");GM_setValue("bluelist","");GM_setValue("generated","");bluearray="";bluelist="";$("#pillageliste").text("");$(".combatreport_ididattack_iwon").css("color","");ELR_Generate(1)}function ELR_SwitchScriptState(e){if(e==1){$("#pillages").hide();$("#elr_switchstate").text("ELR IS OFF");GM_setValue("ACTIVE",0);$(".combatreport_ididattack_iwon").css("color","")}else{GM_setValue("ACTIVE",1);$("#pillages").show();$("#elr_switchstate").text("ELR IS ON");ELR_SetCrsStates();ELR_Generate(1)}}var version="1.0.4";var date=new Date;date=date.getDate()+"/"+(parseInt(date.getMonth(),10)+1)+"/"+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes();var username=$("#playerName .textBeefy").text().replace(/(\r\n|\n|\r)/gm,"").replace(/ /g,"");var server=document.title;var bluelist="";var cristal=parseInt(0);var metal=parseInt(0);var deut=parseInt(0);var tabshtml="";var mif_bGreen="";var mif_end_bColor="";var mif_bDarko="";var mif_bRed="";var mif_b="";var mif_end_b="";var mif_url="";var mif_center="";var mif_end_center="";var i18n=$("meta[name=ogame-language]").attr("content");var lang={scriptname:"Easy loot Report",b_getall:"Get all CR",b_preview:"Preview",b_forum:"Board",b_reset:"Reset",b_bug:"Bug?",b_getall_t:"Automatically retrieves all CR of the current page.",b_preview_t:"Generate an overview of all loots",b_forum_t:"Generate BBCODE for boards.",b_reset_t:"Reset loots list.",b_bug_t:"Report a bug",b_elr_ison:"ELR IS ON",b_elr_isoff:"ELR IS OFF",elr_bug_main:'Describe the problem and click "submit a bug report" <br /> Remember to include your email or skype so that we can contact you.',elr_bug_submit:"Submit bug report",elr_generate_selectpls:'Click on a CR or on "Get all CR" to generate a report',elr_generate_result:"Results",elr_generate_metal:"Metal",elr_generate_cristal:"Crytal",elr_generate_deut:"Deuterium",elr_generate_renta:"Rentability",elr_generate_url:"Loot report generated with Ogame Easy Loot Report (By webdo)",elr_generate_loots:"loots"};if(i18n=="fr"){lang={scriptname:"Easy loot Report",b_getall:"Récupérer tous",b_preview:"Aperçu",b_forum:"Forum",b_reset:"Reinitialiser",b_bug:"Bug?",b_getall_t:"Récupère automatiquement tous les rapports de combats de la page actuelle.",b_preview_t:"Génére un apercu en couleur des pillages.",b_forum_t:"Génére le BBCODE pour le forum.",b_reset_t:"Réinitialise la liste des pillages.",b_bug_t:"Rapporter un bug",b_elr_ison:"ELR IS ON",b_elr_isoff:"ELR IS OFF",elr_bug_main:'Décrivez le problème et cliquez sur "Soumettre un rapport de bug"<br />Pensez à inclure votre courriel ou votre skype afin que l\'on puisse vous recontacter',elr_bug_submit:"Soumettre le rapport",elr_generate_selectpls:'Cliquez sur un rapport de combat ou sur "Récupérer tous" afin de générer un rapport',elr_generate_result:"Bilan",elr_generate_metal:"Métal",elr_generate_cristal:"Cristal",elr_generate_deut:"Deutérium",elr_generate_renta:"Rentabilité",elr_generate_url:"Rapport de pillage réalisé avec Ogame Easy Loot Report (Par webdo)",elr_generate_loots:"pillages"}}$(window).load(function(){setTimeout(function(){if(typeof GM_getValue("allloots")!=="undefined"&&GM_getValue("allloots")!==null){t=GM_getValue("allloots")}else{t="";GM_setValue("allloots","")}if(typeof GM_getValue("ACTIVE")=="undefined"||GM_getValue("ACTIVE")===null){GM_setValue("ACTIVE",0)}if(GM_getValue("ACTIVE")===0){text=lang.b_elr_isoff;disp="none"}else{text=lang.b_elr_ison;disp="block";ELR_Generate(1);setTimeout(function(){ELR_Generate(1)},100);ELR_SetCrsStates()}$(".tabsbelow").append('<div style="display:block;padding:3px;"><a href="javascript:void(0);" id="elr_switchstate" style="color:green;text-decoration:none;font-weight:bold">&nbsp;&nbsp;&nbsp;'+text+"</a><div>");tabshtml+='<div id="pillages"style="display:'+disp+';width:597px;background-color:#14191f;border:10px #0d1014 solid;padding:0px 20px 20px 20px;margin-left:-25px;margin-top:10px;margin-bottom:10px;height:250px;overflow:hidden">';tabshtml+='<center><span style="color:green;font-size:18px;">'+lang.scriptname+"</span><br/>";tabshtml+='<div style="text-align:left;font-weight:bold;font-size:14px;color:#ffffff;padding-left:5px;">';tabshtml+='<a title="'+lang.b_getall_t+'" style="text-align:left;font-weight:bold;font-size:14px;color:#ffffff;padding-left:5px;text-decoration:none" id="elr_getall" href="javascript:void(0);"> '+lang.b_getall+"</a> |";tabshtml+='<a title="'+lang.b_preview_t+'" style="text-align:left;font-weight:bold;font-size:14px;color:#ffffff;padding-left:5px;text-decoration:none;" id="elr_generateprev" href="javascript:void(0);"> '+lang.b_preview+"</a> |";tabshtml+='<a title="'+lang.b_forum_t+'" style="text-align:left;font-weight:bold;font-size:14px;color:#ffffff;padding-left:5px;text-decoration:none;" id="elr_generate" href="javascript:void(0);"> '+lang.b_forum+"</a> |";tabshtml+='<a title="'+lang.b_reset_t+'" style="text-align:left;font-weight:bold;font-size:14px;color:#ffffff;padding-left:5px;text-decoration:none" id="elr_reset" href="javascript:void(0);"> '+lang.b_reset+"</a>";tabshtml+='<a title="'+lang.b_bug_t+'" style="margin-left:155px;text-align:left;font-weight:bold;font-size:11px;color:red;padding-left:5px;text-decoration:none" id="elr_bug" href="javascript:void(0);"> '+lang.b_bug+"</a></div></center><br/>";tabshtml+='<div id="pillageliste" style="padding-top:10px;height:195px;overflow-y:auto;overflow-x:hidden;border:1px #ffffff solid;text-align:center"" ></div></div>';$("#tabs").append(tabshtml)},500)});$(document).on("click",".icon_rewind, .icon_fastforward, icon_fastforward, .icon_skip_back, .icon icon_skip, .reiter, .tabsbelow ",function(){if(GM_getValue("ACTIVE")==1){ELR_SetCrsStates()}});$(document).on("click","#elr_reset",function(){if(GM_getValue("ACTIVE")==1){ELR_Reset()}});$(document).on("click","#elr_bug",function(){ELR_Bug()});$(document).on("click","#elr_bugsubmit",function(){ELR_BugSubmit()});$(document).on("click","#elr_generate",function(){if(GM_getValue("ACTIVE")==1){ELR_Generate(0)}});$(document).on("click","#elr_getall",function(){if(GM_getValue("ACTIVE")==1){ELR_GetAllCombatReports()}});$(document).on("click","#elr_generateprev",function(){if(GM_getValue("ACTIVE")==1){ELR_Generate(1)}});$(document).on("click","#elr_switchstate",function(){ELR_SwitchScriptState(GM_getValue("ACTIVE"))});$(document).on("click",".combatreport_ididattack_iwon",function(){if(GM_getValue("ACTIVE")==1){ELR_GetCombatReport($(this))}})