wukodlak / show planets

// ==UserScript==
// @name        show planets
// @namespace   local_time
// @description Shows local time in Retro Server
// @include     *://ogame1304.de/game/index.php?page=overview&session=*
// @include     *://ogame1304.de/game/index.php?page=b_building&session=*
// @require		https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @author 		wukodlak
// @version     1.0
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_deleteValue
// ==/UserScript==

/*
 *  Vu_getValue - Vu_setValue
 *
 *  Permet de gérer la compatibilité mobile pour les get/setValue de GreaseMonkey
 *********************************************************************************/
function Vu_getValue(key,defaultVal)
{
     try
     {  return GM_getValue(key,defaultVal);    }
     catch( err )
     {
        return defaultVal;
     }
}

function Vu_setValue(key,value)
{
     try
     {  GM_setValue(key,value); }
     catch( err )
     {}
}

var ListingPlanetVsSize = 'Listing des planètes<br/>'  ;
// app
(function()
{
	Element.prototype.hasClass = function(className) {
        return this.className && new RegExp("(^|\\s)" + className + "(\\s|$)").test(this.className);
    };

	/*
	 *  raidsTable_init
	 *
	 *  initialisation du tableau raidsTable
	 *****************************************************************************************/
	function showPlanetsCoord_init()
	{

       var planets_coords =  Vu_getValue('planetsCoords_oldSchool', 'coord1|coord2|coord3|coord4|coord5|coord6|coord7|coord8|coord9|');
        var planets_size =  Vu_getValue('planetsSize_oldSchool', 'taille1|taille2|taille3|taille4|taille5|taille6|taille7|taille8|taille9|');


      /*  console.log(' ______visu de base________' ) ;
        console.log( planets_coords ) ;
        console.log( planets_size ) ;
        console.log(' _______visu de base_______' ) ;*/

         var planets_coords_split = planets_coords.split('|');
         var planets_size_split = planets_size.split('|');

		 // récupération de coordonnées

		  var divs = document.getElementsByTagName('select');
		  for (var i = 0 ; i < divs.length ; i++)
		  {
			if (divs[i].parentNode.className=='header' )
			{
			  var coords = divs[i].querySelectorAll('option');
                var temp = 0 ;
			  for(var j = 0; j < coords.length; j++)
			  {
				  // extraction des coord
                  temp = j+1 ;
				  planets_coords_split[j] = coords[j].innerHTML.match(/\[.+\]/)[0].split('[')[1].replace(/\[|\]/g,'') ;
			      ListingPlanetVsSize +=  'pla'+ temp + ' : ' +  planets_coords_split[j] + ' = '+ planets_size_split[j] + '<br/>' ;
               //   console.log( 'pla'+ temp + ' : ' +  planets_coords_split[j] + ' = '+ planets_size_split[j] );

			  }
			}
			else{ console.log( 'rien' ); }
		  }


        // récupération des tailles
        var coord_pla =  $("th:contains(Position)").next().text().match(/\[.+\]/)[0].split('[')[1].replace(/\[|\]/g,'') ;

        var index_pla = planets_coords_split.indexOf(coord_pla); // +1
        //console.log( 'index planète '+ index_pla );

        /***********/
        if (planets_coords_split.indexOf(coord_pla) === -1) {
            planets_coords_split.push(coord_pla);
        //    console.log('Le nouveau tableau est : ' + planets_coords_split);
        } else if (planets_coords_split.indexOf(coord_pla) > -1) {
        //    console.log(coord_pla + ' existe déjà dans le tableau.');
        }
        /***********/

         planets_size_split[index_pla] = $("th:contains(Diameter)").next().text().match(/\d+/g)[2] + '/' + $("th:contains(Diameter)").next().text().match(/\d+/g)[3];

      //  console.log ( coord_pla + ' = ' + planets_size_split[index_pla]  );

        var planetCoordSave = planets_coords_split.join('|');
        var sizeSave = planets_size_split.join('|') ;

      /*
        console.log(' ___________________' ) ;
        console.log( planetCoordSave ) ;
        console.log( sizeSave ) ;
        console.log(' ___________________' ) ;
      */
         Vu_setValue('planetsCoords_oldSchool', planetCoordSave);
         Vu_setValue('planetsSize_oldSchool', sizeSave );

         // Bouton options
  
    var td_ShowPlanetsSize = '<td id="showPlanetSize"><div align="left" style="font-size:1em;color:#00ff00;">'+ListingPlanetVsSize+'</div></td>';
  
    var tr_ShowPlanetsSize = document.createElement("tr");
    tr_ShowPlanetsSize.innerHTML = td_ShowPlanetsSize;
    tr_ShowPlanetsSize.id = 'showPlanetSize';
    document.getElementsByTagName('tbody')[3].appendChild(tr_ShowPlanetsSize);

	}

    function showPlanetsMines_init()
	{
        console.log("recherche des mines");
        var content =  document.querySelectorAll('tbody');
        var tabMines = content[4];
        console.log( tabMines.innerHTML );
        
        // />(?:[a-zA-Z]+ [a-zA-Z]+<\/a> \(level (\d+)\))</g
        console.log( tabMines.textContent.match(/>(?:[a-zA-Z]+ [a-zA-Z]+<\/a> \(level (\d+)\))</g) );
        
       // MetalMine =  tabMines.getElementsByClassName('l')[1].textContent.match(/(\d+)\)/)[1] ; 
      //  console.log( MetalMine); // métal
                   
      //  console.log( tabMines.getElementsByClassName('l')[1].textContent ); // métal
    /*    
        console.log( tabMines.getElementsByClassName('l')[1].textContent ); // métal
        console.log( tabMines.getElementsByClassName('l')[3].textContent ); // cristal
        console.log( tabMines.getElementsByClassName('l')[5].textContent ); // deut
        console.log( tabMines.getElementsByClassName('l')[7].textContent ); // centrale Solaire
        console.log( tabMines.getElementsByClassName('l')[9].textContent ); // centrale fusion
        console.log( tabMines.getElementsByClassName('l')[11].textContent ); // robot
        console.log( tabMines.getElementsByClassName('l')[13].textContent ); // chantier
        console.log( tabMines.getElementsByClassName('l')[15].textContent ); // hangar M
        console.log( tabMines.getElementsByClassName('l')[17].textContent ); // hangar C
        console.log( tabMines.getElementsByClassName('l')[19].textContent ); // hangar D
        console.log( tabMines.getElementsByClassName('l')[21].textContent ); // Labo
        console.log( tabMines.getElementsByClassName('l')[23].textContent ); // Silo
        
        
        console.log( tabMines.getElementsByClassName('l')[1].textContent.match(/(\d+)\)/)[1] ); // métal
        console.log( tabMines.getElementsByClassName('l')[3].textContent.match(/(\d+)\)/)[1] ); // cristal
        console.log( tabMines.getElementsByClassName('l')[5].textContent.match(/(\d+)\)/)[1] ); // deut
        console.log( tabMines.getElementsByClassName('l')[7].textContent.match(/(\d+)\)/)[1] ); // centrale Solaire
        console.log( tabMines.getElementsByClassName('l')[9].textContent.match(/((\d+))/)[1] ); // centrale fusion
        console.log( tabMines.getElementsByClassName('l')[11].textContent.match(/(\d+)\)/)[1] ); // robot
        console.log( tabMines.getElementsByClassName('l')[13].textContent.match(/(\d+)\)/)[1] ); // chantier
        console.log( tabMines.getElementsByClassName('l')[15].textContent.match(/(\d+)\)/)[1] ); // hangar M
        console.log( tabMines.getElementsByClassName('l')[17].textContent.match(/(\d+)\)/)[1] ); // hangar C
        console.log( tabMines.getElementsByClassName('l')[19].textContent.match(/(\d+)\)/)[1] ); // hangar D
        console.log( tabMines.getElementsByClassName('l')[21].textContent.match(/(\d+)\)/)[1] ); // Labo
        console.log( tabMines.getElementsByClassName('l')[23].textContent.match(/(\d+)\)/)[1] ); // Silo
*/

        

  /*
                var tabMines = document.getElementsByTagName('tbody').next();
        console.log( 'nb tr :'+tabMines.length );

         for (var i = 0 ; i < tabMines.length ; i++)
		  {

			  var Batiment = tabMines[i].querySelectorAll('tr');
              var temp = 0 ;
              var type_bat ;
			  for(var j = 0; j < Batiment.length; j++)
			  {
				  // extraction des coord
                  temp = j+1 ;
				  type_bat[j] = Batiment[j].innerHTML ; //split('[')[1].replace(/\[|\]/g,'') ;

                  console.log( 'batiment :'+type_bat[j] );

			  }
		  }
*/
        // récupération des tailles
      //  var Mine_Metal =  $("td").innerHTML.match(/\(.+\)/)[0].split('(')[1] ;
       // console.log(Mine_Metal);

    }


	if(/page=overview&session=/.test(location.href)  )
	{
        //GM_deleteValue('planetsCoords'+info.serveur);
       // GM_deleteValue('planetsSize'+info.serveur);

        // init du script
		//setInterval(showPlanetsCoord_init, 1050);
        showPlanetsCoord_init();
	}
    else if(/page=b_building&session=/.test(location.href)  )
	{


        showPlanetsMines_init();
        // init du script
		//setInterval(showPlanetsCoord_init, 1050);
        //showPlanetsCoord_init();
	}
})();