Guest User

Untitled

a guest
Aug 2nd, 2012
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Simulateur v 3.0
  3. // @namespace vulca
  4. // @include http://websim.speedsim.net/index.php*
  5. // @include http://drago-sim.com*
  6. // ==/UserScript==
  7.  
  8.  
  9. // 43 : pas inscrit assez tot, truc invalide
  10. // 108 laro ?
  11.  
  12. function addPoints(nombre)
  13. {
  14.  
  15. var signe = '';
  16. if (nombre<0)
  17. {
  18. nombre = Math.abs(nombre);
  19. signe = '-';
  20. }
  21. nombre=parseInt(nombre);
  22. var str = nombre.toString(), n = str.length;
  23. if (n <4) {return signe + nombre;}
  24. else
  25. {
  26. return signe + (((n % 3) ? str.substr(0, n % 3) + '.' : '') + str.substr(n % 3).match(new RegExp('[0-9]{3}', 'g')).join('.'));
  27. }
  28. }
  29.  
  30. var cout= new Array( 4, 12, 4, 10, 29, 60, 40, 18, 1, 90 , 2.5, 125, 10000, 85, 2, 2, 6, 37, 6, 130, 20, 100);
  31. var ratio = new Array(0.25, 0.25, 1, 1, 1 , 1, 0.25, 0.25, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
  32.  
  33. function speedsim3()
  34. {
  35. var coutDef = 0;
  36. var coutAtt = 0;
  37. var nb=0;
  38.  
  39.  
  40. for (var i =0 ; i<21 ; i++)
  41. {
  42. nb= document.getElementsByName('ship_d_'+i+'_b')[0].value;
  43.  
  44. nb = nb=='' ? 0 : parseInt(nb) ;
  45. coutDef+= nb*cout[i] *ratio[i];
  46.  
  47. if(document.getElementsByName('ship_a_'+i+'_b')[0])
  48. {
  49. nb= document.getElementsByName('ship_a_'+i+'_b')[0].value;
  50.  
  51. nb = nb=='' ? 0 : parseInt(nb) ;
  52. coutAtt+= nb*cout[i] *ratio[i];
  53. }
  54.  
  55.  
  56. var taux = (coutDef ==0 ? 0 : parseInt(coutAtt/ coutDef*100)/100);
  57. var couleur = 'FF9900';
  58.  
  59. if(taux<3) couleur = '00FF00';
  60. else if(taux>5) couleur = 'FF0000';
  61.  
  62.  
  63.  
  64. document.getElementById('shiptable').getElementsByTagName('th')[0].innerHTML = '<span float:"left" style="color:#'+couleur+';" > A: '+addPoints(coutAtt) +' <br/> D: '+ addPoints(coutDef) + '</br> => '+ taux+"</span>";
  65.  
  66. }
  67. //alert(coutDef)
  68. }
  69.  
  70.  
  71. function dragoSim3()
  72. {
  73. var coutDef = 0;
  74. var coutAtt = 0;
  75. var nb=0;
  76. var n=0;
  77.  
  78. var input=document.getElementsByClassName('maintable')[0].getElementsByClassName('number')
  79. var attaquant = true;
  80. for (var i =6 ; i<41 ; i++)
  81. {
  82. nb= input[i].value;
  83. nb = nb=='' ? 0 : parseInt(nb) ;
  84.  
  85. if(i<26) attaquant = (i%2==0)
  86. else if(i<33) attaquant = (i%2==1)
  87. else attaquant = false;
  88.  
  89. if(attaquant) coutAtt+= nb*cout[n] *ratio[n];
  90. else
  91. {
  92. coutDef+= nb*cout[n] *ratio[n];
  93. n++;
  94. }
  95.  
  96. // if(attaquant) input[i].style.backgroundColor="#00FFFF"
  97. //else input[i].style.backgroundColor="#FFFF00"
  98.  
  99.  
  100. }
  101.  
  102. var taux = (coutDef ==0 ? 0 : parseInt(coutAtt/ coutDef*1000)/1000);
  103. var couleur = 'FF9900';
  104.  
  105. if(taux<3) couleur = '00FF00';
  106. else if(taux>5) couleur = 'FF0000';
  107.  
  108. var tr = document.getElementsByClassName('maintable')[0].getElementsByTagName('tr');
  109. tr[7].getElementsByTagName('td')[0].innerHTML = '<b>Flotte <br/><span float:"left" style="color:#'+couleur+';" > A: '+addPoints(coutAtt) +' <br/> D: '+ addPoints(coutDef) + '</br> => '+ taux+"</span></b>";
  110.  
  111.  
  112.  
  113.  
  114.  
  115. }
  116.  
  117. if(/drago-sim/.test(location.href)) setInterval(dragoSim3, 500);
  118. if(/speedsim/.test(location.href))setInterval(speedsim3, 500);
Advertisement
Add Comment
Please, Sign In to add comment