Capitan

Aide à la recherche de cachettes de Capitan

当前为 2020-10-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author TilK, Dabihul, Rouletabille
  3. // @description Aide à la recherche de cachettes de Capitan
  4. // @grant GM_getValue
  5. // @grant GM_setValue
  6. // @grant GM_deleteValue
  7. // @grant GM_listValues
  8. // @include */mountyhall/View/TresorHistory*
  9. // @include */mountyhall/MH_Play/Actions/Play_a_TrouverCachette2*
  10. // @include */mountyhall/MH_Play/Play_equipement.php*
  11. // @include */mountyhall/MH_Taniere/TanierePJ_o_Stock.php*
  12. // @exclude *mh2.mh.raistlin.fr*
  13. // @exclude *mzdev.mh.raistlin.fr*
  14. // @name Capitan
  15. // @version 8.8.08
  16. // @namespace https://greasyfork.org/users/70018
  17. // ==/UserScript==
  18.  
  19. /****************************************************************
  20. * Aide à la recherche de cachettes de Capitan *
  21. * Développé par Mini TilK (n°36216) *
  22. * mini@tilk.info *
  23. *****************************************************************
  24. * Adapté pour GreaseMonkey par Dabihul (n°79738) *
  25. * Roule : ajout https 07/08/2016 *
  26. *****************************************************************
  27. * Pour utiliser la recherche, allez des les infos *
  28. * de la carte de la cachette du capitan *
  29. * Une fois ceci fait, *
  30. * toutes les recherches seront sauvergardées *
  31. * Et dans le détail de la carte vous verrez *
  32. * Le nombre de cachettes possibles et leur position *
  33. ****************************************************************/
  34.  
  35. /*
  36. Roule 16/10/2020 V8.8.08
  37. Adaptation à des modifications MH
  38. Roule 07/10/2020 V8.8.07
  39. Adaptation à des modifications MH
  40. disciple 17/06/2020 V8.8.06
  41. Correction ± #2
  42. Roule 05/08/2018 V8.8.04
  43. Saut de version suite à une erreur de numérotation
  44. Correction ± (Tu es => Vous êtes)
  45. Roule 05/08/2018 V8.2.03
  46. Passage en objet pour assurer l'indépendance par rapport aux autres scripts
  47. Blindage de la détection sous/hors GreaseMonkey ou ViolentMonkey
  48. Roule 05/08/2018 V8.1.67
  49. Correction ±
  50. Roule 04/08/2018 V8.1.66
  51. Utilisation hors GM
  52. Roule 25/08/2017 V8.1.61
  53. Réactivation de la gestion des signes (+/-)
  54. Roule 23/11/2016 V8.1.6
  55. Adaptation à l'affichage en popup dans les tanières (méthode toujours très discutable par setInterval)
  56. Roule 09/12/2016 V8.1.5
  57. Nouvelle méthode de migration des essais V1.0 par copier/coller de tout pref.js
  58. Roule 23/11/2016 V8.1.4
  59. Adaptation à l'affichage en popup du détail d'un équipement (méthode très discutable par setInterval)
  60. Roule 14/10/2016 V8.1.3
  61. simplification de l'entête GM (include)
  62. passage à greasyfork
  63. Roule 24 à 26/08/2016 V8.1.2
  64. Ajout outils de récupération des recherches pré Greasemonkey
  65. Roule 15/08/2016 V8.1.1
  66. Ajout demande d'avis sur la position courante sur le site Psyko-Chasseurs
  67. Quelques corrections de calcul (on avait du NaN)
  68. Roule 08 à 10/08/2016
  69. recopie ici de this.appendButton() version MZ
  70. Ajout liste des essais et possibilité d'en supprimer
  71. Ajout lien vers Psyko Chasseurs
  72. Adaptation aux IDs dans la page de résultat d'une recherche de cachette (et plus besoin de stocker le numéro de carte)
  73. */
  74.  
  75. /* À faire
  76. Hera 23/08/2017
  77. FAIT les chiffres sont bons mais ça inverse + et - en x/y (quand ce n'est pas ++/--) toutes les cachettes qui comportent un +/- sont inversées. donc récurent
  78. */
  79.  
  80. /* 05/08/2018 passage en objet
  81. avantages
  82. indépendance du nomage par rapport aux autres scripts (il y avait effectivement un souci aléatoire sans doute lié à une collision de nom)
  83. inconvénient
  84. syntaxe plus compliquée (utilisation de this, déclaration pas naturelle des fonctions
  85. complexité pour l'utilisation des callback (par exemple setIntervale)
  86. */
  87.  
  88. var oCAPITAN_MH_ROULE;
  89. if (oCAPITAN_MH_ROULE instanceof Object) {
  90. window.console.log("script capitan déjà chargé"); // ça arrive dans le cas de l'affichage des détails d'une carte en popup
  91. } else {
  92. oCAPITAN_MH_ROULE = {
  93. bDebug: false,
  94. appendButton: function(paren,value,onClick) {
  95. var input = document.createElement('input');
  96. input.type = 'button';
  97. input.className = 'mh_form_submit';
  98. input.value = value;
  99. input.onmouseover = function(){this.style.cursor='pointer';};
  100. if (onClick) input.onclick = onClick;
  101. paren.appendChild(input);
  102. return input;
  103. },
  104.  
  105. /* Ajout des éléments manquants de libs */
  106. isPage: function(url) {
  107. return window.location.href.indexOf(url)!=-1;
  108. },
  109.  
  110. insertTitle: function(next,txt) {
  111. var div = document.createElement('div');
  112. div.className = 'titre2';
  113. this.appendText(div,txt);
  114. this.insertBefore(next,div);
  115. },
  116.  
  117. insertBefore: function(next,el) {
  118. next.parentNode.this.insertBefore(el,next);
  119. },
  120.  
  121. // Roule 08/08/2016 ajout cssClass
  122. appendTr: function(tbody, cssClass) {
  123. var tr = document.createElement('tr');
  124. tbody.appendChild(tr);
  125. if (cssClass) tr.className = cssClass;
  126. return tr;
  127. },
  128.  
  129. appendTd: function(tr) {
  130. var td = document.createElement('td');
  131. if(tr) { tr.appendChild(td); }
  132. return td;
  133. },
  134.  
  135. appendText: function(paren,text,bold) {
  136. if(bold) {
  137. var b = document.createElement('b');
  138. b.appendChild(document.createTextNode(text));
  139. paren.appendChild(b);
  140. }
  141. else
  142. paren.appendChild(document.createTextNode(text));
  143. },
  144.  
  145. appendTdText: function(tr,text,bold) {
  146. var td = this.appendTd(tr);
  147. this.appendText(td,text,bold);
  148. return td;
  149. },
  150. /* */
  151.  
  152. sortNumber: function(a,b) {
  153. return b-a;
  154. },
  155.  
  156. removeTab: function(tab, i) {
  157. var newTab = new Array();
  158. for(var j=0;j<i;j++)
  159. {
  160. newTab.push(tab[j]);
  161. }
  162. for(var j=i+1;j<tab.length;j++)
  163. {
  164. newTab.push(tab[j]);
  165. }
  166. return newTab;
  167. },
  168. cache: new Array(),
  169.  
  170. tabToString: function(tab) {
  171. var string = tab[0];
  172. for(var i=1;i<tab.length;i++)
  173. string+=";"+tab[i];
  174. return string;
  175. },
  176.  
  177. combi: function(tab) {
  178. var newTab = new Array();
  179. if(tab.length==1)
  180. {
  181. newTab[""+tab[0]]=1;
  182. return newTab;
  183. }
  184. var val = this.tabToString(tab);
  185. if(this.cache[val])
  186. return this.cache[val];
  187. for(var i=0;i<tab.length;i++)
  188. {
  189. var lastTab = this.combi(this.removeTab(tab,i));
  190. for(var j in lastTab)
  191. newTab[tab[i]+";"+j]=1;
  192. }
  193. this.cache[val]=newTab;
  194. return newTab;
  195. },
  196.  
  197. affiche: function(tab) {
  198. var newTab = this.combi(tab);
  199. var string="";
  200. for(var i in newTab)
  201. {
  202. string += i+"\n";
  203. }
  204. window.alert(string);
  205. },
  206.  
  207. extractPosition: function(nombre, indice) {
  208. if((nombre+"").length<=indice)
  209. return "%";
  210. indice = (nombre+"").length - 1 - indice;
  211. return (nombre+"").substring(indice,indice+1);
  212. },
  213.  
  214. comparePos: function(x,y,n,x1,y1,n1) {
  215. x = Math.abs(x);
  216. y = Math.abs(y);
  217. n = Math.abs(n);
  218. x1 = Math.abs(x1);
  219. y1 = Math.abs(y1);
  220. n1 = Math.abs(n1);
  221. var nbGood=0;
  222. for(var i=0;i<(x+"").length;i++)
  223. if(this.extractPosition(x,i)==this.extractPosition(x1,i))
  224. nbGood++;
  225. for(var i=0;i<(y+"").length;i++)
  226. if(this.extractPosition(y,i)==this.extractPosition(y1,i))
  227. nbGood++;
  228. for(var i=0;i<(n+"").length;i++)
  229. if(this.extractPosition(n,i)==this.extractPosition(n1,i))
  230. nbGood++;
  231. return nbGood;
  232. },
  233.  
  234. signe: function(x) {
  235. if(x<0)
  236. return -1;
  237. return 1;
  238. },
  239.  
  240. getPosFromArray: function(liste,begin,length) {
  241. var pos="";
  242. for(var i=begin;i<begin+length;i++)
  243. pos+=""+liste[i];
  244. return parseInt(pos, 10);
  245. },
  246.  
  247. calculeSolution6: function(x,y,n,essais) {
  248. var listeChiffre = new Array();
  249. for(var i=0;i<(Math.abs(x)+"").length;i++)
  250. listeChiffre.push(this.extractPosition(Math.abs(x),i));
  251. for(var i=0;i<(Math.abs(y)+"").length;i++)
  252. listeChiffre.push(this.extractPosition(Math.abs(y),i));
  253. for(var i=0;i<(Math.abs(n)+"").length;i++)
  254. listeChiffre.push(this.extractPosition(Math.abs(n),i));
  255. var listeSolutionsPossibles = this.combi(listeChiffre);
  256. var listeSolutions = new Array();
  257. for(var key in listeSolutionsPossibles)
  258. {
  259. var liste = key.split(";");
  260. var x1 = this.getPosFromArray(liste,0,listeChiffre.length/3);
  261. var y1 = this.getPosFromArray(liste,listeChiffre.length/3,listeChiffre.length/3);
  262. var n1 = this.getPosFromArray(liste,2*(listeChiffre.length)/3,listeChiffre.length/3);
  263. var oki = true;
  264. for(var i=0;i<essais.length;i++)
  265. {
  266. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  267. {
  268. oki=false;
  269. break;
  270. }
  271. }
  272. if(oki)
  273. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  274. }
  275. return listeSolutions;
  276. },
  277.  
  278. calculeSolution5: function(x,y,n,essais) {
  279. var listeChiffre = new Array();
  280. for(var i=0;i<(Math.abs(x)+"").length;i++)
  281. listeChiffre.push(this.extractPosition(Math.abs(x),i));
  282. for(var i=0;i<(Math.abs(y)+"").length;i++)
  283. listeChiffre.push(this.extractPosition(Math.abs(y),i));
  284. for(var i=0;i<(Math.abs(n)+"").length;i++)
  285. listeChiffre.push(this.extractPosition(Math.abs(n),i));
  286. var listeSolutionsPossibles = this.combi(listeChiffre);
  287. var length = Math.floor(listeChiffre.length/3);
  288. var listeSolutions = new Array();
  289. for(var key in listeSolutionsPossibles)
  290. {
  291. var liste = key.split(";");
  292. var x1 = this.getPosFromArray(liste,0,length);
  293. var y1 = this.getPosFromArray(liste,length,length+1);
  294. var n1 = this.getPosFromArray(liste,2*length+1,length+1);
  295. var oki = true;
  296. for(var i=0;i<essais.length;i++)
  297. {
  298. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  299. {
  300. oki=false;
  301. break;
  302. }
  303. }
  304. if(oki)
  305. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  306. }
  307. for(var key in listeSolutionsPossibles)
  308. {
  309. var liste = key.split(";");
  310. var x1 = this.getPosFromArray(liste,0,length+1);
  311. var y1 = this.getPosFromArray(liste,length+1,length);
  312. var n1 = this.getPosFromArray(liste,2*length+1,length+1);
  313. var oki = true;
  314. for(var i=0;i<essais.length;i++)
  315. {
  316. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  317. {
  318. oki=false;
  319. break;
  320. }
  321. }
  322. if(oki)
  323. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  324. }
  325. for(var key in listeSolutionsPossibles)
  326. {
  327. var liste = key.split(";");
  328. var x1 = this.getPosFromArray(liste,0,length+1);
  329. var y1 = this.getPosFromArray(liste,length+1,length+1);
  330. var n1 = this.getPosFromArray(liste,2*length+2,length);
  331. var oki = true;
  332. for(var i=0;i<essais.length;i++)
  333. {
  334. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  335. {
  336. oki=false;
  337. break;
  338. }
  339. }
  340. if(oki)
  341. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  342. }
  343. return listeSolutions;
  344. },
  345.  
  346. calculeSolution4: function(x,y,n,essais) {
  347. var listeChiffre = new Array();
  348. for(var i=0;i<(Math.abs(x)+"").length;i++)
  349. listeChiffre.push(this.extractPosition(Math.abs(x),i));
  350. for(var i=0;i<(Math.abs(y)+"").length;i++)
  351. listeChiffre.push(this.extractPosition(Math.abs(y),i));
  352. for(var i=0;i<(Math.abs(n)+"").length;i++)
  353. listeChiffre.push(this.extractPosition(Math.abs(n),i));
  354. var listeSolutionsPossibles = this.combi(listeChiffre);
  355. var length = Math.floor(listeChiffre.length/3);
  356. var listeSolutions = new Array();
  357. for(var key in listeSolutionsPossibles)
  358. {
  359. var liste = key.split(";");
  360. var x1 = this.getPosFromArray(liste,0,length);
  361. var y1 = this.getPosFromArray(liste,length,length);
  362. var n1 = this.getPosFromArray(liste,2*length,length+1);
  363. var oki = true;
  364. for(var i=0;i<essais.length;i++)
  365. {
  366. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  367. {
  368. oki=false;
  369. break;
  370. }
  371. }
  372. if(oki)
  373. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  374. }
  375. for(var key in listeSolutionsPossibles)
  376. {
  377. var liste = key.split(";");
  378. var x1 = this.getPosFromArray(liste,0,length+1);
  379. var y1 = this.getPosFromArray(liste,length+1,length);
  380. var n1 = this.getPosFromArray(liste,2*length+1,length);
  381. var oki = true;
  382. for(var i=0;i<essais.length;i++)
  383. {
  384. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  385. {
  386. oki=false;
  387. break;
  388. }
  389. }
  390. if(oki)
  391. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  392. }
  393. for(var key in listeSolutionsPossibles)
  394. {
  395. var liste = key.split(";");
  396. var x1 = this.getPosFromArray(liste,0,length);
  397. var y1 = this.getPosFromArray(liste,length,length+1);
  398. var n1 = this.getPosFromArray(liste,2*length+1,length);
  399. var oki = true;
  400. for(var i=0;i<essais.length;i++)
  401. {
  402. if(essais[i][3] != this.comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  403. {
  404. oki=false;
  405. break;
  406. }
  407. }
  408. if(oki)
  409. listeSolutions.push(new Array(x1*this.signe(x),y1*this.signe(y),n1*this.signe(n)));
  410. }
  411. return listeSolutions;
  412. },
  413.  
  414. calculeSolution: function(x,y,n,essais) {
  415. var size = (";"+Math.abs(x)+Math.abs(y)+Math.abs(n)).length-1;
  416. if(size%3==0)
  417. return this.calculeSolution6(x,y,n,essais);
  418. if(size%3==1)
  419. return this.calculeSolution4(x,y,n,essais);
  420. if(size%3==2)
  421. return this.calculeSolution5(x,y,n,essais);
  422. },
  423.  
  424. afficheSolutions: function(x,y,n,essais) {
  425. var listeSolutions = this.calculeSolution(x,y,n,essais);
  426. if (this.bDebug) window.console.log('afficheSolutions: ListeSolutions=' + JSON.stringify(listeSolutions) + ', x=' + x);
  427. var string="Il y a "+listeSolutions.length+" solutions";
  428. if(listeSolutions.length<=10)
  429. {
  430. for(var i=0;i<listeSolutions.length;i++)
  431. {
  432. string+= "\n x="+listeSolutions[i][0]+" y="+listeSolutions[i][1]+" n="+listeSolutions[i][2];
  433. }
  434. }
  435. return string;
  436. },
  437.  
  438. toggleTableau: function() {
  439. var tbody = this.parentNode.parentNode.parentNode.childNodes[1];
  440.  
  441. tbody.setAttribute('style', !tbody.getAttribute('style') || tbody.getAttribute('style') == '' ? 'display:none;' : '');
  442. },
  443.  
  444. createCase: function(titre,table,width) {
  445. if(width==null)
  446. width="120";
  447. var tr = this.appendTr(table, 'mh_tdpage');
  448.  
  449. var td = this.appendTdText(tr, titre, true);
  450. td.setAttribute('class', 'mh_tdpage');
  451. td.setAttribute('width', width);
  452. td.setAttribute('align', 'center');
  453.  
  454. return td;
  455. },
  456.  
  457. showXYN: function(tabXYN, bSigneOK) {
  458. if (bSigneOK)
  459. return "X = " + tabXYN[0] + ", Y = " + tabXYN[1] + ", N = " + tabXYN[2];
  460. return "X = ±" + Math.abs(tabXYN[0]) + ", Y = ±" + Math.abs(tabXYN[1]) + ", N = " + tabXYN[2];
  461. },
  462.  
  463. is200: function(tabXYN) { // vrai si au moins une coord >= 200
  464. if (Math.abs(tabXYN[0]) >= 200) return true;
  465. if (Math.abs(tabXYN[1]) >= 200) return true;
  466. if (Math.abs(tabXYN[2]) >= 200) return true;
  467. return false;
  468. },
  469.  
  470. gbody: null,
  471.  
  472. generateTable: function(listeSolutions, bSigneOK) {
  473. var table = document.createElement('table');
  474. table.setAttribute('class', 'mh_tdborder');
  475. table.setAttribute('border', '0');
  476. table.setAttribute('cellspacing', '1');
  477. table.setAttribute('cellpadding', '4');
  478. table.setAttribute('style', 'width: 400px;');
  479. table.setAttribute('align', 'center');
  480.  
  481. if(listeSolutions.length==1)
  482. {
  483. var thead = document.createElement('thead');
  484. var tr = this.appendTr(thead, 'mh_tdtitre');
  485. var td = this.appendTdText(tr, "Position de la cachette : " + this.showXYN(listeSolutions[0], bSigneOK), true);
  486. td.setAttribute('align', 'center');
  487. table.appendChild(thead);
  488. return table;
  489. }
  490. else if(listeSolutions.length==0)
  491. {
  492. var thead = document.createElement('thead');
  493. var tr = this.appendTr(thead, 'mh_tdtitre');
  494. var td = this.appendTdText(tr, "Aucune solution trouvée.", true);
  495. td.setAttribute('align', 'center');
  496. table.appendChild(thead);
  497. return table;
  498. }
  499.  
  500. var thead = document.createElement('thead');
  501. var tr = this.appendTr(thead, 'mh_tdtitre');
  502. var td = this.appendTdText(tr, "Il y a "+listeSolutions.length+" positions possibles", true);
  503. td.setAttribute('align', 'center');
  504. table.appendChild(thead);
  505.  
  506. this.gbody = document.createElement('tbody');
  507. table.appendChild(this.gbody);
  508.  
  509. var bExist200 = false;
  510. for (var i = 0; i < listeSolutions.length; i++) {
  511. if (this.is200(listeSolutions[i]))
  512. bExist200 = true;
  513. else
  514. this.createCase(this.showXYN(listeSolutions[i], bSigneOK),this.gbody,400);
  515. }
  516. if (bExist200) {
  517. this.createCase("Les suivantes sont peu probables car trop en dehors du Hall",this.gbody,400);
  518. for (var i = 0; i < listeSolutions.length; i++) {
  519. if (this.is200(listeSolutions[i]))
  520. this.createCase(this.showXYN(listeSolutions[i], bSigneOK),this.gbody,400);
  521. }
  522. }
  523.  
  524. td.addEventListener("click", this.toggleTableau, true);
  525. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  526. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  527. this.gbody.setAttribute('style', 'display:none;');
  528.  
  529. return table;
  530. },
  531.  
  532. gListeSolutions: new Array(),
  533. gEssais: null, // Roule 08/08/2016 essais en variable globale (pour générer le bloc liste et le bloc pour l'outils de Psycho Chasseurs)
  534.  
  535. afficheInfoCarte: function(idCarte) {
  536. var originalPos = this.CAPITAN_getValue("capitan."+idCarte+".position").split(";");
  537. if(originalPos.length!=3)
  538. return;
  539. this.gEssais = new Array();
  540. var i = 0;
  541. while(this.CAPITAN_getValue("capitan."+idCarte+".essai."+i) != null)
  542. {
  543. this.gEssais.push(this.CAPITAN_getValue("capitan."+idCarte+".essai."+i).split(";"));
  544. i++;
  545. }
  546. if(this.CAPITAN_getValue("capitan."+idCarte+".this.signe") !=null)
  547. {
  548. var signes = this.CAPITAN_getValue("capitan."+idCarte+".this.signe").split(";");
  549. this.gListeSolutions = this.calculeSolution(Math.abs(originalPos[0])*this.signe(signes[0]),Math.abs(originalPos[1])*this.signe(signes[1]),originalPos[2],this.gEssais);
  550. if (this.bDebug) window.console.log('afficheInfoCarte: gListeSolutions=' + JSON.stringify(this.gListeSolutions) + ', signe=' + JSON.stringify(signes));
  551. }
  552. else
  553. {
  554. this.gListeSolutions = this.calculeSolution(originalPos[0],originalPos[1],originalPos[2],this.gEssais);
  555. for (var i = 0; i < this.gListeSolutions; i++) {
  556. this.gListeSolutions[i][0] = Math.abs(this.gListeSolutions[i][0]);
  557. this.gListeSolutions[i][1] = Math.abs(this.gListeSolutions[i][1]);
  558. }
  559. if (this.bDebug) window.console.log('afficheInfoCarte: sans signe, gListeSolutions=' + JSON.stringify(this.gListeSolutions));
  560. }
  561. return this.generateTable(this.gListeSolutions, signes != undefined);
  562. },
  563.  
  564. getRepartitionFromCase: function(tx, ty, tn, listeSolutions) {
  565. // Roule 15/08/2016 plus que dubitatif sur ce calcul de Size, je modifie l'algorithme
  566. //var size = (";"+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])).length-1;
  567. var repartition = new Array();
  568. //for(var i=0;i<size;i++)
  569. // repartition.push(0);
  570. for(var i=0;i<listeSolutions.length;i++)
  571. {
  572. var nbGood = this.comparePos(listeSolutions[i][0],listeSolutions[i][1],listeSolutions[i][2],tx,ty,tn);
  573. for (var j = repartition.length; j <= nbGood; j++) repartition.push(0); // Roule 15/08/2016 compléter le tableau selon le besoin
  574. repartition[nbGood]++;
  575. }
  576. repartition.sort(this.sortNumber);
  577. return repartition;
  578. },
  579.  
  580. getMeanPositionNumber: function(repartition,nbSolutions) {
  581. var result=0;
  582. for(var i=0;i<repartition.length;i++)
  583. {
  584. result+=repartition[i]*repartition[i];
  585. }
  586. return result/nbSolutions;
  587. },
  588.  
  589. // Roule 08/08/2016 passage numTroll en paramètre
  590. // Roule 15/08/2016 passage position courante en paramètre (tableau des 3 valeurs)
  591. newRecherche: function(listeSolutions, currentPos) {
  592. if(listeSolutions.length<=1)
  593. return null;
  594. // Roule 15/08/2016 plus que dubitatif sur ce calcul de Size, j'utilise repartition.length
  595. //var size = (";"+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])).length-1;
  596. var repartition = this.getRepartitionFromCase(currentPos[0], currentPos[1], currentPos[2], listeSolutions);
  597. var size = repartition.length;
  598. if (this.bDebug) window.console.log('newRecherche: this.newRecherche, repartition=' + JSON.stringify(repartition));
  599.  
  600. var table = document.createElement('table');
  601. table.setAttribute('class', 'mh_tdborder');
  602. table.setAttribute('border', '0');
  603. table.setAttribute('cellspacing', '1');
  604. table.setAttribute('cellpadding', '4');
  605. table.setAttribute('style', 'width: 400px;');
  606. table.setAttribute('align', 'center');
  607.  
  608. var nbNotZero = 0;
  609. for(var i=0;i<size;i++)
  610. {
  611. if(repartition[i]!=0)
  612. nbNotZero++;
  613. }
  614. var string = "Il y a une utilité de faire une recherche en X = "+currentPos[0]+" Y = "+currentPos[1]+" N = "+currentPos[2];
  615. if(nbNotZero<=1)
  616. {
  617. //
  618. var minsolution = listeSolutions.length;
  619. var newpos = "";
  620. var isNotN = true;
  621. for(var dx=-1;dx<=1;dx++)
  622. for(var dy=-1;dy<=1;dy++)
  623. for(var dn=0;dn!=-3;dn=(dn==0?1:dn-2))
  624. {
  625. if(dx==0 && dy==0 && dn==0)
  626. continue;
  627. var tmprepartition = this.getRepartitionFromCase(currentPos[0]+dx, currentPos[1]+dy, currentPos[2]+dn, listeSolutions);
  628. var tmpmeanscore = this.getMeanPositionNumber(tmprepartition,listeSolutions.length);
  629. if(((dn==0 || !isNotN) && minsolution>=tmpmeanscore) || (dn!=0 && isNotN && tmpmeanscore<=2*minsolution/3))
  630. {
  631. minsolution = tmpmeanscore;
  632. repartition = tmprepartition;
  633. newpos = "X = "+(currentPos[0]+dx)+" Y = "+(currentPos[1]+dy)+" N = "+(currentPos[2]+dn);
  634. isNotN = (dn==0);
  635. }
  636. }
  637. if(minsolution == listeSolutions.length)
  638. {
  639. var thead = document.createElement('thead');
  640. var tr = this.appendTr(thead, 'mh_tdtitre');
  641. var td = this.appendTdText(tr, "Il n'y a aucune utilité de faire une recherche en X = "+currentPos[0]+" Y = "+currentPos[1]+" N = "+currentPos[2], true);
  642. td.setAttribute('align', 'center');
  643. table.appendChild(thead);
  644. return table;
  645. }
  646. string = "Conseil : allez faire une recherche en "+newpos;
  647. }
  648.  
  649. var thead = document.createElement('thead');
  650. var tr = this.appendTr(thead, 'mh_tdtitre');
  651. var td = this.appendTdText(tr,string, true);
  652. td.setAttribute('align', 'center');
  653. table.appendChild(thead);
  654. var tbody = document.createElement('tbody');
  655. table.appendChild(tbody);
  656. for(var i=0;i<size;i++)
  657. {
  658. if(i==size-1)
  659. {
  660. if(repartition[i]!=0)
  661. this.createCase(Math.round(100*repartition[i]/listeSolutions.length)+"% de chance d'éliminer "+(listeSolutions.length-repartition[i])+" positions possibles",tbody,400);
  662. }
  663. else
  664. {
  665. var n=1;
  666. while((i+n)<size && repartition[i]==repartition[i+n])
  667. n++;
  668. if(repartition[i]!=0)
  669. this.createCase(Math.round(100*n*repartition[i]/listeSolutions.length)+"% de chance d'éliminer "+(listeSolutions.length-repartition[i])+" positions possibles",tbody,400);
  670. i+=n-1;
  671. }
  672. }
  673.  
  674. td.addEventListener("click", this.toggleTableau, true);
  675. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  676. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  677. tbody.setAttribute('style', 'display:none;');
  678. return table;
  679. },
  680.  
  681. // Roule 08/08/2016 récupération numéro de Troll dans la page HTML
  682. getNumTroll: function() {
  683. /* 07/10/2020, l'info n'est plus dans la page, on se replie sur le localStorage
  684. var infoObjet = document.evaluate("//td[@class = 'mh_tdtitre']/text()[contains(.,'Propriétaire actuel')]",
  685. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  686. if (this.bDebug) {
  687. if (infoObjet) {
  688. window.console.log('CAPITAN getNumTroll: infoObjet.nodeValue=' + infoObjet.nodeValue);
  689. } else {
  690. window.console.log('CAPITAN getNumTroll: infoObjet est nul');
  691. }
  692. }
  693. var numTroll = 0;
  694. if (infoObjet)
  695. {
  696. // infoObjet.nodeValue=Propriétaire actuel : TROLL - 91305. Rouletabille
  697. var m = infoObjet.nodeValue.match(/troll[ -]*(\d*)[. +]/i);
  698. if (m) {
  699. if (this.bDebug) window.console.log('CAPITAN getNumTroll: m=' + m);
  700. if (m.length > 1) numTroll = parseInt(m[1]);
  701. }
  702. }
  703. */
  704. numTroll = parseInt(window.localStorage['NUM_TROLL']);
  705. if (this.bDebug) window.console.log('CAPITAN getNumTroll: numTroll=' + numTroll);
  706. return numTroll;
  707. },
  708.  
  709. getIDCarte: function() {
  710. var infoObjet = document.evaluate("//td[@class = 'titre2']/text()[contains(.,'Carte de la Cachette')]",
  711. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  712. // si échec, essayer avec l'ancienne méthode
  713. if (!infoObjet) infoObjet = document.evaluate("//div[@class = 'titre2']/text()[contains(.,'Carte de la Cachette')]",
  714. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  715. var idCarte = 0;
  716. if(infoObjet)
  717. {
  718. idCarte = parseInt(infoObjet.nodeValue.replace('[', ''));
  719. }
  720. return idCarte;
  721. },
  722.  
  723. analyseObjectCallback: function() { // appelle analyseObject dans le contexte de l'objet
  724. oCAPITAN_MH_ROULE.analyseObject();
  725. },
  726.  
  727. analyseObject: function() {
  728. var eSpacer = document.getElementById('spacerMZCapitan');
  729. if (eSpacer) return; // déjà affiché
  730. var numTroll = this.getNumTroll(); // Roule 08/08/2016 récupération numéro de Troll dans la page HTML
  731. if( !numTroll) {
  732. window.console.log('CAPITAN analyseObject: *** erreur *** pas de numéro de Trõll');
  733. return;
  734. }
  735. var idCarte = this.getIDCarte();
  736. if (idCarte > 0) var originalPos = this.CAPITAN_getValue("capitan."+idCarte+".position");
  737. if (this.bDebug) window.console.log('CAPITAN analyseObject: this.analyseObject numTroll=' + numTroll + ', idCarte=' + idCarte + ', originalPos=' + originalPos);
  738. if(!originalPos || originalPos == null)
  739. {
  740. var infoPos = document.evaluate("//td/text()[contains(.,'ai été tué en')]",
  741. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  742. if(!infoPos) {
  743. if (this.bDebug) window.console.log('CAPITAN analyseObject: numTroll=' + numTroll + ', idCarte=' + idCarte + ', impossible de trouver le texte de la mort du Capitan');
  744. return;
  745. }
  746. var listePos = infoPos.nodeValue.split("=");
  747. if(listePos.length!=4) {
  748. if (this.bDebug) window.console.log('CAPITAN analyseObject: numTroll=' + numTroll + ', idCarte=' + idCarte + ', impossible de trouver les coord. de la mort du Capitan ' + infoPos.nodeValue);
  749. return;
  750. }
  751. var x = parseInt(listePos[1]);
  752. var y = parseInt(listePos[2]);
  753. var n = parseInt(listePos[3]);
  754. if (this.bDebug) window.console.log('CAPITAN analyseObject: setValue("capitan.'+idCarte+'.position, '+x+";"+y+";"+n);
  755. this.CAPITAN_setValue("capitan."+idCarte+".position",x+";"+y+";"+n);
  756. }
  757. // Roule 23/11/2016 travail dans le body (ancienne version, fenêtre indépendante) ou dans la div modale (nouvelle version en "popup")
  758. var parentElt = document.body;
  759. var modalElt = document.evaluate("//div[@class = 'modal']",
  760. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  761. if (modalElt) parentElt = modalElt;
  762.  
  763. // bloc liste de solutions
  764. var table = this.afficheInfoCarte(idCarte);
  765. var p = document.createElement('p');
  766. p.id = 'spacerMZCapitan';
  767. p.appendChild(table);
  768. parentElt.appendChild(p);
  769.  
  770. // position courante du Troll
  771. // Roule 08/08/2016 utilisation de localStorage car c'est là que tout_MZ stocke les coord
  772. var curPos = [];
  773. curPos[0] = parseInt(window.localStorage[numTroll+".position.X"]);
  774. curPos[1] = parseInt(window.localStorage[numTroll+".position.Y"]);
  775. curPos[2] = parseInt(window.localStorage[numTroll+".position.N"]);
  776. if (this.bDebug) window.console.log('CAPITAN analyseObject: position du troll récupérée en localStorage=' + JSON.stringify(curPos));
  777.  
  778. // bloc utilité de faire une recherche sur la position courante
  779. table = this.newRecherche(this.gListeSolutions, curPos);
  780. if(table!=null)
  781. {
  782. var p = document.createElement('p');
  783. p.appendChild(table);
  784. parentElt.appendChild(p);
  785. // bloc ajout de nouvelle recherche
  786. this.createNewRecherche(parentElt);
  787. }
  788.  
  789. // Roule 08/08/2016 bloc des recherches mémorisées
  790. if(this.gEssais)
  791. {
  792. table = this.prevRecherche(idCarte);
  793. var p = document.createElement('p');
  794. p.appendChild(table);
  795. parentElt.appendChild(p);
  796. // Roule 08/08/2016 bloc préparant les infos pour l'outil Mamoune (Psyko-Chasseurs)
  797. table = this.blocMamoune(idCarte, curPos);
  798. if(table!=null)
  799. {
  800. p = document.createElement('p');
  801. p.appendChild(table);
  802. parentElt.appendChild(p);
  803. }
  804. }
  805.  
  806. // Roule 25/08/2016 récupération des anciennes recherches (préférences)
  807. table = this.PrepareRecupFromPreferences();
  808. if(table!=null)
  809. {
  810. p = document.createElement('p');
  811. p.appendChild(table);
  812. parentElt.appendChild(p);
  813. }
  814.  
  815. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  816. table = this.PrepareRecupFromLocalStorage(idCarte);
  817. if(table!=null)
  818. {
  819. p = document.createElement('p');
  820. p.appendChild(table);
  821. parentElt.appendChild(p);
  822. }
  823. },
  824.  
  825. // Roule 08/08/2016
  826. blocMamoune: function(idCarte, currentPos) {
  827. var table = document.createElement('table');
  828. table.setAttribute('class', 'mh_tdborder');
  829. table.setAttribute('border', '0');
  830. table.setAttribute('cellspacing', '1');
  831. table.setAttribute('cellpadding', '4');
  832. table.setAttribute('style', 'width: 400px;');
  833. table.setAttribute('align', 'center');
  834.  
  835. var thead = document.createElement('thead');
  836. var tr = this.appendTr(thead, 'mh_tdtitre');
  837. var td = this.appendTdText(tr, "Outil du cercle des Psyko-Chasseurs", true);
  838. td.setAttribute('align', 'center');
  839. td.setAttribute('title', 'sélectionnez (triple-clic), copiez et collez dans l\'outil des Psyko-Chasseurs');
  840. table.appendChild(thead);
  841.  
  842. var tbody = document.createElement('tbody');
  843. table.appendChild(tbody);
  844.  
  845. // http://mountyhall.dispas.net/dynamic/outils_capitan.php?x=1&y=2&n=3&t=4+5+6+7%0D%0A10+11+12+5&enter=Go#
  846. var tabtxt = new Array();
  847. var currentPosAlreadyDone = false;
  848. for (var i = 0; i < this.gEssais.length; i++) {
  849. tabtxt.push(this.gEssais[i].join('+'));
  850. if (this.gEssais[i][0] == currentPos[0] && this.gEssais[i][1] == currentPos[1] && this.gEssais[i][2] == currentPos[2]) currentPosAlreadyDone = true;
  851. }
  852. if (!currentPosAlreadyDone) tabtxt.push(currentPos.join('+') + '+%3F'); // spécial pour demander à Mamoune ce qu'elle pense d'un essai à la position courante
  853. var tr2 = this.appendTr(tbody, 'mh_tdpage');
  854. var td2 = this.appendTd(tr2);
  855. var originalPos = this.CAPITAN_getValue("capitan."+idCarte+".position").split(";");
  856. if(originalPos.length!=3) {
  857. td2.this.appendText('Erreur\u00A0: impossible de retrouver les coordonnées de la mort');
  858. } else {
  859. var a = document.createElement('a');
  860. this.appendText(a, 'Cliquer ici pour savoir ce qu\'en pensent les Psyko-Chasseurs');
  861. a.setAttribute('href', 'http://mountyhall.dispas.net/dynamic/outils_capitan.php?x=' + originalPos[0] + '&y=' + originalPos[1] + '&n=' + originalPos[2] + '&t=' + tabtxt.join('%0D%0A'));
  862. a.setAttribute('target', 'psykochasseurs');
  863. td2.appendChild(a);
  864. }
  865.  
  866. td.setAttribute('class', 'mh_tdpage');
  867. //td.setAttribute('width', width);
  868. td.setAttribute('align', 'center');
  869.  
  870.  
  871. td.addEventListener("click", this.toggleTableau, true);
  872. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  873. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  874. td.setAttribute('colspan', 2);
  875. tbody.setAttribute('style', 'display:none;');
  876.  
  877. return table;
  878. },
  879.  
  880. prevRecherche: function(idCarte) {
  881. var table = document.createElement('table');
  882. table.setAttribute('class', 'mh_tdborder');
  883. table.setAttribute('border', '0');
  884. table.setAttribute('cellspacing', '1');
  885. table.setAttribute('cellpadding', '4');
  886. table.setAttribute('style', 'width: 400px;');
  887. table.setAttribute('align', 'center');
  888.  
  889. var thead = document.createElement('thead');
  890. var tr = this.appendTr(thead, 'mh_tdtitre');
  891. var td = this.appendTdText(tr, "Vous avez mémorisé " + this.gEssais.length + " essai" + (this.gEssais.length > 1 ? "s" : ""), true);
  892. td.setAttribute('align', 'center');
  893. table.appendChild(thead);
  894.  
  895. var tbody = document.createElement('tbody');
  896. table.appendChild(tbody);
  897.  
  898. for (var i = 0; i < this.gEssais.length; i++) {
  899. var td2 = this.createCase("X = "+this.gEssais[i][0]+", Y = "+this.gEssais[i][1]+", N = "+this.gEssais[i][2]+" => "+this.gEssais[i][3],tbody,400);
  900. var td3 = this.appendTd(td2.parentNode);
  901. var bt = this.appendButton(td3, "Supprimer", this.delRecherche);
  902. bt.idEssai = i;
  903. bt.idCarte = idCarte;
  904. td3.setAttribute('class', 'mh_tdpage');
  905. td3.setAttribute('width', 200);
  906. td3.setAttribute('align', 'center');
  907. }
  908.  
  909. td.addEventListener("click", this.toggleTableau, true);
  910. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  911. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  912. td.setAttribute('colspan', 2);
  913. tbody.setAttribute('style', 'display:none;');
  914.  
  915. return table;
  916. },
  917.  
  918. delRecherche: function(e) { // ATTENTION, cette fonction ne tourne pas dans le contexte de l'objet ("this" pointe vers le bouton)
  919. var idEssaiDel = e.target.idEssai;
  920. var idCarte = e.target.idCarte;
  921. if (this.bDebug) window.console.log('CAPITAN delRecherche: idEssaiDel=' + idEssaiDel + ', idCarte=' + idCarte + ', oCAPITAN_MH_ROULE.gEssais.length=' + oCAPITAN_MH_ROULE.gEssais.length);
  922. for (var i = 0; i < oCAPITAN_MH_ROULE.gEssais.length; i++) {
  923. if (i == oCAPITAN_MH_ROULE.gEssais.length - 1) {
  924. window.console.log("CAPITAN delRecherche: capitan."+idCarte+".essai."+i)
  925. CAPITAN_deleteValue("capitan."+idCarte+".essai."+i);
  926. } else if (i >= idEssaiDel) {
  927. window.console.log("CAPITAN delRecherche: set capitan."+idCarte+".essai."+(i)+'+++'+oCAPITAN_MH_ROULE.gEssais[i+1][0]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][1]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][2]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][3]);
  928. oCAPITAN_MH_ROULE.CAPITAN_setValue("capitan."+idCarte+".essai."+(i),oCAPITAN_MH_ROULE.gEssais[i+1][0]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][1]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][2]+";"+oCAPITAN_MH_ROULE.gEssais[i+1][3]);
  929. }
  930. }
  931. window.location.replace(window.location);
  932. },
  933.  
  934. createNewRecherche: function(parentElt) {
  935. p = document.createElement('p');
  936.  
  937. var table = document.createElement('table');
  938. table.setAttribute('class', 'mh_tdborder');
  939. table.setAttribute('border', '0');
  940. table.setAttribute('cellspacing', '1');
  941. table.setAttribute('cellpadding', '4');
  942. table.setAttribute('style', 'width: 400px;');
  943. table.setAttribute('align', 'center');
  944. var tbody = document.createElement('tbody');
  945. table.appendChild(tbody);
  946.  
  947. var td = this.createCase("Rajouter manuellement une recherche :",tbody);
  948.  
  949. td.appendChild(document.createElement('br'));
  950. td.appendChild(document.createTextNode("X = "));
  951. this.addInput(td, "rX");
  952. td.appendChild(document.createTextNode(" Y = "));
  953. this.addInput(td, "rY");
  954. td.appendChild(document.createTextNode(" N = "));
  955. this.addInput(td, "rN");
  956. td.appendChild(document.createElement('br'));
  957. td.appendChild(document.createTextNode("Nombre de chiffres bien placés : "));
  958. this.addInput(td, "rBP",1);
  959. td.appendChild(document.createElement('br'));
  960. var button=this.appendButton(td, "Ajouter", this.addRecherche);
  961.  
  962. p.appendChild(table);
  963. parentElt.appendChild(p);
  964. },
  965.  
  966. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  967. PrepareRecupFromLocalStorage: function(idCarte) {
  968. var table = document.createElement('table');
  969. table.setAttribute('class', 'mh_tdborder');
  970. table.setAttribute('border', '0');
  971. table.setAttribute('cellspacing', '1');
  972. table.setAttribute('cellpadding', '4');
  973. table.setAttribute('style', 'width: 400px;');
  974. table.setAttribute('align', 'center');
  975.  
  976. var thead = document.createElement('thead');
  977. var tr = this.appendTr(thead, 'mh_tdtitre');
  978. var td = this.appendTdText(tr, "Récupération des anciens essais V1.1", true);
  979. td.setAttribute('align', 'center');
  980. td.title = "C'est ici pour tenter de récupérer les essais faits avec le version 1.1 du script";
  981. table.appendChild(thead);
  982.  
  983. var tbody = document.createElement('tbody');
  984. tbody.idCarte = idCarte;
  985. table.appendChild(tbody);
  986.  
  987. td.addEventListener("click", this.recupFromLocalStorage, true);
  988. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  989. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  990. td.setAttribute('colspan', 2);
  991. tbody.setAttribute('style', 'display:none;');
  992.  
  993. return table;
  994. },
  995.  
  996. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  997. recupFromLocalStorage: function() {
  998. var tbody = this.parentNode.parentNode.parentNode.childNodes[1];
  999. if (tbody.RecupVisible) return; // ne pas populer 2 fois
  1000. var idCarte = parseInt(tbody.idCarte);
  1001. tbody.setAttribute('style', !tbody.getAttribute('style') || tbody.getAttribute('style') == '' ? 'display:none;' : '');
  1002. // entrée d'un jeu de test
  1003. // window.localStorage.setItem('91305.capitan.8600686.essai.1', '1;2;3;4');
  1004. // window.localStorage.removeItem('91305.capitan.8600686.essai.2');
  1005. // window.localStorage.removeItem('91305.capitan.8600686.essai.3');
  1006. // window.localStorage.removeItem('91306.capitan.8600686.essai.1');
  1007. // window.localStorage.setItem('91305.capitan.8600686.essai.2', '1;2;-4;4');
  1008. // window.localStorage.setItem('91305.capitan.8600686.essai.3', '1;-2;5;4');
  1009. // window.localStorage.setItem('91306.capitan.8600686.essai.1', '-1;2;6;4');
  1010. // return;
  1011.  
  1012. try {
  1013. var nLocalStorage = window.localStorage.length;
  1014. //var td2 = this.createCase('nLocalStorage=' + nLocalStorage,tbody,400);
  1015. var nAlready = 0;
  1016. var nRecup = 0;
  1017. for (var iKey = 0; iKey < nLocalStorage; iKey++) {
  1018. var k = window.localStorage.key(iKey);
  1019. //var td2 = this.createCase(k + '=' + v,tbody,400); // debug
  1020. var m = k.match(/(\d*)\.capitan\.(\d*)\.essai\.(\d*)/i);
  1021. if (!m) continue; // pas une entrée de carte de capitan
  1022. if (parseInt(m[2]) != idCarte) continue; // pas la même carte
  1023.  
  1024. var v = window.localStorage.getItem(k);
  1025. //var nTroll = parseInt(m[1]); // pas utile
  1026. //var nEssai = parseInt(m[3]); // pas utile non plus
  1027. var bAlready = this.testAlready(idCarte, v);
  1028. if (bAlready) { // déjà connu : on compte et on ignore
  1029. nAlready++;
  1030. continue;
  1031. }
  1032. // extraire x, y, n, nb
  1033. m = v.match(/([+-]?\d*);([+-]?\d*);([+-]?\d*);(\d*)/i);
  1034. if (!m) {
  1035. var td2 = this.createCase('Erreur à la récupération des coordonnées ' + v,tbody,400);
  1036. continue;
  1037. }
  1038. var x = m[1];
  1039. var y = m[2];
  1040. var n = m[3];
  1041. var nbChiffres = m[4];
  1042. // ajout sous Greasemonkey
  1043. this.addOneRecherche(idCarte, x, y, n, nbChiffres);
  1044. nRecup++;
  1045. var td2 = this.createCase('Recherche récupérée X = '+ x + ', Y = ' + y + ', N = ' + n + ' => ' + nbChiffres,tbody,400);
  1046. }
  1047. if (nRecup > 0) {
  1048. var td2 = this.createCase('Recharger la page (F5) maintenant',tbody,400);
  1049. td2.style.fontWeight="bold";
  1050. }
  1051. if (nAlready > 0) {
  1052. var td2 = this.createCase(nAlready + ' recherche(s) avaient déjà été récupérée(s)',tbody,400);
  1053. td2.style.fontStyle="italic";
  1054. }
  1055. if (nRecup == 0 && nAlready == 0) {
  1056. var td2 = this.createCase('Désolé, je n\'ai rien trouvé pour la carte ' + idCarte,tbody,400);
  1057. }
  1058. }
  1059. catch(e)
  1060. {
  1061. window.console.log(e);
  1062. }
  1063.  
  1064. tbody.RecupVisible = true;
  1065. },
  1066.  
  1067. testAlready: function(idCarte, v) {
  1068. var v2;
  1069. // tester si cet essai est déjà connu sous Greasemonkey
  1070. var bAlready = false;
  1071. for (var iGM = 0; v2 = this.CAPITAN_getValue("capitan."+idCarte+".essai."+iGM); iGM++) {
  1072. if (v2 != v) continue;
  1073. return true;
  1074. break;
  1075. }
  1076. return false;
  1077. },
  1078.  
  1079. // Roule 25/08/2016 récupération des anciennes recherches (préférences)
  1080. PrepareRecupFromPreferences: function() {
  1081. var table = document.createElement('table');
  1082. table.setAttribute('class', 'mh_tdborder');
  1083. table.setAttribute('border', '0');
  1084. table.setAttribute('cellspacing', '1');
  1085. table.setAttribute('cellpadding', '4');
  1086. table.setAttribute('style', 'width: 400px;');
  1087. table.setAttribute('align', 'center');
  1088.  
  1089. var thead = document.createElement('thead');
  1090. var tr = this.appendTr(thead, 'mh_tdtitre');
  1091. var td = this.appendTdText(tr, "Récupération des anciens essais V1.0", true);
  1092. td.setAttribute('align', 'center');
  1093. td.title = "C'est ici pour entrer manuellement les essais faits avec la version 1.0 du script";
  1094. table.appendChild(thead);
  1095.  
  1096. var tbody = document.createElement('tbody');
  1097. table.appendChild(tbody);
  1098.  
  1099. var td2 = this.createCase("Ouvrez un nouvel onglet sous Firefox",tbody);
  1100. td2.style.textAlign = "left";
  1101.  
  1102. var nbsp = String.fromCharCode(160);
  1103. td2.appendChild(document.createElement('br'));
  1104. td2.appendChild(document.createTextNode("(«" + nbsp + "+" + nbsp + "» à droite des onglets)"));
  1105. td2.appendChild(document.createElement('br'));
  1106. td2.appendChild(document.createTextNode("Tapez dans la barre d'adresse «" + nbsp + "about:config" + nbsp + "» et validez"));
  1107. td2.appendChild(document.createElement('br'));
  1108. td2.appendChild(document.createTextNode("C'est promis, vous ferez attention" + nbsp + "!"));
  1109. td2.appendChild(document.createElement('br'));
  1110. td2.appendChild(document.createTextNode("Filtrez ensuite par «" + nbsp + "capitan" + nbsp +"» (zone «" + nbsp + "Rechercher" + nbsp + "» en haut)"));
  1111. td2.appendChild(document.createElement('br'));
  1112. td2.appendChild(document.createTextNode("Ensuite, ligne par ligne,"));
  1113. td2.appendChild(document.createElement('br'));
  1114. td2.appendChild(document.createTextNode("copiez la ligne (bouton de droite de la souris - copier),"));
  1115. td2.appendChild(document.createElement('br'));
  1116. td2.appendChild(document.createTextNode("(Vous pouvez aussi copier *tout* le contenu de pref.js trouvé dans le profil Firefox)"));
  1117. td2.appendChild(document.createElement('br'));
  1118. td2.appendChild(document.createTextNode("Collez ci-dessous et Ajouter"));
  1119. td2.appendChild(document.createElement('br'));
  1120. var inp = this.addInput(td2, "t", 100);
  1121. inp.removeAttribute('maxlength'); // permettre de copier tout pref.js
  1122. inp.style.width = "350px";
  1123. td2.appendChild(document.createElement('br'));
  1124. var button=this.appendButton(td2, "Ajouter", this.addV1);
  1125.  
  1126. td.addEventListener("click", this.toggleTableau, true);
  1127. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  1128. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  1129. td.setAttribute('colspan', 2);
  1130. tbody.setAttribute('style', 'display:none;');
  1131.  
  1132. return table;
  1133. },
  1134.  
  1135. addV1: function(eButton) {
  1136. // pour test mountyhall.91306.capitan.8600686.essai.1;-1;2;6;4
  1137. try
  1138. {
  1139. var td=this.parentNode;
  1140. var eInput = td.getElementsByTagName("input")[0];
  1141. var val = eInput.value;
  1142. var bClear;
  1143. if (val.match(/user_pref\(/)) {
  1144. bClear = this.addV1Pref(val);
  1145. } else {
  1146. bClear = this.addV1Unitaire(val);
  1147. }
  1148. if (bClear)eInput.value = ''; // vider le champ pour que l'utilisateur puisse copier à nouveau
  1149. }
  1150. catch(e)
  1151. {
  1152. window.alert(e);
  1153. }
  1154. },
  1155.  
  1156. addV1Pref: function(val) {
  1157. // on a tout le contenu de pref.js dans val
  1158. tabPref = val.split(/\);/);
  1159. if (this.bDebug) window.console.log('CAPITAN addV1Pref: nb val=' + tabPref.length);
  1160. //user_pref("mountyzilla.storage.91305.capitan.8600686.essai.1", "1;2;3;4");
  1161. var nAlready = 0;
  1162. var nDone = 0;
  1163. for (var i = 0; i < tabPref.length; i++) {
  1164. var m = tabPref[i].match(/user_pref\(\"mountyzilla\.storage\.(\d*)\.capitan\.(\d*)\.essai\.(\d*)\", *\"([+-]?\d*);([+-]?\d*);([+-]?\d*);(\d*)\"/i);
  1165. if (!m) continue;
  1166. //window.console.log('CAPITAN addV1Pref: trouvé troll ' + m[1] + ', carte ' + m[2] + ', essai ' + m[3] + ', X = ' + m[4] + ', Y=' + m[5] + ', N=' + m[6] + ' => ' + m[7]);
  1167. var bAlready = this.testAlready(m[2], m[4] + ';' + m[5] + ';' + m[6] + ';' + m[7]);
  1168. if (bAlready) {
  1169. nAlready++;
  1170. } else {
  1171. this.addOneRecherche(parseInt(m[2]), m[4], m[5], m[6], m[7]);
  1172. nDone++;
  1173. }
  1174. }
  1175. alert(nAlready + ' essai(s) ont été ignorés car déjà migrés'
  1176. + "\n" + nDone + ' essai(s) viennent d\'être migrés'
  1177. + "\nIl faut rafraichir cette page (F5 ou afficher à nouveau l'équipement)");
  1178. return true;
  1179. },
  1180.  
  1181. addV1Unitaire: function(val) {
  1182. if (this.bDebug) window.console.log('CAPITAN addV1Unitaire: val=' + val);
  1183. var m = val.match(/capitan\.(\d*)\.essai\.(\d*);([+-]?\d*);([+-]?\d*);([+-]?\d*);(\d*)/i);
  1184. if (!m) {
  1185. alert("Désolé, impossible de retrouver le numéro de carte, les coordonnées et le nombre de chiffres bien placés");
  1186. return false;
  1187. }
  1188. var bAlready = this.testAlready(m[1], m[3] + ';' + m[4] + ';' + m[5] + ';' + m[6]);
  1189. if (bAlready) {
  1190. alert("L'essai pour la carte " + m[1] + "\nX = " + m[3]
  1191. + ", Y=" + m[4] + ", N=" + m[5] + " => " + m[6]
  1192. + "\navait DÉJÀ été entré");
  1193. return true;
  1194. }
  1195. this.addOneRecherche(parseInt(m[1]), m[3], m[4], m[5], m[6]);
  1196. alert("L'essai pour la carte " + m[1] + "\nX = " + m[3]
  1197. + ", Y=" + m[4] + ", N=" + m[5] + " => " + m[6]
  1198. + "\na bien été enregistré\nIl faudra rafraichir cette page (F5) quand vous aurez terminé");
  1199. return true;
  1200. },
  1201.  
  1202. addRecherche: function()
  1203. {
  1204. try
  1205. {
  1206. var td=this.parentNode;
  1207. var x = (td.getElementsByTagName("input")[0]).value;
  1208. var y = (td.getElementsByTagName("input")[1]).value;
  1209. var n = (td.getElementsByTagName("input")[2]).value;
  1210. var nbChiffres = (td.getElementsByTagName("input")[3]).value;
  1211. if(x==null || isNaN(parseInt(x)))
  1212. {
  1213. window.alert("Erreur : champ X mal formaté.");
  1214. return;
  1215. }
  1216. if(y==null || isNaN(parseInt(y)))
  1217. {
  1218. window.alert("Erreur : champ Y mal formaté.");
  1219. return;
  1220. }
  1221. if(n==null || isNaN(parseInt(n)))
  1222. {
  1223. window.alert("Erreur : champ N mal formaté.");
  1224. return;
  1225. }
  1226. if(nbChiffres==null || isNaN(parseInt(nbChiffres)))
  1227. {
  1228. window.alert("Erreur : nombre de chiffres bien placés mal formaté.");
  1229. return;
  1230. }
  1231. oCAPITAN_MH_ROULE.addOneRecherche(oCAPITAN_MH_ROULE.getIDCarte(), x, y, n, nbChiffres);
  1232. window.location.replace(window.location);
  1233. }
  1234. catch(e)
  1235. {
  1236. window.alert(e);
  1237. }
  1238. },
  1239.  
  1240. addOneRecherche: function(idCarte, x, y, n, nbChiffres) {
  1241. for (var i = 0; this.CAPITAN_getValue("capitan."+idCarte+".essai."+i); i++){}
  1242. this.CAPITAN_setValue("capitan."+idCarte+".essai."+i,parseInt(x)+";"+parseInt(y)+";"+parseInt(n)+";"+parseInt(nbChiffres));
  1243. },
  1244.  
  1245. addInput: function(parent, nom, size)
  1246. {
  1247. var input = document.createElement('input');
  1248. input.setAttribute('type','text');
  1249. input.setAttribute('name',nom);
  1250. input.setAttribute('type','text');
  1251. input.setAttribute('maxlength',size==null?4:size);
  1252. input.setAttribute('size',size==null?4:size);
  1253. parent.appendChild(input);
  1254. return input;
  1255. },
  1256.  
  1257. infoRecherche: function()
  1258. {
  1259. var idCarte = this.getIntegerByID('carte', 'numéro de carte');
  1260. if (idCarte === undefined) return;
  1261. var x = this.getIntegerByID('x', 'x');
  1262. if (x === undefined) return; // ne pas utiliser «!» car x peut être «0» !
  1263. var y = this.getIntegerByID('y', 'y');
  1264. if (y === undefined) return;
  1265. var n = this.getIntegerByID('n', 'n');
  1266. if (n === undefined) return;
  1267. var nb = this.getIntegerByID('nb', 'le nombre de chiffres bien placés');
  1268. if (nb === undefined) return;
  1269.  
  1270. var i = 0;
  1271. while(this.CAPITAN_getValue("capitan."+idCarte+".essai."+i) != null)
  1272. {
  1273. i++;
  1274. }
  1275. this.CAPITAN_setValue("capitan."+idCarte+".essai."+i,x+";"+y+";"+n+";"+nb);
  1276.  
  1277. if(this.CAPITAN_getValue("capitan."+idCarte+".this.signe") == null)
  1278. {
  1279. var msg = document.getElementById("msgEffet").textContent;
  1280.  
  1281. // fonctionne à la fois pour "Tu es dans..." et "Vous êtes dans..."
  1282. if(!msg.match(/es dans le bon Xcoin/))
  1283. x = -x;
  1284. if(!msg.match(/es dans le bon Ycoin/))
  1285. y = -y;
  1286.  
  1287. this.CAPITAN_setValue("capitan."+idCarte+".this.signe",this.signe(x)+";"+this.signe(y));
  1288. }
  1289.  
  1290. var table = this.afficheInfoCarte(idCarte);
  1291.  
  1292. form = document.getElementsByTagName('FORM')[0];
  1293. var p = document.createElement('p');
  1294. p.appendChild(table);
  1295. form.appendChild(p);
  1296. },
  1297.  
  1298. // return undefined if not found
  1299. getIntegerByID: function(id, msg) {
  1300. var e = document.getElementById(id);
  1301. if (!e || !e.childNodes || !e.childNodes[0] || !e.childNodes[0].nodeValue) {
  1302. if (msg) window.alert('Script carte de Capitan : impossible de retrouver le ' + msg);
  1303. return;
  1304. }
  1305. return parseInt(e.childNodes[0].nodeValue);
  1306. },
  1307.  
  1308. ///////////////////////////////////
  1309. // debuging
  1310. // essais : objet
  1311. // .mode : description
  1312. // .essais : tableau d'objets essai
  1313. // .mode : description
  1314. // .essais : tableau de cartes
  1315. // .noCarte : id de la carte
  1316. // .essais : tableau d'essais, [x, y, n, nb]
  1317. AfficheEssais: function(essais, sMode) {
  1318. var eBigDiv = document.getElementById('ListeEssaiCapitan');
  1319. if (!eBigDiv) {
  1320. var insertPoint = document.getElementById('footer1');
  1321. eBigDiv = document.createElement('table');
  1322. eBigDiv.id = 'ListeEssaiCapitan';
  1323. this.insertBefore(insertPoint, document.createElement('p'));
  1324. this.insertTitle(insertPoint,'Capitan : Liste des essais');
  1325. this.insertBefore(insertPoint, eBigDiv);
  1326. this.addTrEssais(eBigDiv, 'mode', 'carte', 'nombre d\'essais', true);
  1327. }
  1328. if (!essais) {
  1329. this.addTrEssais(eBigDiv, sMode, '', 'pas d\'essai', false);
  1330. return;
  1331. }
  1332. var carte;
  1333. for (carte in essais) {
  1334. this.addTrEssais(eBigDiv, sMode, carte, essais[carte] + ' essai(s)', false);
  1335. }
  1336. if (carte === undefined) {
  1337. this.addTrEssais(eBigDiv, sMode, '', '0 essai', false);
  1338. }
  1339. },
  1340.  
  1341. addTrEssais: function(eTable, sMode, sCarte, sText, bBold) {
  1342. var tr = this.appendTr(eTable);
  1343. var td = this.appendTd(tr);
  1344. this.appendText(td, sMode, bBold);
  1345. td = this.appendTd(tr);
  1346. this.appendText(td, sCarte, bBold);
  1347. td = this.appendTd(tr);
  1348. this.appendText(td, sText, bBold);
  1349. },
  1350.  
  1351. getEssaiV1_2: function() {
  1352. if (!GM_getValue) {
  1353. window.console.log('CAPITAN getEssaiV1_2: pas de GM_getValue');
  1354. return;
  1355. }
  1356. var tabKey = GM_listValues();
  1357. window.console.log('CAPITAN getEssaiV1_2: nb key : ' + tabKey.length);
  1358. var r = [];
  1359. for (var i = 0; i < tabKey.length; i++) {
  1360. var k = tabKey[i];
  1361. //window.console.log('CAPITAN getEssaiV1_2: key ' + k + ' => ' + GM_getValue(k));
  1362. var t = k.split(/\./);
  1363. if (t[0] !== 'capitan') continue;
  1364. if (t[2] !== 'essai') continue;
  1365. var carte = 'carte n°' + t[1];
  1366. if (r[carte]) r[carte]++;
  1367. else r[carte] = 1;
  1368. //window.console.log('CAPITAN getEssaiV1_2: r[' + carte + ']=' + r[carte]);
  1369. }
  1370. return r;
  1371. },
  1372.  
  1373. showEssai: function() {
  1374. window.console.log('CAPITAN début this.showEssai CapitanList');
  1375. var essai1_2 = this.getEssaiV1_2();
  1376. this.AfficheEssais(essai1_2, 'V1.2');
  1377. window.console.log('CAPITAN fin this.showEssai CapitanList');
  1378. },
  1379.  
  1380. CAPITAN_horsGM: false,
  1381. init: function () {
  1382. this.CAPITAN_horsGM = false;
  1383. try { // à partir du 11/07/2018, (GM_info === undefined) provoque une exception
  1384. if (GM_info == undefined) {
  1385. this.CAPITAN_horsGM = true;
  1386. } else if (GM_info.script.version == 'sans GM') {
  1387. this.CAPITAN_horsGM = true;
  1388. }
  1389. } catch (e2) {
  1390. this.CAPITAN_horsGM = true;
  1391. if (this.bDebug) window.console.log('CAPITAN init: test GM_deleteValue, exception=' + e2);
  1392. }
  1393. try {
  1394. if (GM_getValue == undefined) {
  1395. this.CAPITAN_horsGM = true;
  1396. }
  1397. GM_getValue('x'); // provoque une exception hors GM
  1398. } catch (e2) {
  1399. this.CAPITAN_horsGM = true;
  1400. if (this.bDebug) window.console.log('CAPITAN init: test GM_deleteValue, exception=' + e2);
  1401. }
  1402. try {
  1403. if (GM_deleteValue == undefined) {
  1404. this.CAPITAN_horsGM = true;
  1405. }
  1406. } catch (e2) {
  1407. this.CAPITAN_horsGM = true;
  1408. if (this.bDebug) window.console.log('CAPITAN init: test GM_deleteValue, exception=' + e2);
  1409. }
  1410. window.console.log('CAPITAN init: horsGM=' + this.CAPITAN_horsGM);
  1411. if (this.CAPITAN_horsGM) { // remplacer GM_xxxValue
  1412. this.CAPITAN_getValue = function(key) {
  1413. return window.localStorage[key];
  1414. }
  1415. this.CAPITAN_deleteValue = function(key) {
  1416. window.localStorage.removeItem(key);
  1417. }
  1418. this.CAPITAN_setValue = function(key, val) {
  1419. window.localStorage[key] = val;
  1420. }
  1421. } else {
  1422. this.CAPITAN_getValue = GM_getValue;
  1423. this.CAPITAN_deleteValue = GM_deleteValue;
  1424. this.CAPITAN_setValue = GM_setValue;
  1425. }
  1426. if (this.isPage("View/TresorHistory.php"))
  1427. {
  1428. this.analyseObject();
  1429. }
  1430. else if(this.isPage("MH_Play/Actions/Play_a_TrouverCachette2.php"))
  1431. {
  1432. this.infoRecherche();
  1433. }
  1434. else if(this.isPage("MH_Play/Play_equipement.php") || this.isPage("MH_Taniere/TanierePJ_o_Stock.php"))
  1435. {
  1436. // Roule, 23/11/2016, il faudrait trouver mieux pour s'activer quand l'utilisateur ouvre le popup
  1437. //window.setInterval(this.analyseObject.bind(this), 1000); // ceci fonctionne mais n'est supporté que par les navigateurs récents
  1438. window.setInterval(this.analyseObjectCallback, 1000);
  1439. }
  1440. // debuging
  1441. // else if(this.isPage("MH_Play/Options/Play_o_Interface"))
  1442. // {
  1443. // this.showEssai();
  1444. // }
  1445. },
  1446. }
  1447. try
  1448. {
  1449. oCAPITAN_MH_ROULE.init();
  1450. } catch(e) {
  1451. window.console.log('script capitan exception: ' + e);
  1452. }
  1453. }