vulca / officierDetect

// ==UserScript==
// @name        officierDetect
// @namespace   officierDetect
// @include     *.ogame*gameforge.com/game/index.php?page=message*
// @include     http://topraider.eu/*
// @updateURL   https://openuserjs.org/install/vulca/officierDetect.user.js
// @downloadURL https://openuserjs.org/install/vulca/officierDetect.user.js
// @author     Vulca
// @version     0.1

// ==/UserScript==

function is_int(value)
{
  if((Math.abs(value - Math.round(value)))<0.005 && !isNaN(value))
  {
      return true;
  } 
  else 
  {
      return false;
  }
}

function officierDetect()
{

    if(document.getElementsByClassName('fleetdefbuildings spy')[0] && ! document.getElementById('officierDetect'))
    {
    	var E=document.getElementsByClassName('fragment spy2')[0].getElementsByTagName('td')[7].textContent.replace(/[^0-9]/g,'');
    	var CeS=0;
    	var CeF=0;
    	var TechE=0;
    	var Sat=0;

    	if(document.getElementsByClassName("fleetdefbuildings spy")[0])
    	{
    		for(var i = 0 ; i < document.getElementsByClassName("fleetdefbuildings spy")[0].getElementsByClassName('value').length ; i++)
    		{
	    		var value=document.getElementsByClassName("fleetdefbuildings spy")[0].getElementsByClassName('value')[i].textContent.replace(/[^0-9]/g,'');
	    		var key	= document.getElementsByClassName("fleetdefbuildings spy")[0].getElementsByClassName('key')[i].textContent;
	    	
	    		if(/Satellite solaire/.test(key))
	    			Sat=value;
    		}
    	}

    	if(document.getElementsByClassName("fleetdefbuildings spy")[2])
    	{
    		for(var i = 0 ; i < document.getElementsByClassName("fleetdefbuildings spy")[2].getElementsByClassName('value').length ; i++)
    		{
	    		var value=document.getElementsByClassName("fleetdefbuildings spy")[2].getElementsByClassName('value')[i].textContent.replace(/[^0-9]/g,'');
	    		var key	= document.getElementsByClassName("fleetdefbuildings spy")[2].getElementsByClassName('key')[i].textContent;
	    	
	    		if(/Centrale électrique solaire/.test(key))
	    			CeS=value;
	    		
	    		if(/Centrale électrique de fusion/.test(key))
	    			CeF=value;
			}
    	}

    	if(document.getElementsByClassName("fleetdefbuildings spy")[3] && CeF>0)
    	{
    		for(var i = 0 ; i < document.getElementsByClassName("fleetdefbuildings spy")[3].getElementsByClassName('value').length ; i++)
    		{
	    		var value=document.getElementsByClassName("fleetdefbuildings spy")[3].getElementsByClassName('value')[i].textContent.replace(/[^0-9]/g,'');
	    		var key	= document.getElementsByClassName("fleetdefbuildings spy")[3].getElementsByClassName('key')[i].textContent;
	    	
	    		if(/Technologie énergétique/.test(key))
	    			TechE=value;
    		}
    	}
      
        var pasfini=true;
        
        while(pasfini)
        {
            if(CeF==0)
                pasfini=false;
            
            
            var ECeS = Math.floor(20*CeS*Math.pow(1.1,CeS));
            var ECeSo = Math.floor(20*CeS*Math.pow(1.1,CeS)*1.1);
            var ECeSfo = Math.floor(20*CeS*Math.pow(1.1,CeS)*1.12);

            var ECeF = Math.floor(30*CeF*Math.pow((1.05+TechE*0.01),CeF));
            var ECeFo = Math.floor(30*CeF*Math.pow((1.05+TechE*0.01),CeF)*1.1);
            var ECeFfo = Math.floor(30*CeF*Math.pow((1.05+TechE*0.01),CeF)*1.12);

            if(Sat>0)
            {
                var pasOff = is_int((E-ECeS-ECeF)/Sat);
                var inge = 	is_int((E-ECeSo-ECeFo)/(Sat*1.1));
                var fullOff = is_int((E-ECeSfo-ECeFfo)/(Sat*1.12));
            }
            else
            {
                var pasOff = (E==ECeS+ECeF);
                var inge = 	(E==ECeSo+ECeFo);
                var fullOff = (E==ECeSfo+ECeFfo);

            }
            
            
            if(pasOff | inge | fullOff)
                pasfini=false;
            else
                CeF=0;
           
        }
        
        if(fullOff) inge=true;
        
         if(pasOff && inge && fullOff)
         {   
             pasOff =false;
             inge =false;
             fullOff=false;
         }

  		var newElement3 = document.createElement("span"); // On crée un nouvelle élément div
        newElement3.innerHTML ='<span style="color:#'+(pasOff?'00ff00':'ff0000')+'">PasOff</span> | '
		+'<span style="color:#'+(inge?'00ff00':'ff0000')+'">ingenieur</span> | '
		+'<span style="color:#'+(fullOff?'00ff00':'ff0000')+'">Full Off</span>'        ;
        
       	newElement3.id ='officierDetect';
        document.getElementsByClassName('infohead')[0].appendChild(newElement3);




    }
}


setInterval(officierDetect,500);