Capitan

Aide à la recherche de cachettes de Capitan

当前为 2016-10-14 提交的版本,查看 最新版本

  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. // @include */mountyhall/View/TresorHistory*
  8. // @include */mountyhall/MH_Play/Actions/Play_a_TrouverCachette2*
  9. // @name Capitan
  10. // @version 8.1.3
  11. // @namespace https://greasyfork.org/users/70018
  12. // ==/UserScript==
  13.  
  14. /****************************************************************
  15. * Aide à la recherche de cachettes de Capitan *
  16. * Développé par Mini TilK (n°36216) *
  17. * mini@tilk.info *
  18. *****************************************************************
  19. * Adapté pour GreaseMonkey par Dabihul (n°79738) *
  20. * Roule : ajout https 07/08/2016 *
  21. *****************************************************************
  22. * Pour utiliser la recherche, allez des les infos *
  23. * de la carte de la cachette du capitan *
  24. * Une fois ceci fait, *
  25. * toutes les recherches seront sauvergardées *
  26. * Et dans le détail de la carte vous verrez *
  27. * Le nombre de cachettes possibles et leur position *
  28. ****************************************************************/
  29.  
  30. /*
  31. Roule 08 à 10/08/2016
  32. recopie ici de appendButton() version MZ
  33. Ajout liste des essais et possibilité d'en supprimer
  34. Ajout lien vers Psyko Chasseurs
  35. Adaptation aux IDs dans la page de résultat d'une recherche de cachette (et plus besoin de stocker le numéro de carte)
  36. Roule 15/08/2016 V8.1.1
  37. Ajout demande d'avis sur la position courante sur le site Psyko-Chasseurs
  38. Quelques corrections de calcul (on avait du NaN)
  39. Roule 24 à 26/08/2016 V8.1.2
  40. Ajout outils de récupération des recherches pré Greasemonkey
  41. Roule 14/10/2016 V8.1.3
  42. simplification de l'entête GM (include)
  43. passage à greasyfork
  44. */
  45.  
  46. function appendButton(paren,value,onClick) {
  47. var input = document.createElement('input');
  48. input.type = 'button';
  49. input.className = 'mh_form_submit';
  50. input.value = value;
  51. input.onmouseover = function(){this.style.cursor='pointer';};
  52. if (onClick) input.onclick = onClick;
  53. paren.appendChild(input);
  54. return input;
  55. }
  56.  
  57. /* Ajout des éléments manquants de libs */
  58. function isPage(url) {
  59. return window.location.href.indexOf(url)!=-1;
  60. }
  61.  
  62. // Roule 08/08/2016 ajout cssClass
  63. function appendTr(tbody, cssClass) {
  64. var tr = document.createElement('tr');
  65. tbody.appendChild(tr);
  66. if (cssClass) tr.className = cssClass;
  67. return tr;
  68. }
  69.  
  70. function appendTd(tr) {
  71. var td = document.createElement('td');
  72. if(tr) { tr.appendChild(td); }
  73. return td;
  74. }
  75.  
  76. function appendText(paren,text,bold) {
  77. if(bold) {
  78. var b = document.createElement('b');
  79. b.appendChild(document.createTextNode(text));
  80. paren.appendChild(b);
  81. }
  82. else
  83. paren.appendChild(document.createTextNode(text));
  84. }
  85.  
  86. function appendTdText(tr,text,bold) {
  87. var td = appendTd(tr);
  88. appendText(td,text,bold);
  89. return td;
  90. }
  91. /* */
  92.  
  93. function sortNumber(a,b)
  94. {
  95. return b-a;
  96. }
  97.  
  98. function removeTab(tab, i)
  99. {
  100. var newTab = new Array();
  101. for(var j=0;j<i;j++)
  102. {
  103. newTab.push(tab[j]);
  104. }
  105. for(var j=i+1;j<tab.length;j++)
  106. {
  107. newTab.push(tab[j]);
  108. }
  109. return newTab;
  110. }
  111. var cache=new Array();
  112.  
  113. function tabToString(tab)
  114. {
  115. var string = tab[0];
  116. for(var i=1;i<tab.length;i++)
  117. string+=";"+tab[i];
  118. return string;
  119. }
  120.  
  121. function combi(tab)
  122. {
  123. var newTab = new Array();
  124. if(tab.length==1)
  125. {
  126. newTab[""+tab[0]]=1;
  127. return newTab;
  128. }
  129. var val = tabToString(tab);
  130. if(cache[val])
  131. return cache[val];
  132. for(var i=0;i<tab.length;i++)
  133. {
  134. var lastTab = combi(removeTab(tab,i));
  135. for(var j in lastTab)
  136. newTab[tab[i]+";"+j]=1;
  137. }
  138. cache[val]=newTab;
  139. return newTab;
  140. }
  141.  
  142. function affiche(tab)
  143. {
  144. var newTab = combi(tab);
  145. var string="";
  146. for(var i in newTab)
  147. {
  148. string += i+"\n";
  149. }
  150. window.alert(string);
  151. }
  152.  
  153. function extractPosition(nombre, indice)
  154. {
  155. if((nombre+"").length<=indice)
  156. return "%";
  157. indice = (nombre+"").length - 1 - indice;
  158. return (nombre+"").substring(indice,indice+1);
  159. }
  160.  
  161. function comparePos(x,y,n,x1,y1,n1)
  162. {
  163. x = Math.abs(x);
  164. y = Math.abs(y);
  165. n = Math.abs(n);
  166. x1 = Math.abs(x1);
  167. y1 = Math.abs(y1);
  168. n1 = Math.abs(n1);
  169. var nbGood=0;
  170. for(var i=0;i<(x+"").length;i++)
  171. if(extractPosition(x,i)==extractPosition(x1,i))
  172. nbGood++;
  173. for(var i=0;i<(y+"").length;i++)
  174. if(extractPosition(y,i)==extractPosition(y1,i))
  175. nbGood++;
  176. for(var i=0;i<(n+"").length;i++)
  177. if(extractPosition(n,i)==extractPosition(n1,i))
  178. nbGood++;
  179. return nbGood;
  180. }
  181.  
  182. function signe(x)
  183. {
  184. if(x<0)
  185. return -1;
  186. return 1;
  187. }
  188.  
  189. function getPosFromArray(liste,begin,length)
  190. {
  191. var pos="";
  192. for(var i=begin;i<begin+length;i++)
  193. pos+=""+liste[i];
  194. return parseInt(pos, 10);
  195. }
  196.  
  197. function calculeSolution6(x,y,n,essais)
  198. {
  199. var listeChiffre = new Array();
  200. for(var i=0;i<(Math.abs(x)+"").length;i++)
  201. listeChiffre.push(extractPosition(Math.abs(x),i));
  202. for(var i=0;i<(Math.abs(y)+"").length;i++)
  203. listeChiffre.push(extractPosition(Math.abs(y),i));
  204. for(var i=0;i<(Math.abs(n)+"").length;i++)
  205. listeChiffre.push(extractPosition(Math.abs(n),i));
  206. var listeSolutionsPossibles = combi(listeChiffre);
  207. var listeSolutions = new Array();
  208. for(var key in listeSolutionsPossibles)
  209. {
  210. var liste = key.split(";");
  211. var x1 = getPosFromArray(liste,0,listeChiffre.length/3);
  212. var y1 = getPosFromArray(liste,listeChiffre.length/3,listeChiffre.length/3);
  213. var n1 = getPosFromArray(liste,2*(listeChiffre.length)/3,listeChiffre.length/3);
  214. var oki = true;
  215. for(var i=0;i<essais.length;i++)
  216. {
  217. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  218. {
  219. oki=false;
  220. break;
  221. }
  222. }
  223. if(oki)
  224. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  225. }
  226. return listeSolutions;
  227. }
  228.  
  229. function calculeSolution5(x,y,n,essais)
  230. {
  231. var listeChiffre = new Array();
  232. for(var i=0;i<(Math.abs(x)+"").length;i++)
  233. listeChiffre.push(extractPosition(Math.abs(x),i));
  234. for(var i=0;i<(Math.abs(y)+"").length;i++)
  235. listeChiffre.push(extractPosition(Math.abs(y),i));
  236. for(var i=0;i<(Math.abs(n)+"").length;i++)
  237. listeChiffre.push(extractPosition(Math.abs(n),i));
  238. var listeSolutionsPossibles = combi(listeChiffre);
  239. var length = Math.floor(listeChiffre.length/3);
  240. var listeSolutions = new Array();
  241. for(var key in listeSolutionsPossibles)
  242. {
  243. var liste = key.split(";");
  244. var x1 = getPosFromArray(liste,0,length);
  245. var y1 = getPosFromArray(liste,length,length+1);
  246. var n1 = getPosFromArray(liste,2*length+1,length+1);
  247. var oki = true;
  248. for(var i=0;i<essais.length;i++)
  249. {
  250. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  251. {
  252. oki=false;
  253. break;
  254. }
  255. }
  256. if(oki)
  257. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  258. }
  259. for(var key in listeSolutionsPossibles)
  260. {
  261. var liste = key.split(";");
  262. var x1 = getPosFromArray(liste,0,length+1);
  263. var y1 = getPosFromArray(liste,length+1,length);
  264. var n1 = getPosFromArray(liste,2*length+1,length+1);
  265. var oki = true;
  266. for(var i=0;i<essais.length;i++)
  267. {
  268. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  269. {
  270. oki=false;
  271. break;
  272. }
  273. }
  274. if(oki)
  275. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  276. }
  277. for(var key in listeSolutionsPossibles)
  278. {
  279. var liste = key.split(";");
  280. var x1 = getPosFromArray(liste,0,length+1);
  281. var y1 = getPosFromArray(liste,length+1,length+1);
  282. var n1 = getPosFromArray(liste,2*length+2,length);
  283. var oki = true;
  284. for(var i=0;i<essais.length;i++)
  285. {
  286. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  287. {
  288. oki=false;
  289. break;
  290. }
  291. }
  292. if(oki)
  293. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  294. }
  295. return listeSolutions;
  296. }
  297.  
  298. function calculeSolution4(x,y,n,essais)
  299. {
  300. var listeChiffre = new Array();
  301. for(var i=0;i<(Math.abs(x)+"").length;i++)
  302. listeChiffre.push(extractPosition(Math.abs(x),i));
  303. for(var i=0;i<(Math.abs(y)+"").length;i++)
  304. listeChiffre.push(extractPosition(Math.abs(y),i));
  305. for(var i=0;i<(Math.abs(n)+"").length;i++)
  306. listeChiffre.push(extractPosition(Math.abs(n),i));
  307. var listeSolutionsPossibles = combi(listeChiffre);
  308. var length = Math.floor(listeChiffre.length/3);
  309. var listeSolutions = new Array();
  310. for(var key in listeSolutionsPossibles)
  311. {
  312. var liste = key.split(";");
  313. var x1 = getPosFromArray(liste,0,length);
  314. var y1 = getPosFromArray(liste,length,length);
  315. var n1 = getPosFromArray(liste,2*length,length+1);
  316. var oki = true;
  317. for(var i=0;i<essais.length;i++)
  318. {
  319. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  320. {
  321. oki=false;
  322. break;
  323. }
  324. }
  325. if(oki)
  326. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  327. }
  328. for(var key in listeSolutionsPossibles)
  329. {
  330. var liste = key.split(";");
  331. var x1 = getPosFromArray(liste,0,length+1);
  332. var y1 = getPosFromArray(liste,length+1,length);
  333. var n1 = getPosFromArray(liste,2*length+1,length);
  334. var oki = true;
  335. for(var i=0;i<essais.length;i++)
  336. {
  337. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  338. {
  339. oki=false;
  340. break;
  341. }
  342. }
  343. if(oki)
  344. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  345. }
  346. for(var key in listeSolutionsPossibles)
  347. {
  348. var liste = key.split(";");
  349. var x1 = getPosFromArray(liste,0,length);
  350. var y1 = getPosFromArray(liste,length,length+1);
  351. var n1 = getPosFromArray(liste,2*length+1,length);
  352. var oki = true;
  353. for(var i=0;i<essais.length;i++)
  354. {
  355. if(essais[i][3] != comparePos(x1,y1,n1,Math.abs(essais[i][0]),Math.abs(essais[i][1]),Math.abs(essais[i][2])))
  356. {
  357. oki=false;
  358. break;
  359. }
  360. }
  361. if(oki)
  362. listeSolutions.push(new Array(x1*signe(x),y1*signe(y),n1*signe(n)));
  363. }
  364. return listeSolutions;
  365. }
  366.  
  367. function calculeSolution(x,y,n,essais)
  368. {
  369. var size = (";"+Math.abs(x)+Math.abs(y)+Math.abs(n)).length-1;
  370. if(size%3==0)
  371. return calculeSolution6(x,y,n,essais);
  372. if(size%3==1)
  373. return calculeSolution4(x,y,n,essais);
  374. if(size%3==2)
  375. return calculeSolution5(x,y,n,essais);
  376. }
  377. function afficheSolutions(x,y,n,essais)
  378. {
  379. var listeSolutions = calculeSolution(x,y,n,essais);
  380. var string="Il y a "+listeSolutions.length+" solutions";
  381. if(listeSolutions.length<=10)
  382. {
  383. for(var i=0;i<listeSolutions.length;i++)
  384. {
  385. string+= "\n x="+listeSolutions[i][0]+" y="+listeSolutions[i][1]+" n="+listeSolutions[i][2];
  386. }
  387. }
  388. return string;
  389. }
  390.  
  391. function toggleTableau() {
  392.  
  393. var tbody = this.parentNode.parentNode.parentNode.childNodes[1];
  394. tbody.setAttribute('style', !tbody.getAttribute('style') || tbody.getAttribute('style') == '' ? 'display:none;' : '');
  395. }
  396.  
  397. function createCase(titre,table,width)
  398. {
  399. if(width==null)
  400. width="120";
  401. var tr = appendTr(table, 'mh_tdpage');
  402.  
  403. var td = appendTdText(tr, titre, true);
  404. td.setAttribute('class', 'mh_tdpage');
  405. td.setAttribute('width', width);
  406. td.setAttribute('align', 'center');
  407.  
  408. return td;
  409. }
  410.  
  411. var tbody;
  412.  
  413. function generateTable(listeSolutions)
  414. {
  415. var table = document.createElement('table');
  416. table.setAttribute('class', 'mh_tdborder');
  417. table.setAttribute('border', '0');
  418. table.setAttribute('cellspacing', '1');
  419. table.setAttribute('cellpadding', '4');
  420. table.setAttribute('style', 'width: 400px;');
  421. table.setAttribute('align', 'center');
  422. if(listeSolutions.length==1)
  423. {
  424. var thead = document.createElement('thead');
  425. var tr = appendTr(thead, 'mh_tdtitre');
  426. var td = appendTdText(tr, "Position de la cachette : X = "+listeSolutions[0][0]+", Y = "+listeSolutions[0][1]+", N = "+listeSolutions[0][2], true);
  427. td.setAttribute('align', 'center');
  428. table.appendChild(thead);
  429. return table;
  430. }
  431. else if(listeSolutions.length==0)
  432. {
  433. var thead = document.createElement('thead');
  434. var tr = appendTr(thead, 'mh_tdtitre');
  435. var td = appendTdText(tr, "Aucune solution trouvée.", true);
  436. td.setAttribute('align', 'center');
  437. table.appendChild(thead);
  438. return table;
  439. }
  440. var thead = document.createElement('thead');
  441. var tr = appendTr(thead, 'mh_tdtitre');
  442. var td = appendTdText(tr, "Il y a "+listeSolutions.length+" positions possibles", true);
  443. td.setAttribute('align', 'center');
  444. table.appendChild(thead);
  445. tbody = document.createElement('tbody');
  446. table.appendChild(tbody);
  447. for (var i = 0; i < listeSolutions.length; i++) {
  448. createCase("X = "+listeSolutions[i][0]+", Y = "+listeSolutions[i][1]+", N = "+listeSolutions[i][2],tbody,400);
  449. }
  450. td.addEventListener("click", toggleTableau, true);
  451. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  452. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  453. tbody.setAttribute('style', 'display:none;');
  454. return table;
  455. }
  456.  
  457. var listeSolutions = new Array();
  458. var essais; // Roule 08/08/2016 essais en variable globale (pour générer le bloc liste et le bloc pour l'outils de Psycho Chasseurs)
  459.  
  460. function afficheInfoCarte(idCarte)
  461. {
  462. var originalPos = GM_getValue("capitan."+idCarte+".position").split(";");
  463. if(originalPos.length!=3)
  464. return;
  465. essais = new Array();
  466. var i = 0;
  467. while(GM_getValue("capitan."+idCarte+".essai."+i) != null)
  468. {
  469. essais.push(GM_getValue("capitan."+idCarte+".essai."+i).split(";"));
  470. i++;
  471. }
  472. if(GM_getValue("capitan."+idCarte+".signe") !=null)
  473. {
  474. var signes = GM_getValue("capitan."+idCarte+".signe").split(";");
  475. listeSolutions = calculeSolution(Math.abs(originalPos[0])*signe(signes[0]),Math.abs(originalPos[1])*signe(signes[1]),originalPos[2],essais);
  476. }
  477. else
  478. {
  479. listeSolutions = calculeSolution(originalPos[0],originalPos[1],originalPos[2],essais);
  480. }
  481. return generateTable(listeSolutions);
  482. }
  483.  
  484. function getRepartitionFromCase(tx, ty, tn, listeSolutions)
  485. {
  486. // Roule 15/08/2016 plus que dubitatif sur ce calcul de Size, je modifie l'algorithme
  487. //var size = (";"+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])).length-1;
  488. var repartition = new Array();
  489. //for(var i=0;i<size;i++)
  490. // repartition.push(0);
  491. for(var i=0;i<listeSolutions.length;i++)
  492. {
  493. var nbGood = comparePos(listeSolutions[i][0],listeSolutions[i][1],listeSolutions[i][2],tx,ty,tn);
  494. for (var j = repartition.length; j <= nbGood; j++) repartition.push(0); // Roule 15/08/2016 compléter le tableau selon le besoin
  495. repartition[nbGood]++;
  496. }
  497. repartition.sort(sortNumber);
  498. return repartition;
  499. }
  500.  
  501. function getMeanPositionNumber(repartition,nbSolutions)
  502. {
  503. var result=0;
  504. for(var i=0;i<repartition.length;i++)
  505. {
  506. result+=repartition[i]*repartition[i];
  507. }
  508. return result/nbSolutions;
  509. }
  510.  
  511. // Roule 08/08/2016 passage numTroll en paramètre
  512. // Roule 15/08/2016 passage position courante en paramètre (tableau des 3 valeurs)
  513. function newRecherche(listeSolutions, currentPos)
  514. {
  515. if(listeSolutions.length<=1)
  516. return null;
  517. // Roule 15/08/2016 plus que dubitatif sur ce calcul de Size, j'utilise repartition.length
  518. //var size = (";"+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])+Math.abs(listeSolutions[0][0])).length-1;
  519. var repartition = getRepartitionFromCase(currentPos[0], currentPos[1], currentPos[2], listeSolutions);
  520. var size = repartition.length;
  521. //window.console.log('newRecherche, repartition=' + JSON.stringify(repartition));
  522. var table = document.createElement('table');
  523. table.setAttribute('class', 'mh_tdborder');
  524. table.setAttribute('border', '0');
  525. table.setAttribute('cellspacing', '1');
  526. table.setAttribute('cellpadding', '4');
  527. table.setAttribute('style', 'width: 400px;');
  528. table.setAttribute('align', 'center');
  529. var nbNotZero = 0;
  530. for(var i=0;i<size;i++)
  531. {
  532. if(repartition[i]!=0)
  533. nbNotZero++;
  534. }
  535. var string = "Il y a une utilité de faire une recherche en X = "+currentPos[0]+" Y = "+currentPos[1]+" N = "+currentPos[2];
  536. if(nbNotZero<=1)
  537. {
  538. //
  539. var minsolution = listeSolutions.length;
  540. var newpos = "";
  541. var isNotN = true;
  542. for(var dx=-1;dx<=1;dx++)
  543. for(var dy=-1;dy<=1;dy++)
  544. for(var dn=0;dn!=-3;dn=(dn==0?1:dn-2))
  545. {
  546. if(dx==0 && dy==0 && dn==0)
  547. continue;
  548. var tmprepartition = getRepartitionFromCase(currentPos[0]+dx, currentPos[1]+dy, currentPos[2]+dn, listeSolutions);
  549. var tmpmeanscore = getMeanPositionNumber(tmprepartition,listeSolutions.length);
  550. if(((dn==0 || !isNotN) && minsolution>=tmpmeanscore) || (dn!=0 && isNotN && tmpmeanscore<=2*minsolution/3))
  551. {
  552. minsolution = tmpmeanscore;
  553. repartition = tmprepartition;
  554. newpos = "X = "+(currentPos[0]+dx)+" Y = "+(currentPos[1]+dy)+" N = "+(currentPos[2]+dn);
  555. isNotN = (dn==0);
  556. }
  557. }
  558. if(minsolution == listeSolutions.length)
  559. {
  560. var thead = document.createElement('thead');
  561. var tr = appendTr(thead, 'mh_tdtitre');
  562. var td = appendTdText(tr, "Il n'y a aucune utilité de faire une recherche en X = "+currentPos[0]+" Y = "+currentPos[1]+" N = "+currentPos[2], true);
  563. td.setAttribute('align', 'center');
  564. table.appendChild(thead);
  565. return table;
  566. }
  567. string = "Conseil : allez faire une recherche en "+newpos;
  568. }
  569. var thead = document.createElement('thead');
  570. var tr = appendTr(thead, 'mh_tdtitre');
  571. var td = appendTdText(tr,string, true);
  572. td.setAttribute('align', 'center');
  573. table.appendChild(thead);
  574. var tbody = document.createElement('tbody');
  575. table.appendChild(tbody);
  576. for(var i=0;i<size;i++)
  577. {
  578. if(i==size-1)
  579. {
  580. if(repartition[i]!=0)
  581. createCase(Math.round(100*repartition[i]/listeSolutions.length)+"% de chance d'éliminer "+(listeSolutions.length-repartition[i])+" positions possibles",tbody,400);
  582. }
  583. else
  584. {
  585. var n=1;
  586. while((i+n)<size && repartition[i]==repartition[i+n])
  587. n++;
  588. if(repartition[i]!=0)
  589. createCase(Math.round(100*n*repartition[i]/listeSolutions.length)+"% de chance d'éliminer "+(listeSolutions.length-repartition[i])+" positions possibles",tbody,400);
  590. i+=n-1;
  591. }
  592. }
  593. td.addEventListener("click", toggleTableau, true);
  594. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  595. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  596. tbody.setAttribute('style', 'display:none;');
  597. return table;
  598. }
  599.  
  600. // Roule 08/08/2016 récupération numéro de Troll dans la page HTML
  601. function getNumTroll()
  602. {
  603. var infoObjet = document.evaluate("//td[@class = 'mh_tdtitre']/text()[contains(.,'Propriétaire actuel')]",
  604. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  605. //window.console.log('infoObjet.nodeValue=' + infoObjet.nodeValue);
  606. var numTroll = 0;
  607. if(infoObjet)
  608. {
  609. // infoObjet.nodeValue=Propriétaire actuel : TROLL - 91305. Rouletabille
  610. var m = infoObjet.nodeValue.match(/troll[ -]*(\d*)[. +]/i);
  611. if (m) {
  612. //window.console.log(m);
  613. if (m.length > 1) numTroll = parseInt(m[1]);
  614. }
  615. }
  616. //window.console.log('numTroll=' + numTroll);
  617. return numTroll;
  618. }
  619.  
  620. function getIDCarte()
  621. {
  622. var infoObjet = document.evaluate("//div[@class = 'titre2']/text()[contains(.,'Carte de la Cachette')]",
  623. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  624. var idCarte = 0;
  625. if(infoObjet)
  626. {
  627. idCarte = parseInt(infoObjet.nodeValue);
  628. }
  629. return idCarte;
  630. }
  631.  
  632. function analyseObject()
  633. {
  634. var numTroll = getNumTroll(); // Roule 08/08/2016 récupération numéro de Troll dans la page HTML
  635. var idCarte = getIDCarte();
  636. var originalPos = GM_getValue("capitan."+idCarte+".position");
  637. if(!originalPos || originalPos == null)
  638. {
  639. var infoPos = document.evaluate("//td/text()[contains(.,'ai été tué en')]",
  640. document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  641. if(!infoPos)
  642. return
  643. var listePos = infoPos.nodeValue.split("=");
  644. if(listePos.length!=4)
  645. return;
  646. var x = parseInt(listePos[1]);
  647. var y = parseInt(listePos[2]);
  648. var n = parseInt(listePos[3]);
  649. GM_setValue("capitan."+idCarte+".position",x+";"+y+";"+n);
  650. }
  651. // bloc liste de solutions
  652. var table = afficheInfoCarte(idCarte);
  653. var p = document.createElement('p');
  654. p.appendChild(table);
  655. document.body.appendChild(p);
  656. // position courante du Troll
  657. // Roule 08/08/2016 utilisation de localStorage car c'est là que tout_MZ stocke les coord
  658. var curPos = [];
  659. curPos[0] = parseInt(window.localStorage[numTroll+".position.X"]);
  660. curPos[1] = parseInt(window.localStorage[numTroll+".position.Y"]);
  661. curPos[2] = parseInt(window.localStorage[numTroll+".position.N"]);
  662.  
  663. // bloc utilité de faire une recherche sur la position courante
  664. table = newRecherche(listeSolutions, curPos);
  665. if(table!=null)
  666. {
  667. var p = document.createElement('p');
  668. p.appendChild(table);
  669. document.body.appendChild(p);
  670. // bloc ajout de nouvelle recherche
  671. createNewRecherche();
  672. }
  673. // Roule 08/08/2016 bloc des recherches mémorisées
  674. if(essais)
  675. {
  676. table = prevRecherche(idCarte);
  677. var p = document.createElement('p');
  678. p.appendChild(table);
  679. document.body.appendChild(p);
  680. // Roule 08/08/2016 bloc préparant les infos pour l'outil Mamoune (Psyko-Chasseurs)
  681. table = blocMamoune(idCarte, curPos);
  682. if(table!=null)
  683. {
  684. p = document.createElement('p');
  685. p.appendChild(table);
  686. document.body.appendChild(p);
  687. }
  688. }
  689.  
  690. // Roule 25/08/2016 récupération des anciennes recherches (préférences)
  691. table = PrepareRecupFromPreferences();
  692. if(table!=null)
  693. {
  694. p = document.createElement('p');
  695. p.appendChild(table);
  696. document.body.appendChild(p);
  697. }
  698.  
  699. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  700. table = PrepareRecupFromLocalStorage(idCarte);
  701. if(table!=null)
  702. {
  703. p = document.createElement('p');
  704. p.appendChild(table);
  705. document.body.appendChild(p);
  706. }
  707. }
  708.  
  709. // Roule 08/08/2016
  710. function blocMamoune(idCarte, currentPos) {
  711. var table = document.createElement('table');
  712. table.setAttribute('class', 'mh_tdborder');
  713. table.setAttribute('border', '0');
  714. table.setAttribute('cellspacing', '1');
  715. table.setAttribute('cellpadding', '4');
  716. table.setAttribute('style', 'width: 400px;');
  717. table.setAttribute('align', 'center');
  718. var thead = document.createElement('thead');
  719. var tr = appendTr(thead, 'mh_tdtitre');
  720. var td = appendTdText(tr, "Outil du cercle des Psyko-Chasseurs", true);
  721. td.setAttribute('align', 'center');
  722. td.setAttribute('title', 'sélectionnez (triple-clic), copiez et collez dans l\'outil des Psyko-Chasseurs');
  723. table.appendChild(thead);
  724. var tbody = document.createElement('tbody');
  725. table.appendChild(tbody);
  726. // 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#
  727. var tabtxt = new Array();
  728. var currentPosAlreadyDone = false;
  729. for (var i = 0; i < essais.length; i++) {
  730. tabtxt.push(essais[i].join('+'));
  731. if (essais[i][0] == currentPos[0] && essais[i][1] == currentPos[1] && essais[i][2] == currentPos[2]) currentPosAlreadyDone = true;
  732. }
  733. if (!currentPosAlreadyDone) tabtxt.push(currentPos.join('+') + '+%3F'); // spécial pour demander à Mamoune ce qu'elle pense d'un essai à la position courante
  734. var tr2 = appendTr(tbody, 'mh_tdpage');
  735. var td2 = appendTd(tr2);
  736. var originalPos = GM_getValue("capitan."+idCarte+".position").split(";");
  737. if(originalPos.length!=3) {
  738. td2.appendText('Erreur\u00A0: impossible de retrouver les coordonnées de la mort');
  739. } else {
  740. var a = document.createElement('a');
  741. appendText(a, 'Cliquer ici pour savoir ce qu\'en pensent les Psyko-Chasseurs');
  742. 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'));
  743. a.setAttribute('target', 'psykochasseurs');
  744. td2.appendChild(a);
  745. }
  746. td.setAttribute('class', 'mh_tdpage');
  747. //td.setAttribute('width', width);
  748. td.setAttribute('align', 'center');
  749.  
  750. td.addEventListener("click", toggleTableau, true);
  751. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  752. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  753. td.setAttribute('colspan', 2);
  754. tbody.setAttribute('style', 'display:none;');
  755. return table;
  756. }
  757.  
  758. function prevRecherche(idCarte)
  759. {
  760. var table = document.createElement('table');
  761. table.setAttribute('class', 'mh_tdborder');
  762. table.setAttribute('border', '0');
  763. table.setAttribute('cellspacing', '1');
  764. table.setAttribute('cellpadding', '4');
  765. table.setAttribute('style', 'width: 400px;');
  766. table.setAttribute('align', 'center');
  767. var thead = document.createElement('thead');
  768. var tr = appendTr(thead, 'mh_tdtitre');
  769. var td = appendTdText(tr, "Vous avez mémorisé " + essais.length + " essai" + (essais.length > 1 ? "s" : ""), true);
  770. td.setAttribute('align', 'center');
  771. table.appendChild(thead);
  772.  
  773. var tbody = document.createElement('tbody');
  774. table.appendChild(tbody);
  775.  
  776. for (var i = 0; i < essais.length; i++) {
  777. var td2 = createCase("X = "+essais[i][0]+", Y = "+essais[i][1]+", N = "+essais[i][2]+" => "+essais[i][3],tbody,400);
  778. var td3 = appendTd(td2.parentNode);
  779. var bt = appendButton(td3, "Supprimer", delRecherche);
  780. bt.idEssai = i;
  781. bt.idCarte = idCarte;
  782. td3.setAttribute('class', 'mh_tdpage');
  783. td3.setAttribute('width', 200);
  784. td3.setAttribute('align', 'center');
  785. }
  786.  
  787. td.addEventListener("click", toggleTableau, true);
  788. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  789. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  790. td.setAttribute('colspan', 2);
  791. tbody.setAttribute('style', 'display:none;');
  792. return table;
  793. }
  794.  
  795. function delRecherche(e) {
  796. var idEssaiDel = e.target.idEssai;
  797. var idCarte = e.target.idCarte;
  798. window.console.log('idEssaiDel=' + idEssaiDel + ', idCarte=' + idCarte + ', essais.length=' + essais.length);
  799. for (var i = 0; i < essais.length; i++) {
  800. if (i == essais.length - 1) {
  801. window.console.log("delete capitan."+idCarte+".essai."+i)
  802. GM_deleteValue("capitan."+idCarte+".essai."+i);
  803. } else if (i >= idEssaiDel) {
  804. window.console.log("set capitan."+idCarte+".essai."+(i)+'+++'+essais[i+1][0]+";"+essais[i+1][1]+";"+essais[i+1][2]+";"+essais[i+1][3]);
  805. GM_setValue("capitan."+idCarte+".essai."+(i),essais[i+1][0]+";"+essais[i+1][1]+";"+essais[i+1][2]+";"+essais[i+1][3]);
  806. }
  807. }
  808. window.location.replace(window.location);
  809. }
  810.  
  811. function createNewRecherche()
  812. {
  813. p = document.createElement('p');
  814. var table = document.createElement('table');
  815. table.setAttribute('class', 'mh_tdborder');
  816. table.setAttribute('border', '0');
  817. table.setAttribute('cellspacing', '1');
  818. table.setAttribute('cellpadding', '4');
  819. table.setAttribute('style', 'width: 400px;');
  820. table.setAttribute('align', 'center');
  821. var tbody = document.createElement('tbody');
  822. table.appendChild(tbody);
  823. var td = createCase("Rajouter manuellement une recherche :",tbody);
  824.  
  825. td.appendChild(document.createElement('br'));
  826. td.appendChild(document.createTextNode("X = "));
  827. addInput(td, "rX");
  828. td.appendChild(document.createTextNode(" Y = "));
  829. addInput(td, "rY");
  830. td.appendChild(document.createTextNode(" N = "));
  831. addInput(td, "rN");
  832. td.appendChild(document.createElement('br'));
  833. td.appendChild(document.createTextNode("Nombre de chiffres bien placés : "));
  834. addInput(td, "rBP",1);
  835. td.appendChild(document.createElement('br'));
  836. var button=appendButton(td, "Ajouter", addRecherche);
  837. p.appendChild(table);
  838. document.body.appendChild(p);
  839. }
  840.  
  841. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  842. function PrepareRecupFromLocalStorage(idCarte) {
  843. var table = document.createElement('table');
  844. table.setAttribute('class', 'mh_tdborder');
  845. table.setAttribute('border', '0');
  846. table.setAttribute('cellspacing', '1');
  847. table.setAttribute('cellpadding', '4');
  848. table.setAttribute('style', 'width: 400px;');
  849. table.setAttribute('align', 'center');
  850. var thead = document.createElement('thead');
  851. var tr = appendTr(thead, 'mh_tdtitre');
  852. var td = appendTdText(tr, "Récupération des anciens essais V1.1", true);
  853. td.setAttribute('align', 'center');
  854. td.title = "C'est ici pour tenter de récupérer les essais faits avec le version 1.1 du script";
  855. table.appendChild(thead);
  856. var tbody = document.createElement('tbody');
  857. tbody.idCarte = idCarte;
  858. table.appendChild(tbody);
  859. td.addEventListener("click", recupFromLocalStorage, true);
  860. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  861. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  862. td.setAttribute('colspan', 2);
  863. tbody.setAttribute('style', 'display:none;');
  864. return table;
  865. }
  866.  
  867. // Roule 24/08/2016 récupération des anciennes recherches (localStorage)
  868. function recupFromLocalStorage() {
  869. var tbody = this.parentNode.parentNode.parentNode.childNodes[1];
  870. if (tbody.RecupVisible) return; // ne pas populer 2 fois
  871. var idCarte = parseInt(tbody.idCarte);
  872. tbody.setAttribute('style', !tbody.getAttribute('style') || tbody.getAttribute('style') == '' ? 'display:none;' : '');
  873. // entrée d'un jeu de test
  874. // window.localStorage.setItem('91305.capitan.8600686.essai.1', '1;2;3;4');
  875. // window.localStorage.removeItem('91305.capitan.8600686.essai.2');
  876. // window.localStorage.removeItem('91305.capitan.8600686.essai.3');
  877. // window.localStorage.removeItem('91306.capitan.8600686.essai.1');
  878. // window.localStorage.setItem('91305.capitan.8600686.essai.2', '1;2;-4;4');
  879. // window.localStorage.setItem('91305.capitan.8600686.essai.3', '1;-2;5;4');
  880. // window.localStorage.setItem('91306.capitan.8600686.essai.1', '-1;2;6;4');
  881. // return;
  882.  
  883. try {
  884. var nLocalStorage = window.localStorage.length;
  885. //var td2 = createCase('nLocalStorage=' + nLocalStorage,tbody,400);
  886. var nAlready = 0;
  887. var nRecup = 0;
  888. for (var iKey = 0; iKey < nLocalStorage; iKey++) {
  889. var k = window.localStorage.key(iKey);
  890. //var td2 = createCase(k + '=' + v,tbody,400); // debug
  891. var m = k.match(/(\d*)\.capitan\.(\d*)\.essai\.(\d*)/i);
  892. if (!m) continue; // pas une entrée de carte de capitan
  893. if (parseInt(m[2]) != idCarte) continue; // pas la même carte
  894.  
  895. var v = window.localStorage.getItem(k);
  896. //var nTroll = parseInt(m[1]); // pas utile
  897. //var nEssai = parseInt(m[3]); // pas utile non plus
  898. var bAlready = testAlready(idCarte, v);
  899. if (bAlready) { // déjà connu : on compte et on ignore
  900. nAlready++;
  901. continue;
  902. }
  903. // extraire x, y, n, nb
  904. m = v.match(/([+-]?\d*);([+-]?\d*);([+-]?\d*);(\d*)/i);
  905. if (!m) {
  906. var td2 = createCase('Erreur à la récupération des coordonnées ' + v,tbody,400);
  907. continue;
  908. }
  909. var x = m[1];
  910. var y = m[2];
  911. var n = m[3];
  912. var nbChiffres = m[4];
  913. // ajout sous Greasemonkey
  914. addOneRecherche(idCarte, x, y, n, nbChiffres);
  915. nRecup++;
  916. var td2 = createCase('Recherche récupérée X = '+ x + ', Y = ' + y + ', N = ' + n + ' => ' + nbChiffres,tbody,400);
  917. }
  918. if (nRecup > 0) {
  919. var td2 = createCase('Recharger la page (F5) maintenant',tbody,400);
  920. td2.style.fontWeight="bold";
  921. }
  922. if (nAlready > 0) {
  923. var td2 = createCase(nAlready + ' recherche(s) avaient déjà été récupérée(s)',tbody,400);
  924. td2.style.fontStyle="italic";
  925. }
  926. if (nRecup == 0 && nAlready == 0) {
  927. var td2 = createCase('Désolé, je n\'ai rien trouvé pour la carte ' + idCarte,tbody,400);
  928. }
  929. }
  930. catch(e)
  931. {
  932. window.console.log(e);
  933. }
  934.  
  935. tbody.RecupVisible = true;
  936. }
  937.  
  938. function testAlready(idCarte, v) {
  939. var v2;
  940. // tester si cet essai est déjà connu sous Greasemonkey
  941. var bAlready = false;
  942. for (var iGM = 0; v2 = GM_getValue("capitan."+idCarte+".essai."+iGM); iGM++) {
  943. if (v2 != v) continue;
  944. return true;
  945. break;
  946. }
  947. return false;
  948. }
  949.  
  950. // Roule 25/08/2016 récupération des anciennes recherches (préférences)
  951. function PrepareRecupFromPreferences() {
  952. var table = document.createElement('table');
  953. table.setAttribute('class', 'mh_tdborder');
  954. table.setAttribute('border', '0');
  955. table.setAttribute('cellspacing', '1');
  956. table.setAttribute('cellpadding', '4');
  957. table.setAttribute('style', 'width: 400px;');
  958. table.setAttribute('align', 'center');
  959. var thead = document.createElement('thead');
  960. var tr = appendTr(thead, 'mh_tdtitre');
  961. var td = appendTdText(tr, "Récupération des anciens essais V1.0", true);
  962. td.setAttribute('align', 'center');
  963. td.title = "C'est ici pour entrer manuellement les essais faits avec la version 1.0 du script";
  964. table.appendChild(thead);
  965.  
  966. var tbody = document.createElement('tbody');
  967. table.appendChild(tbody);
  968.  
  969. var td2 = createCase("Ouvrez un nouvel onglet sous Firefox",tbody);
  970. td2.style.textAlign = "left";
  971.  
  972. var nbsp = String.fromCharCode(160);
  973. td2.appendChild(document.createElement('br'));
  974. td2.appendChild(document.createTextNode("(«" + nbsp + "+" + nbsp + "» à droite des onglets)"));
  975. td2.appendChild(document.createElement('br'));
  976. td2.appendChild(document.createTextNode("Tapez dans la barre d'adresse «" + nbsp + "about:config" + nbsp + "» et validez"));
  977. td2.appendChild(document.createElement('br'));
  978. td2.appendChild(document.createTextNode("C'est promis, vous ferez attention" + nbsp + "!"));
  979. td2.appendChild(document.createElement('br'));
  980. td2.appendChild(document.createTextNode("Filtrez ensuite par «" + nbsp + "capitan" + nbsp +"» (zone «" + nbsp + "Rechercher" + nbsp + "» en haut)"));
  981. td2.appendChild(document.createElement('br'));
  982. td2.appendChild(document.createTextNode("Ensuite, ligne par ligne,"));
  983. td2.appendChild(document.createElement('br'));
  984. td2.appendChild(document.createTextNode("copiez la ligne (bouton de droite de la souris - copier),"));
  985. td2.appendChild(document.createElement('br'));
  986. td2.appendChild(document.createTextNode("Collez ci-dessous et Ajouter"));
  987. td2.appendChild(document.createElement('br'));
  988. var inp = addInput(td2, "t", 100);
  989. inp.style.width = "350px";
  990. td2.appendChild(document.createElement('br'));
  991. var button=appendButton(td2, "Ajouter", addV1);
  992.  
  993. td.addEventListener("click", toggleTableau, true);
  994. td.setAttribute('onmouseover', "this.style.cursor = 'pointer'; this.className = 'mh_tdpage';");
  995. td.setAttribute('onmouseout', "this.className = 'mh_tdtitre';");
  996. td.setAttribute('colspan', 2);
  997. tbody.setAttribute('style', 'display:none;');
  998. return table;
  999. }
  1000.  
  1001. function addV1(eButton) {
  1002. // pour test mountyhall.91306.capitan.8600686.essai.1;-1;2;6;4
  1003. try
  1004. {
  1005. var td=this.parentNode;
  1006. var eInput = td.getElementsByTagName("input")[0];
  1007. var val = eInput.value;
  1008. //window.console.log('val=' + val);
  1009. var m = val.match(/capitan\.(\d*)\.essai\.(\d*);([+-]?\d*);([+-]?\d*);([+-]?\d*);(\d*)/i);
  1010. if (!m) {
  1011. alert("Désolé, impossible de retrouver le numéro de carte, les coordonnées et le nombre de chiffres bien placés");
  1012. return;
  1013. }
  1014. var bAlready = testAlready(m[1], m[3] + ';' + m[4] + ';' + m[5] + ';' + m[6]);
  1015. if (bAlready) {
  1016. alert("L'essai pour la carte " + m[1] + "\nX = " + m[3]
  1017. + ", Y=" + m[4] + ", N=" + m[5] + " => " + m[6]
  1018. + "\navait DÉJÀ été entré");
  1019. eInput.value = ''; // vider le champ pour que l'utilisateur puisse copier à nouveau
  1020. return;
  1021. }
  1022. addOneRecherche(parseInt(m[1]), m[3], m[4], m[5], m[6]);
  1023. alert("L'essai pour la carte " + m[1] + "\nX = " + m[3]
  1024. + ", Y=" + m[4] + ", N=" + m[5] + " => " + m[6]
  1025. + "\na bien été enregistré\nIl faudra rafraichir cette page (F5) quand vous aurez terminé");
  1026. eInput.value = ''; // vider le champ pour que l'utilisateur puisse copier à nouveau
  1027. }
  1028. catch(e)
  1029. {
  1030. window.alert(e);
  1031. }
  1032. }
  1033.  
  1034. function addRecherche()
  1035. {
  1036. try
  1037. {
  1038. var td=this.parentNode;
  1039. var x = (td.getElementsByTagName("input")[0]).value;
  1040. var y = (td.getElementsByTagName("input")[1]).value;
  1041. var n = (td.getElementsByTagName("input")[2]).value;
  1042. var nbChiffres = (td.getElementsByTagName("input")[3]).value;
  1043. if(x==null || isNaN(parseInt(x)))
  1044. {
  1045. window.alert("Erreur : champ X mal formaté.");
  1046. return;
  1047. }
  1048. if(y==null || isNaN(parseInt(y)))
  1049. {
  1050. window.alert("Erreur : champ Y mal formaté.");
  1051. return;
  1052. }
  1053. if(n==null || isNaN(parseInt(n)))
  1054. {
  1055. window.alert("Erreur : champ N mal formaté.");
  1056. return;
  1057. }
  1058. if(nbChiffres==null || isNaN(parseInt(nbChiffres)))
  1059. {
  1060. window.alert("Erreur : nombre de chiffres bien placés mal formaté.");
  1061. return;
  1062. }
  1063. addOneRecherche(getIDCarte(), x, y, n, nbChiffres);
  1064. window.location.replace(window.location);
  1065. }
  1066. catch(e)
  1067. {
  1068. window.alert(e);
  1069. }
  1070. }
  1071.  
  1072. function addOneRecherche(idCarte, x, y, n, nbChiffres) {
  1073. for (var i = 0; GM_getValue("capitan."+idCarte+".essai."+i); i++){}
  1074. GM_setValue("capitan."+idCarte+".essai."+i,parseInt(x)+";"+parseInt(y)+";"+parseInt(n)+";"+parseInt(nbChiffres));
  1075. }
  1076.  
  1077. function addInput(parent, nom, size)
  1078. {
  1079. var input = document.createElement('input');
  1080. input.setAttribute('type','text');
  1081. input.setAttribute('name',nom);
  1082. input.setAttribute('type','text');
  1083. input.setAttribute('maxlength',size==null?4:size);
  1084. input.setAttribute('size',size==null?4:size);
  1085. parent.appendChild(input);
  1086. return input;
  1087. }
  1088.  
  1089. function infoRecherche()
  1090. {
  1091. var idCarte = getIntegerByID('carte', 'numéro de carte');
  1092. if (idCarte === undefined) return;
  1093. var x = getIntegerByID('x', 'x');
  1094. if (x === undefined) return; // ne pas utiliser «!» car x peut être «0» !
  1095. var y = getIntegerByID('y', 'y');
  1096. if (y === undefined) return;
  1097. var n = getIntegerByID('n', 'n');
  1098. if (n === undefined) return;
  1099. var nb = getIntegerByID('nb', 'le nombre de chiffres bien placés');
  1100. if (nb === undefined) return;
  1101.  
  1102. var i = 0;
  1103. while(GM_getValue("capitan."+idCarte+".essai."+i) != null)
  1104. {
  1105. i++;
  1106. }
  1107. GM_setValue("capitan."+idCarte+".essai."+i,x+";"+y+";"+n+";"+nb);
  1108.  
  1109. var table = afficheInfoCarte(idCarte);
  1110. form = document.getElementsByTagName('FORM')[0];
  1111. var p = document.createElement('p');
  1112. p.appendChild(table);
  1113. form.appendChild(p);
  1114. }
  1115.  
  1116. // return undefined if not found
  1117. function getIntegerByID(id, msg) {
  1118. var e = document.getElementById(id);
  1119. if (!e || !e.childNodes || !e.childNodes[0] || !e.childNodes[0].nodeValue) {
  1120. window.alert('Script carte de Capitan : impossible de retrouver le ' + msg);
  1121. return;
  1122. }
  1123. return parseInt(e.childNodes[0].nodeValue);
  1124. }
  1125.  
  1126. try
  1127. {
  1128. if (isPage("View/TresorHistory.php"))
  1129. {
  1130. analyseObject();
  1131. }
  1132. else if(isPage("MH_Play/Actions/Play_a_TrouverCachette2.php"))
  1133. {
  1134. infoRecherche();
  1135. }
  1136. }
  1137. catch(e)
  1138. {
  1139. window.alert(e);
  1140. }
  1141.