ForwardUntoDawn / GTC_Extend_Num_PRIVATE

// ==UserScript==
// @name        GTC_Extend_Num_PRIVATE
// @namespace   GTC_Extend_Num_PRIVATE
// @description Agrandit les cases de numéros de parc, ajoute une barre de progression pour l'état moteur et affiche les moyennes d'âge, kilométrique, et d'état du parc.
// @include     http://www.gestion-tc.com/parc.php
// @include     http://gestion-tc.com/parc.php
// @include     http://www.gestion-tc.com/parc.php?change_numero=ok
// @include     http://gestion-tc.com/parc.php?change_numero=ok
// @include     http://www.gestion-tc.com/occasion.php
// @include     http://gestion-tc.com/occasion.php
// @include     http://www.gestion-tc.com/occasion.php?id=*
// @include     http://gestion-tc.com/occasion.php?id=*
// @version     1.6.26.P
// @grant       none
// @author      ForwardUntoDawn/Paul 714
// ==/UserScript==
var main = document.getElementById('corps');
var co = main.getElementsByTagName('span');
co[1].id='content' ;
etat_texte = ["Neuf","Excellent", "Très bon", "Bon", "Correct", "Passable", "Moyen", "Mauvais", "Très mauvais", "Catastrophique", "Épave"];
etat_num = [100, 95, 90, 75, 65, 60, 50, 30, 10, 5, 0];
var content = document.getElementById('content');
var contentiH = content.innerHTML;
var dA = 'véhicules dans ton parc | Âge moyen : <div style="display: inline-block; font-weight: bold;" id="ageParc"></div> ans | Moyenne kilométrique : <div style="display: inline-block; font-weight: bold;" id="kmParc"></div> km | État moyen : <div style="display: inline-block; font-weight: bold;" id="etatParc"></div> % :)';
var nco = contentiH.replace('véhicules dans ton parc', dA);
content.innerHTML = nco;
var nums = document.getElementsByName('num');
var sp;
var iH;
var prog;
var esp;
var start;
var dateiH;
var datel;
var dateSum = 0;
var nbre_dates = 0;
var date = new Date();
var cu_year = date.getFullYear();
var cu_year = parseInt(cu_year);
var age;
var age_moyen;
var etat;
var kmSum = 0;
var etSum = 0;
var kmiH;
var kmMoyen = 0;
var etatMoyen = 0;
var num_size = 10;
var listtd = document.getElementsByTagName('td');
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > - 1;
var a = window.location;
var b = a.toString();
var listli = document.getElementsByTagName('li');
var lli = listli.length;
var lai = listli[lli-2];
var lip = lai.parentNode;
var dispExtN = localStorage.getItem("displayEN");
var dE = '';
var dispBarres = localStorage.getItem("displayEB");
var db = '';
var dispAge = "true";
var options_initial_style = 'display: none;';
if(dispExtN == "true")
{
    var dE = 'checked="'+dispExtN+'"';
}
if(dispBarres == "true")
{
    var dB = 'checked="'+dispExtN+'"';
}
if (typeof localStorage.getItem("displayEN") == 'undefined')
{
    dispExtN = true;
    localStorage.setItem("displayEN", dispExtN);
}
if (typeof localStorage.getItem("displayEB") == 'undefined')
{
    dispBarres = true;
    localStorage.setItem("displayEB", dispBarres);
}
if(is_chrome)
{
    options_initial_style = 'width: 700px; height: 80px; line-height: 80px; display: inline-block;';
}
var options = '<br /><br /><form id="GTCEN_options" action="" style="'+options_initial_style+'"><div class="optCheckBox" style="width: 30px; height: 30px; line-height: 30px; display: inline-block;"><input type="checkbox" id="ENoptC" '+dE+' onchange="localStorage.setItem(\'displayEN\', this.checked);" /></div><div class="optText" style=\"width: 300px; height: 30px; line-height: 30px; display: inline-block; padding-left: 10px;">Étendre les cases de numéros de parcs</div><br /><div class="optCheckBox" style="width: 30px; height: 30px; line-height: 30px; display: inline-block;"><input type="checkbox" id="ENoptB" '+dB+' onchange="localStorage.setItem(\'displayEB\', this.checked);" /></div><div class="optText" style="width: 300px; height: 30px; line-height: 30px; display: inline-block; padding-left: 10px;">Afficher les barres d\'état des véhicules</div></form>';
var miH = main.innerHTML;
main.innerHTML = options + miH;
liH = lip.innerHTML + '<li id="GTCEN_Options" style="display: inline-block; clear: both; width: 108px; float: none; height: 100%;"><a href="#" onclick="javascript:document.getElementById(\'content\').style=\'display: none; visibility: hidden;\'; document.getElementById(\'GTCEN_options\').style=\'width: 700px; height: 30px; line-height: 30px; display: inline-block;\';" style="height: 22px; width: 100px; padding: 9px 4px; line-height: 22px; display: block">GTCEN Opt.</a></li>';
lip.innerHTML = liH;

//INIT.END//

if (typeof localStorage != 'undefined')
{
  if (localStorage.getItem("num_size") !== null && b.indexOf('parc.php') > -1 && dispExtN == "true")
  {
    var num_size = localStorage.getItem("num_size");
    var brd = document.getElementById('corps');
    var brdH = brd.innerHTML;
    brd.innerHTML = 'Largeur des cases de numéros de parc : <textarea id="GTC_Extend_Num_size" maxlength="2" style="width: 30px; height: 18px; resize: none; text-align: center;" onchange="if(this.value < 21 && this.value > 0) { localStorage.setItem(\'num_size\', this.value); this.style=\'width: 30px; height: 18px; resize: none; background-color: #00FF00; text-align: center;\';} else { localStorage.setItem(\'num_size\', 10); this.style=\'width: 30px; height: 18px; resize: none; background-color: #FF0000; text-align: center;\';}">'+num_size+'</textarea>' + brdH;
  } 
  else
  {
    if(b.indexOf('parc.php') > -1 && dispExtN == "true")
    {
      localStorage.setItem("num_size", 10);
    }
  }
}
if(b.indexOf('parc.php' > -1) && dispExtN == "true")
{
    for (i = 0; i < nums.length; i++)
    {
        nums[i].size = num_size;
    }
}
if (b.indexOf('occasion.php') > - 1 && b.indexOf('?id=') == -1)
{
  esp = 7;
  start = 11;
}
else
if (b.indexOf('occasion.php?id=') > - 1)
{
    esp = 7;
    start = 1;
    var sec = 32 - esp;
}
else
if (b.indexOf('parc.php') > - 1)
{
  esp = 15;
  start = 6;
}
if (is_chrome)
{
  var w = 102;
} 
else
{
  var w = 80;
}
for (i = start; i < listtd.length; i = i + esp)
{
  if (listtd !== null && listtd[i].innerHTML != '<b>État</b>')
  {
    listtd[i].style = "text-align: center; white-space: normal;";
    sp = listtd[i].getElementsByTagName('span') [0];
    iH = sp.innerHTML;
    etat = iH.replace('%', '');
    for(iet = 0; iet <= etat_texte.length; iet++)
    {
        if(etat_texte[iet] == etat)
        {
            etat = etat_num[iet];
        }
    }
    if(dispBarres == "true")
    {
        prog = '<progress id=etat_bus_progbar max=\'100\' value=\'' + etat + '\' style=\'width: ' + w + 'px; height: 22px;\'></progress> ';
        iH = prog + '<span class="etat_bus" style="width: 100%; display : inline-block; text-align: center;">' + etat + '%</span>';
        sp.innerHTML = iH;
        st = sp.getAttribute('style');
        sp.style = st + ' min-height: 24px; display: inline-block; line-height: 24px; overflow: hidden; text-align: center;';
        if (b.indexOf('occasion.php?id=') > -1 && i == 1)
        {
            prog = '';
            iH = prog + '<span class="etat_bus" style="text-align: center;">' + etat + '%</span>';
            sp.innerHTML = iH;
            sp.style = st;
            listtd[i].style = "";
        }
    }
    if(b.indexOf('parc.php') > - 1)
    {
        etSum += parseInt(etat);
        kmiH = listtd[i-1].innerHTML;
        kmiH = kmiH.replace(' ', '');
        kmiH = parseInt(kmiH);
        kmSum += kmiH;
        dateiH = listtd[i+1].innerHTML;
        datel = dateiH.length;
        dateiH = dateiH.substring(datel - 4, datel);
        dateiH = parseInt(dateiH);
        age = cu_year - dateiH;
        dateSum += age;
        nbre_dates++;
    }
  } 
  else
  {
  }
  if (b.indexOf('occasion.php?id=') > - 1 && sec !== false)
  {
      i = sec;
      sec = false;
  }
}
if(dispAge == "true")
{
    age = dateSum/nbre_dates;
    age = age.toFixed(2);
    age = String(age);
    kmMoyen = kmSum/nbre_dates;
    kmMoyen = kmMoyen.toFixed(2);
    kmMoyen = String(kmMoyen);
    etatMoyen = etSum/nbre_dates;
    etatMoyen = etatMoyen.toFixed(2);
    etatMoyen = String(etatMoyen);
    var aDiv = document.getElementById('ageParc');
    var kDiv = document.getElementById('kmParc');
    var eDiv = document.getElementById('etatParc');
    aDiv.innerHTML = age;
    kDiv.innerHTML = kmMoyen;
    eDiv.innerHTML = etatMoyen;
}