Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. // ==UserScript==
  2. // @name HLL
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Plainte tous les citoyens en ville
  6. // @author You
  7. // @include https://hordes-la-loi.fr/neighbours/
  8. // @include https://hordes-la-loi.fr/cities/current/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /*
  13. <option value="6">Animateur de villes</option>
  14. <option value="2">Citoyen de confiance</option>
  15. <option value="7">Guide spirituel</option>
  16. <option value="3">La personne la plus classe du monde</option>
  17. <option value="4">Leader de choc</option>
  18. <option value="5">Plus impliqué, tu meurs !</option>
  19. */
  20. var conseilsList = [6, 2, 7, 3, 4, 5];
  21.  
  22. /*
  23. <option value="17">A pas compris ce qu'est Hordes</option>
  24. <option value="21">Chouineuse de Première Classe</option>
  25. <option value="10">Citoyen agressif !</option>
  26. <option value="22">Consanguin</option>
  27. <option value="19">Délit de sale gueule</option>
  28. <option value="9">Inactif</option>
  29. <option value="7">Joue en ermite</option>
  30. <option value="15">Mort comme un plow</option>
  31. <option value="14">Mouton</option>
  32. <option value="12">Pictopute</option>
  33. <option value="1">Pille la banque</option>
  34. <option value="13">Pourrisseur</option>
  35. <option value="6">Reste toujours au chaud</option>
  36. <option value="20">Suicide pour le besoin d'autrui</option>
  37. */
  38.  
  39. var plaintesList = [17, 21, 10, 22, 19, 9, 7, 15, 14, 12, 1, 13, 6, 20];
  40.  
  41. var raclures = [636670, 607031, 578092, 351347, 255882, 99058, 973320, 650618, 412466, 586595, 858364, 414048, 905440, 939928, 581099, 786323, 548899, 662054, 457755, 394614, 924674, 917399, 615237, 33649, 911438, 720089,
  42. 635027, 544124, 841310, 68020, 222045, 26276, 717422, 270994, 420760, 861595, 795200, 765859, 603144, 880941, 343485, 197187, 390304, 712458, 882449, 246750, 112829, 963273, 276165, 711583, 973281, 691173,
  43. 688446, 377775, 589303, 424566, 727936, 699174, 374805, 378036, 538435, 331449, 153107, 969176, 668804, 693648, 684150, 982258, 674482, 634160, 528169, 530615, 423232, 324752, 716620, 714278, 478608, 964768,
  44. 870153, 288355, 514612, 491342, 11826, 948564, 722193, 709055, 163706, 107441, 930274, 838193, 520045, 990230, 916722, 746119, 581020, 499258, 954678, 895385, 894215, 777678, 563503, 559669, 452311, 362706,
  45. 340299, 160348, 94108, 948991, 795577, 929356, 896048, 860176, 841398, 840049, 756019, 643187, 238595, 96474, 986381, 908741, 762432, 739125, 405155, 107590, 981794, 981107, 960139, 758708, 599279, 577117,
  46. 418118, 288102, 939772, 931110, 893303, 889195, 859043, 607592, 981562, 950874, 927430, 886300, 854043];
  47.  
  48. function insertHLL()
  49. {
  50. //<iframe id="extFrame" src="http://www.mySite.com/myPageToInsert.html"></iframe>
  51. }
  52.  
  53.  
  54. function rand()
  55. {
  56. return parseInt(Math.random()*4294967295, 10);
  57. }
  58.  
  59. function give_adviceCustom(type, playerID, complainteID)
  60. {
  61. var xhr = new XMLHttpRequest();
  62. xhr.open('GET', '/controllers/advices/' + type + '.php?id=' + playerID + '&c=' + complainteID, false);
  63. xhr.send(null);
  64. }
  65.  
  66. function setRandomPlainte(playerID)
  67. {
  68. var r = rand()%plaintesList.length;
  69. give_adviceCustom("complaints", playerID, plaintesList[r]);
  70. }
  71.  
  72. function setRandomConseil(playerID)
  73. {
  74. give_adviceCustom("councils", playerID, conseilsList[rand()%conseilsList.length]);
  75. }
  76.  
  77. function updateProgress(handled, plaintes, conseils)
  78. {
  79. var progressElem = document.getElementsByClassName("progress")[0];
  80. //alert("prgoress content: " + progressElem.innerHTML);
  81. var progress = "Citoyens traités: " + handled + ", Plaintés: " + plaintes + ", conseilés: " + conseils;
  82. //alert(progress);
  83. progressElem.innerHTML = progress;
  84. }
  85.  
  86. function plainteConseilTouteLaVille()
  87. {
  88. var citizens = document.getElementsByClassName("table-cell")[0].children[2].children;
  89.  
  90. var plaintesGiven = 0;
  91. var conseilsGiven = 0;
  92.  
  93. //alert(citizens.length);
  94.  
  95. for(var i = 0; i < citizens.length; i++)
  96. {
  97. updateProgress(i, plaintesGiven, conseilsGiven);
  98.  
  99. var playerID = citizens[i].getAttribute("href");
  100. //ex: /users/993514/
  101. playerID = playerID.substring(7, playerID.length-1);
  102.  
  103. var toParse = citizens[i].children[0].textContent;
  104. //ex: (16 conseils, 18 plaintes)
  105. //ex: (1 conseil, 2 plaintes)
  106. //ex: (1 conseil, 0 plainte)
  107. toParse = toParse.split(',');
  108.  
  109. toParse[0] = toParse[0].replace('(', "");
  110. toParse[0] = toParse[0].replace(" conseils", "");
  111. toParse[0] = toParse[0].replace(" conseil", "");
  112.  
  113. toParse[1] = toParse[1].replace(" ", "");
  114. toParse[1] = toParse[1].replace(" plaintes)", "");
  115. toParse[1] = toParse[1].replace(" plainte)", "");
  116.  
  117. //alert("conseil: " + toParse[0]);
  118. //alert("plainte: " + toParse[1]);
  119.  
  120. var conseils = parseFloat(toParse[0]);
  121. var plaintes = parseFloat(toParse[1]);
  122.  
  123. if(conseils+plaintes == 0)
  124. {
  125. setRandomPlainte(playerID);
  126. plaintesGiven++;
  127. continue;
  128. }
  129.  
  130. var ratio = plaintes/(conseils+plaintes);
  131.  
  132. if(plaintes > 30 && ratio > 0.75) //si le joueur a déjà une majorité de plainte(plus de 3/4) lui mettre un conseil
  133. {
  134. setRandomConseil(playerID);
  135. conseilsGiven++;
  136. }
  137. else //sinon lui mettre une plainte
  138. {
  139. setRandomPlainte(playerID);
  140. plaintesGiven++;
  141. }
  142.  
  143. /*if(ratio > 0.75) //si le joueur a déjà une majorité de plainte(plus de 3/4) lui mettre un conseil
  144. {
  145. setRandomConseil(playerID);
  146. conseilsGiven++;
  147. }
  148. else if(plaintes > 50 && ratio > 0.70)
  149. {
  150. continue;
  151. }
  152. else //sinon lui mettre une plainte
  153. {
  154. setRandomPlainte(playerID);
  155. plaintesGiven++;
  156. }*/
  157.  
  158. }
  159.  
  160. updateProgress(i, plaintesGiven, conseilsGiven);
  161. //alert("Conseilés: " + conseilsGiven + " plaintés: " + plaintesGiven);
  162. }
  163.  
  164. function plainteConseilTousLesVoisins()
  165. {
  166. var voisins = document.getElementsByClassName("collapse");
  167.  
  168. //alert("found: " + voisins.length);
  169.  
  170. var from = document.getElementById("indexFrom").value;
  171. var to = document.getElementById("indexTo").value;
  172.  
  173. from = parseInt(from)-1;
  174. to = parseInt(to);
  175.  
  176. if(from < 0) {from = 0;}
  177. if(to > voisins.length) {to = voisins.length;}
  178.  
  179. for(var i = from; i < to; i++)
  180. {
  181. var playerID = voisins[i].getAttribute("id");
  182. playerID = playerID.replace("commun_", "");
  183. playerID = parseInt(playerID, 10);
  184.  
  185. if(raclures.includes(playerID))
  186. {
  187. setRandomConseil(playerID);
  188. }
  189. else
  190. {
  191. setRandomPlainte(playerID);
  192. }
  193. }
  194. }
  195.  
  196. function createElemsOnCurrentTownPage()
  197. {
  198. var startButton = document.createElement('button');
  199. startButton.innerHTML = "Commencer à poser les plaintes et conseils";
  200.  
  201.  
  202. startButton.addEventListener("click", plainteConseilTouteLaVille, false);
  203.  
  204. var progressElem = document.createElement('p');
  205. progressElem.setAttribute("class", "progress");
  206. progressElem.innerHTML = "Citoyens traités: 0, Plaintés: 0, conseilés: 0";
  207.  
  208. var insertDiv = document.getElementsByClassName("table-cell")[0];
  209. var parent = insertDiv.parentElement;
  210.  
  211. parent.insertBefore(progressElem, insertDiv);
  212. parent.insertBefore(startButton,insertDiv);
  213. }
  214.  
  215. function createElemsOnVoisinPage()
  216. {
  217. var startButton = document.createElement('button');
  218. startButton.innerHTML = "Commencer à poser les plaintes et conseils";
  219.  
  220. startButton.addEventListener("click", plainteConseilTousLesVoisins, false);
  221.  
  222. var voisins = document.getElementsByClassName("collapse");
  223.  
  224. var fromElem = document.createElement('input');
  225. fromElem.id = 'indexFrom';
  226. fromElem.value = 1;
  227.  
  228. var toElem = document.createElement('input');
  229. toElem.id = 'indexTo';
  230. toElem.value = voisins.length;
  231.  
  232.  
  233.  
  234. var insertDiv = document.getElementById("letters");
  235. var parent = insertDiv.parentElement;
  236.  
  237. parent.insertBefore(startButton, insertDiv.nextSibling);
  238.  
  239. parent.insertBefore(document.createElement('br'), insertDiv.nextSibling);
  240. parent.insertBefore(toElem, insertDiv.nextSibling);
  241. parent.insertBefore(document.createTextNode("finir à: "), insertDiv.nextSibling);
  242.  
  243.  
  244. parent.insertBefore(document.createElement('br'), insertDiv.nextSibling);
  245. parent.insertBefore(fromElem, insertDiv.nextSibling);
  246. parent.insertBefore(document.createTextNode("commencer à partir de: "), insertDiv.nextSibling);
  247.  
  248. }
  249.  
  250. var url = window.location.pathname;
  251.  
  252. //alert("current is " + url);
  253.  
  254. if(url == "/cities/current/")
  255. {
  256. createElemsOnCurrentTownPage();
  257. }
  258.  
  259. if(url == "/neighbours/")
  260. {
  261. createElemsOnVoisinPage();
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement