Lafay

Script permettant de poster ses séances facilement

当前为 2015-03-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Lafay
  3. // @namespace Lafay
  4. // @include http://www.musculaction.com/forum/*
  5. // @version 2
  6. // @grant none
  7. // @description Script permettant de poster ses séances facilement
  8. // ==/UserScript==
  9.  
  10. /* ------ Permet d'utiliser unsafeWindow sous Chrome ---------*/
  11. var bGreasemonkeyServiceDefined = false;
  12.  
  13. try {
  14. if (typeof Components.interfaces.gmIGreasemonkeyService === "object") {
  15. bGreasemonkeyServiceDefined = true;
  16. }
  17. }
  18. catch (err) {
  19. //Ignore.
  20. console.log(err);
  21. }
  22.  
  23. if ( typeof unsafeWindow === "undefined" || ! bGreasemonkeyServiceDefined) {
  24. unsafeWindow = ( function () {
  25. var dummyElem = document.createElement('p');
  26. dummyElem.setAttribute ('onclick', 'return window;');
  27. return dummyElem.onclick ();
  28. } ) ();
  29. }
  30. /* ------ Permet d'utiliser unsafeWindow sous Chrome ---------*/
  31.  
  32. // Variables globales
  33. var seances = [];
  34. var bbcode = 0;
  35. var nbEchauffement = 5;
  36. var totaux = [];
  37. var start = 0, end = 0;
  38. var timer = false, timerDecompte = false;
  39. var soixDix = false;
  40. var hexDigits = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
  41. var decompteEnCours = false;
  42.  
  43. var snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAAEk3nRd2qAAAAACiDgAAAAAAABCqEEQRLCgwpBGMlJkIz8jKhGvj4k6jzRnqasNKIeoh5gI7BJaC1A1AoNBjJgbyApVS4IDlZgDU5WUAxEKDNmmALHzZp0Fkz1FMTmGFl1FMEyodIavcCAUHDWrKAIA4aa2oCgILEBupZgHvAhEBcZ6joQBxS76AgccrFlczBvKLC0QI2cBoCFvfTDAo7eoOQInqDPBtvrDEZBNYN5xwNwxQRfw8ZQ5wQVLvO8OYU+mHvFLlDh05Mdg7BT6YrRPpCBznMB2r//xKJjyyOh+cImr2/4doscwD6neZjuZR4AgAABYAAAABy1xcdQtxYBYYZdifkUDgzzXaXn98Z0oi9ILU5mBjFANmRwlVJ3/6jYDAmxaiDG3/6xjQQCCKkRb/6kg/wW+kSJ5//rLobkLSiKmqP/0ikJuDaSaSf/6JiLYLEYnW/+kXg1WRVJL/9EmQ1YZIsv/6Qzwy5qk7/+tEU0nkls3/zIUMPKNX/6yZLf+kFgAfgGyLFAUwY//uQZAUABcd5UiNPVXAAAApAAAAAE0VZQKw9ISAAACgAAAAAVQIygIElVrFkBS+Jhi+EAuu+lKAkYUEIsmEAEoMeDmCETMvfSHTGkF5RWH7kz/ESHWPAq/kcCRhqBtMdokPdM7vil7RG98A2sc7zO6ZvTdM7pmOUAZTnJW+NXxqmd41dqJ6mLTXxrPpnV8avaIf5SvL7pndPvPpndJR9Kuu8fePvuiuhorgWjp7Mf/PRjxcFCPDkW31srioCExivv9lcwKEaHsf/7ow2Fl1T/9RkXgEhYElAoCLFtMArxwivDJJ+bR1HTKJdlEoTELCIqgEwVGSQ+hIm0NbK8WXcTEI0UPoa2NbG4y2K00JEWbZavJXkYaqo9CRHS55FcZTjKEk3NKoCYUnSQ0rWxrZbFKbKIhOKPZe1cJKzZSaQrIyULHDZmV5K4xySsDRKWOruanGtjLJXFEmwaIbDLX0hIPBUQPVFVkQkDoUNfSoDgQGKPekoxeGzA4DUvnn4bxzcZrtJyipKfPNy5w+9lnXwgqsiyHNeSVpemw4bWb9psYeq//uQZBoABQt4yMVxYAIAAAkQoAAAHvYpL5m6AAgAACXDAAAAD59jblTirQe9upFsmZbpMudy7Lz1X1DYsxOOSWpfPqNX2WqktK0DMvuGwlbNj44TleLPQ+Gsfb+GOWOKJoIrWb3cIMeeON6lz2umTqMXV8Mj30yWPpjoSa9ujK8SyeJP5y5mOW1D6hvLepeveEAEDo0mgCRClOEgANv3B9a6fikgUSu/DmAMATrGx7nng5p5iimPNZsfQLYB2sDLIkzRKZOHGAaUyDcpFBSLG9MCQALgAIgQs2YunOszLSAyQYPVC2YdGGeHD2dTdJk1pAHGAWDjnkcLKFymS3RQZTInzySoBwMG0QueC3gMsCEYxUqlrcxK6k1LQQcsmyYeQPdC2YfuGPASCBkcVMQQqpVJshui1tkXQJQV0OXGAZMXSOEEBRirXbVRQW7ugq7IM7rPWSZyDlM3IuNEkxzCOJ0ny2ThNkyRai1b6ev//3dzNGzNb//4uAvHT5sURcZCFcuKLhOFs8mLAAEAt4UWAAIABAAAAAB4qbHo0tIjVkUU//uQZAwABfSFz3ZqQAAAAAngwAAAE1HjMp2qAAAAACZDgAAAD5UkTE1UgZEUExqYynN1qZvqIOREEFmBcJQkwdxiFtw0qEOkGYfRDifBui9MQg4QAHAqWtAWHoCxu1Yf4VfWLPIM2mHDFsbQEVGwyqQoQcwnfHeIkNt9YnkiaS1oizycqJrx4KOQjahZxWbcZgztj2c49nKmkId44S71j0c8eV9yDK6uPRzx5X18eDvjvQ6yKo9ZSS6l//8elePK/Lf//IInrOF/FvDoADYAGBMGb7FtErm5MXMlmPAJQVgWta7Zx2go+8xJ0UiCb8LHHdftWyLJE0QIAIsI+UbXu67dZMjmgDGCGl1H+vpF4NSDckSIkk7Vd+sxEhBQMRU8j/12UIRhzSaUdQ+rQU5kGeFxm+hb1oh6pWWmv3uvmReDl0UnvtapVaIzo1jZbf/pD6ElLqSX+rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");
  44.  
  45. _init();
  46.  
  47. /**
  48. * Initialise le script
  49. **/
  50. function _init()
  51. {
  52. // On charge le css
  53. chargerCSS();
  54. var url;
  55.  
  56. // Chargement des données si elles existent
  57. if(localStorage.seances)
  58. {
  59. seances = JSON.parse(localStorage.seances);
  60. console.log(seances);
  61. url = seances.topicUrl;
  62.  
  63. if(seances.savelink.length && (self.location.href).match(/post[0-9]+\.html\#p[0-9]+/) !== null)
  64. {
  65. for(i = 0; i < seances.savelink.length; i++)
  66. {
  67. last = seances.seances[seances.savelink[i]].historique.length - 1;
  68. seances.seances[seances.savelink[i]].historique[last].lien = self.location.href;
  69. }
  70. seances.savelink = [];
  71. sauvegarder(seances);
  72. }
  73. }
  74. if(!url || url == "undefined")
  75. {
  76. // Dans le cas, où l'utilisateur lance le script pour la première fois, on lui demande l'url de son carnet
  77. var urlCarnet = prompt("Script pour vos séances lafay\nVeuillez entrer l'url de votre carnet :", "ex : http://www.musculaction.com/forum/stevens-pdm-23-ans-1m82-71-3kg-nv4-fullbody-p156-t124199.html");
  78. // On récupère l'id du topic depuis l'url
  79. if(/http:\/\/www\.musculaction\.com\/forum\/[a-zA-Z0-9_-]*t(opic)?([0-9]+)\.html/.test(urlCarnet))
  80. {
  81. var idTopic = RegExp.$2;
  82.  
  83. // On récupère l'id du forum en demandant à l'utilisateur d'où provient son carnet
  84. var reForum = prompt("Avez-vous un carnet femme ou homme ? (répondre 'h' pour homme, 'f' pour femme)");
  85. var idForum = reForum == 'h' ? 29 : 33;
  86.  
  87. seances = {'savelink':[], 'topicUrl' : 'http://www.musculaction.com/forum/posting.php?mode=reply&f='+idForum+'&t='+idTopic, 'seances' : []};
  88. sauvegarder(seances);
  89.  
  90. url = 'http://www.musculaction.com/forum/posting.php?mode=reply&f='+idForum+'&t='+idTopic;
  91. var oldSeance = JSON.parse(localStorage.seance);
  92. console.log(oldSeance);
  93. // Récupération des anciennes données
  94. if(oldSeance)
  95. {
  96. var nb = oldSeance.length;
  97. for(i = 0; i < nb; i++)
  98. {
  99. console.log(oldSeance[i]);
  100. if(oldSeance[i].valide == '1')
  101. {
  102. var tmp;
  103. // S'il s'agit d'un bbcode perso
  104. if(oldSeance[i].bbcode !== '')
  105. {
  106. tmp = {'general':{},'bbcode':oldSeance[i].bbcode,'historique':[]};
  107. tmp.general = {
  108. 'titre' : oldSeance[i].nom,
  109. 'bbcode' : 1
  110. };
  111. }
  112. else
  113. {
  114. tmp = {'general' : {}, 'echauffement' : [], 'exercices' : [], 'historique' : []};
  115.  
  116. // Configuration générale
  117. tmp.general = {
  118. 'titre' : oldSeance[i].nom,
  119. 'nbSeances' : oldSeance[i].numero,
  120. 'nbEchauffement' : oldSeance[i].echauffement.length,
  121. 'nbExercices' : oldSeance[i].exercices.length,
  122. 'bbcode' : 0
  123. };
  124. // Echauffement
  125. for(j = 0; j < oldSeance[i].echauffement.length; j++)
  126. {
  127. value = oldSeance[i].echauffement[j];
  128.  
  129. // S'il y a moins d'exercice que prévu, on coupe net la boucle
  130. if(value === '')
  131. break;
  132.  
  133. tmp.echauffement.push(value);
  134. }
  135.  
  136. // Exercices
  137. tmp.exercices = [];
  138. for(j = 0; j < oldSeance[i].exercices.length; j++)
  139. {
  140. value = {
  141. 'nom' : oldSeance[i].exercices[j].nom,
  142. 'nombbcode' : oldSeance[i].exercices[j].nombbcode,
  143. 'nbSeries' : parseInt(oldSeance[i].exercices[j].nb_series),
  144. 'nbRep' : parseInt(oldSeance[i].exercices[j].valeur[0]),
  145. 'max' : (parseInt(oldSeance[i].exercices[j].valeur[0]) * parseInt(oldSeance[i].exercices[j].nb_series)),
  146. 'ris' : 0,
  147. 'repos' : 0,
  148. 'variante' : ''
  149. };
  150.  
  151. tmp.exercices.push(value);
  152. }
  153. }
  154. console.log(tmp);
  155. // On sauvegarde la séance type
  156. seances.seances[i] = tmp;
  157. }
  158. }
  159. if(seances.seances.length)
  160. {
  161. console.log(seances);
  162. sauvegarder(seances);
  163. alert('Vos anciennes séances ont été importées. Il est cependant nécessaire de les modifier pour le bon fonctionnement de cette application.');
  164. }
  165. localStorage.removeItem("seance");
  166. }
  167. }
  168. else
  169. {
  170. alert("L'url fournit est incorrect. Si après modification, il y a toujours un problème, veuillez me contacter sur le topic.");
  171. return;
  172. }
  173. }
  174.  
  175. if(url == document.location.href)
  176. {
  177. chargerBoutonRepondre();
  178. }
  179.  
  180. // Ferme dès qu'on appuie sur 'Echap'
  181. document.body.addEventListener('keyup', function (e) {
  182. if (e.keyCode == 27)
  183. {
  184. quitterApplication();
  185. }
  186. else if(e.keyCode == 38)
  187. {
  188. // Debut decompte
  189. if(!decompteEnCours)
  190. {
  191. var input = document.getElementById('decompteC');
  192. var i = parseInt(input.getAttribute('getI')), j = parseInt(input.getAttribute('getJ')), id = parseInt(input.getAttribute('getID'));
  193. decompte(id, i, j);
  194. }
  195. }
  196. else if(e.keyCode == 40)
  197. {
  198. // Reset decompte
  199. if(decompteEnCours)
  200. {
  201. var input = document.getElementById('decompteC');
  202. var i = parseInt(input.getAttribute('getI')), j = parseInt(input.getAttribute('getJ')), id = parseInt(input.getAttribute('getID'));
  203. resetDecompte(id, i, j);
  204. }
  205. }
  206. else if(e.keyCode == 36)
  207. {
  208. // Debut chrono
  209. play();
  210. }
  211. else if(e.keyCode == 35)
  212. {
  213. // Fin chrono
  214. pause();
  215. }
  216. }, false);
  217. }
  218.  
  219. /**
  220. * Quitte l'application et réinitialise les valeurs par defaut
  221. **/
  222. function quitterApplication()
  223. {
  224. document.body.removeChild(document.getElementById('boxSeance'));
  225. document.body.removeChild(document.getElementById('chrono'));
  226. document.body.removeChild(document.getElementById('decompte'));
  227.  
  228. chargerToutesLesDiv();
  229. bbcode = 0;
  230. nbEchauffement = 5;
  231. soixDix = false;
  232. start = 0;
  233. end = 0;
  234. timer = false;
  235. timerDecompte = false;
  236. totaux = [];
  237. }
  238.  
  239. /**
  240. * Charge les divers règles CSS
  241. **/
  242. function chargerCSS()
  243. {
  244. var css = "<style type='text/css'>\n";
  245. css += ".bouton{padding: 3px; text-align: center; height: 30px; cursor: pointer; border: none;}\n";
  246. css += ".bouton:hover{text-decoration: none;}\n";
  247. css += ".add{background: #6899ef; color: #dedede;}\n";
  248. css += ".add:hover{background: #4e83b2; color: #dedede;}\n";
  249. css += ".go{background: #61d13f; color: #dedede;}\n";
  250. css += ".go:hover{background: #419f24; color: #dedede;}\n";
  251. css += ".edit{background: #ccab0f; color: #dedede;}\n";
  252. css += ".edit:hover{background: #9c830a; color: #dedede;}\n";
  253. css += ".delete{background: #e14848; color: #dedede;}\n";
  254. css += ".delete:hover{background: #ae3131; color: #dedede;}\n";
  255. css += "#boxSeance .table{border-collapse: collapse; border-color: #1c1c1c}\n";
  256. css += "#boxSeance .table td{width: 100px; text-align: center;}\n";
  257. css += "#boxSeance .table td .bouton{width : 100px;}\n";
  258. css += "#boxSeance{position: absolute; z-index: 2000; padding: 10px; padding-top: 0; background: #dedede; color: #1c1c1c; border: 1px solid #1c1c1c; box-shadow: 0 0 1px #1c1c1c;}\n";
  259. css += "#boxSeance input[type=text]{height: 25px; border: none; width : 180px;}\n";
  260. css += "#boxSeance td{width: 200px;}\n";
  261. css += ".changerCouleur{cursor: pointer; margin-right: 2px; display: inline-block; width: 10px; height: 10px; border: 1px solid #1c1c1c;}\n";
  262. css += "#boxSeance input.serie{width: 33px; border: 1px solid #1c1c1c; color: black;}\n";
  263. css += "#boxSeance table.exercices td{width: 45px;}\n";
  264. css += "#boxSeance table{margin-top: 10px;}\n";
  265. css += "#boxSeance input.ressenti{width: 420px;}\n";
  266. css += "#decompte, #chrono{text-align: center; position: fixed; border: 1px solid #dedede; background: #1c1c1c; font-size: 30px; color: #dedede; top: 30px; right: 30px;}\n";
  267. css += "#decompte{top: 150px;}\n";
  268. css += "#decompte .button, #chrono .button{width: 70px; height: 25px; font-size: 15px; border: none; text-align: center;}\n";
  269. css += "#histo td{width : auto; text-align: center}\n";
  270. css += "#histo th{padding: 5px;}\n";
  271. css += "</style>";
  272.  
  273. document.body.innerHTML += css;
  274. }
  275.  
  276. /**
  277. * Affiche le bouton "Gestion séance"
  278. **/
  279. function chargerBoutonRepondre()
  280. {
  281. var title_input = document.getElementById('subject').parentNode;
  282. title_input.innerHTML += '<a title="Ajouter une séance" onclick="afficherListeSeance();" class="bouton add">Générer une séance</a>';
  283.  
  284. chargerToutesLesDiv();
  285. }
  286.  
  287. /**
  288. * Ajoutes les div que l'on va utiliser
  289. **/
  290. function chargerToutesLesDiv()
  291. {
  292. var html = '<div id="boxSeance" style="display:none">';
  293. html += '<div id="listeSeances"></div>';
  294. html += '<div id="etape1"></div>';
  295. html += '<div id="etape2"></div>';
  296. html += '<div id="etape3"></div>';
  297. html += '<div id="historique"></div>';
  298. html += '<div id="seance"></div>';
  299. html += '</div>';
  300. html += '<div id="chrono"></div>';
  301. html += '<div id="decompte"></div>';
  302. //html += '<embed src="http://www.soundjay.com/button/beep-07.wav" autostart="false" width="0" height="0" id="bip" enablejavascript="true">';
  303. document.body.innerHTML += html;
  304. }
  305.  
  306. /**
  307. * Enregistre le tableau fournit en paramètre dans le locale localStorage
  308. * @param Array tableau contenant toutes les données
  309. **/
  310. function sauvegarder(data)
  311. {
  312. localStorage.seances = JSON.stringify(data);
  313. }
  314.  
  315. /**
  316. * Affiche la liste des séances déjà enregistrée
  317. **/
  318. unsafeWindow.afficherListeSeance = function()
  319. {
  320. var html = '';
  321. html += '<h3>Liste des séances</h3>';
  322. if((nb = seances.seances.length))
  323. {
  324. html += "<table BORDER class='table'>";
  325. for(i = 0; i < nb; i++)
  326. {
  327. html += '<tr>';
  328. html += '<td>' + (seances.seances[i].general.titre) + '</td>';
  329. if(seances.seances[i].general.bbcode == 1)
  330. {
  331. html += '<td></td>';
  332. html += '<td><input class="bouton go" onClick="posterSeance('+i+');" value="Poster la séance" /></td>';
  333. html += '<td><input class="bouton edit" onClick="modifierSeance('+i+');" value="Modifier la séance" /></td>';
  334. html += '<td><input class="bouton delete" onClick="supprimerSeance('+i+');" value="Supprimer" /></td>';
  335. }
  336. else
  337. {
  338. html += '<td><input class="bouton go" onClick="lancerSeance('+i+');" value="Lancer la séance" /></td>';
  339. html += '<td><input class="bouton edit" onClick="modifierSeance('+i+');" value="Modifier la séance" /></td>';
  340. html += '<td><input class="bouton add" onClick="historiqueSeance('+i+');" value="Historique" /></td>';
  341. html += '<td><input class="bouton delete" onClick="supprimerSeance('+i+');" value="Supprimer" /></td>';
  342. }
  343. html += '</tr>';
  344. }
  345. html += "</table>";
  346. }
  347.  
  348. // Ajout du bouton pour créer des séances
  349. html += '<input class="bouton add" onClick="ajouterSeance();" value="Ajouter une séance" />';
  350.  
  351. html += '</div></div>';
  352.  
  353. document.getElementById('listeSeances').innerHTML = html;
  354. afficherDiv('liste');
  355. };
  356.  
  357. function afficherDiv(type)
  358. {
  359. document.getElementById('boxSeance').style.display = '';
  360. document.getElementById('etape1').style.display = 'none';
  361. document.getElementById('etape2').style.display = 'none';
  362. document.getElementById('etape3').style.display = 'none';
  363. document.getElementById('listeSeances').style.display = 'none';
  364. document.getElementById('historique').style.display = 'none';
  365. document.getElementById('seance').style.display = 'none';
  366. switch(type)
  367. {
  368. case 'liste' :
  369. document.getElementById('listeSeances').style.display = '';
  370. break;
  371. case 'etape1' :
  372. document.getElementById('etape1').style.display = '';
  373. break;
  374. case 'etape2' :
  375. document.getElementById('etape2').style.display = '';
  376. break;
  377. case 'etape3' :
  378. document.getElementById('etape3').style.display = '';
  379. break;
  380. case 'historique':
  381. document.getElementById('historique').style.display = '';
  382. break;
  383. case 'seance':
  384. document.getElementById('seance').style.display = '';
  385. break;
  386. }
  387. centrerEl(document.getElementById('boxSeance'));
  388. }
  389.  
  390. /**
  391. * Affiche la boite de dialogue permettant de supprimer la séance demandée
  392. **/
  393. unsafeWindow.supprimerSeance = function(id)
  394. {
  395. if(confirm("Etes-vous sur de vouloir supprimer cette séance ?"))
  396. {
  397. seances.seances.splice(id, 1);
  398. sauvegarder(seances);
  399. quitterApplication();
  400. }
  401. };
  402.  
  403. /**
  404. * Affiche la boite de dialogue permettant de modifier la séance demandée
  405. **/
  406. unsafeWindow.modifierSeance = function(id)
  407. {
  408. document.getElementById('listeSeances').style.display = 'none';
  409. etape1(id);
  410. };
  411.  
  412. /**
  413. * Affiche la boite de dialogue permettant d'ajouter des séances facilement
  414. **/
  415. unsafeWindow.ajouterSeance = function()
  416. {
  417. document.getElementById('listeSeances').style.display = 'none';
  418. etape1(null);
  419. };
  420.  
  421. /**
  422. * Première étape d'une séance
  423. **/
  424. unsafeWindow.etape1 = function(id)
  425. {
  426. if(document.getElementById('etape1').innerHTML === '')
  427. {
  428. var html = '';
  429. var value = '';
  430. var seance;
  431.  
  432. // Ajout du titre
  433. if(id === null)
  434. {
  435. html += "<h3>Création d'une nouvelle séance type</h3>";
  436. }
  437. else
  438. {
  439. seance = seances.seances[id].general;
  440. html += "<h3>Modification de " + seance.titre + "</h3>";
  441. }
  442.  
  443. // Ajout des inputs
  444. html += '<table>';
  445. html += '<tr><td><label for="titreSeance">Titre de la séance</label></td>';
  446. value = id === null ? '' : seance.titre;
  447. html += '<td><input type="text" id="titreSeance" value="'+value+'" /></td></tr>';
  448. html += '<tr><td><label for="numSeance">Numéro de la première séance générée par le script <i>(ex : séance n°12)</i></label></td>';
  449. value = id === null ? '' : seance.nbSeances;
  450. html += '<td><input type="text" id="numSeance" value="'+value+'" /></td></tr>';
  451. html += '<tr class="bbcodehide"><td><label for="nbExos">Nombre d\'exercices</label></td>';
  452. value = id === null ? '' : seance.nbExercices;
  453. html += '<td><input type="text" id="nbExos" value="'+value+'" /></td></tr>';
  454. html += '<tr class="bbcodehide"><td><label for="nbEchauffement">Nombre d\'exercices d\'échauffement</label></td>';
  455. value = id === null ? '' : seance.nbEchauffement;
  456. html += '<td><input type="text" id="nbEchauffement" value="'+value+'" /></td></tr>';
  457.  
  458. // Gestion du bbcode perso
  459. html += '<tr><td><label for="bbcodePerso">BBcode personnalisé</label></td>';
  460. html += '<td><input type="checkbox" id="bbcodePerso" onClick="bbcodePerso();" /></td></tr>';
  461.  
  462. // Ajout du bouton pour changer d'étape
  463. html += '<tr><td>&nbsp;</td><td><input class="bouton add" onClick="etape2('+id+');" value="Etape suivante" /></td></tr>';
  464. html += '<table>';
  465.  
  466. document.getElementById('etape1').innerHTML = html;
  467. }
  468. afficherDiv('etape1');
  469. };
  470.  
  471. /**
  472. * Deuxième étape d'une séance
  473. **/
  474. unsafeWindow.etape2 = function(id)
  475. {
  476. var value = '';
  477. var tmp_value = document.getElementById('nbEchauffement').value;
  478. if(document.getElementById('etape2').innerHTML === '' || (tmp_value === '' || tmp_value != nbEchauffement))
  479. {
  480. nbEchauffement = (tmp_value === '' ? nbEchauffement : tmp_value);
  481.  
  482. var html = '';
  483. var seance;
  484.  
  485. // Ajout du titre
  486. if(id === null)
  487. {
  488. html += "<h3>Création d'une nouvelle séance type"+(bbcode ? '' : '- Echauffement')+"</h3>";
  489. }
  490. else
  491. {
  492. seance = seances.seances[id];
  493. html += "<h3>Modification de " + seance.general.titre +(bbcode ? '' : '- Echauffement')+"</h3>";
  494. }
  495.  
  496. // Ajout des inputs
  497. if(bbcode)
  498. {
  499. value = document.getElementById('bbcodeValue') ? document.getElementById('bbcodeValue').value : 'Veuillez entrer votre bbcode personnalisé.';
  500. html += '<textarea id="bbcodeValue">'+value+'</textarea>';
  501. html += '<tr><td><input class="bouton add" onClick="etape1('+id+');" value="Etape précédente" /></td><td><input class="bouton add" onClick="enregistrer('+id+');" value="Enregistrer la séance" /></td></tr>';
  502. html += '<table>';
  503. }
  504. else
  505. {
  506. html += '<table>';
  507. for(i = 0; i < nbEchauffement; i++)
  508. {
  509. value = document.getElementById('echauffement'+(i+1)) ? document.getElementById('echauffement'+(i+1)).value : '';
  510. value = value === '' && id !== null ? seance.echauffement[i] : '';
  511. html += '<tr><td><label for="echauffement'+(i+1)+'">Echauffement '+(i+1)+'</label></td>';
  512. html += '<td><input type="text" id="echauffement'+(i+1)+'" value="'+value+'" /></td></tr>';
  513. }
  514. // Ajout du bouton pour changer d'étape
  515. html += '<tr><td><input class="bouton add" onClick="etape1('+id+');" value="Etape précédente" /></td><td><input class="bouton add" onClick="etape3('+id+');" value="Etape suivante" /></td></tr>';
  516. html += '<table>';
  517. }
  518. document.getElementById('etape2').innerHTML = html;
  519. }
  520. afficherDiv('etape2');
  521. };
  522.  
  523. /**
  524. * Deuxième étape d'une séance
  525. **/
  526. unsafeWindow.etape3 = function(id)
  527. {
  528. var value = '';
  529. var nbExercices = document.getElementById('nbExos').value;
  530.  
  531. if(nbExercices === '')
  532. {
  533. alert("Veuillez préciser un nombre d'exercices.");
  534. etape1(id);
  535. return;
  536. }
  537.  
  538. var html = '';
  539. var seance;
  540.  
  541. // Ajout du titre
  542. if(id === null)
  543. {
  544. html += "<h3>Création d'une nouvelle séance type - Exercices</h3>";
  545. }
  546. else
  547. {
  548. seance = seances.seances[id];
  549. html += "<h3>Modification de " + seance.general.titre + '- Exercices</h3>';
  550. }
  551.  
  552. // Ajout des inputs
  553. for(i = 0; i < nbExercices; i++)
  554. {
  555. html += '<table>';
  556. html += '<tr><td>Exercice '+(i+1)+'</td><td>&nbsp;</td></tr>';
  557. // Nom de l'exercice
  558. value = document.getElementById('exo'+(i+1)+'nom') ? document.getElementById('exo'+(i+1)+'nom').value : '';
  559. value = value === '' && id !== null ? seance.exercices[i].nom : '';
  560. html += '<tr><td><label for="exo'+(i+1)+'nom">Nom</label></td>';
  561. html += '<td><input type="text" id="exo'+(i+1)+'nom" value="'+value+'" /></td></tr>';
  562. // Nom à afficher sur le post
  563. value = document.getElementById('exo'+(i+1)+'nomBBcode') ? document.getElementById('exo'+(i+1)+'nomBBcode').value : '';
  564. value = value === '' && id !== null ? seance.exercices[i].nombbcode : '';
  565. html += '<tr><td><label for="exo'+(i+1)+'nomBBcode">Nom à afficher sur le post</label></td>';
  566. html += '<td><input type="text" id="exo'+(i+1)+'nomBBcode" value="'+value+'" /></td></tr>';
  567. // Variante ou delta de l'exercice
  568. value = document.getElementById('exo'+(i+1)+'variante') ? document.getElementById('exo'+(i+1)+'variante').value : '';
  569. value = value === '' && id !== null ? seance.exercices[i].variante : '';
  570. html += '<tr><td><label for="exo'+(i+1)+'variante">Variante ou delta <i>(laissez vide si besoin)</i></label></td>';
  571. html += '<td><input type="text" id="exo'+(i+1)+'variante" value="'+value+'" /></td></tr>';
  572. // Nombre de séries
  573. value = document.getElementById('exo'+(i+1)+'nbSeries') ? document.getElementById('exo'+(i+1)+'nbSeries').value : '';
  574. value = value === '' && id !== null ? seance.exercices[i].nbSeries : '';
  575. html += '<tr><td><label for="exo'+(i+1)+'nbSeries">Nombre de séries</label></td>';
  576. html += '<td><input type="text" id="exo'+(i+1)+'nbSeries" value="'+value+'" /></td></tr>';
  577. // Nombre de rep minimum
  578. value = document.getElementById('exo'+(i+1)+'nbRep') ? document.getElementById('exo'+(i+1)+'nbRep').value : '';
  579. value = value === '' && id !== null ? seance.exercices[i].nbRep : '';
  580. html += '<tr><td><label for="exo'+(i+1)+'nbRep">Mode minimum</label></td>';
  581. html += '<td><input type="text" id="exo'+(i+1)+'nbRep" value="'+value+'" /></td></tr>';
  582. // Nombre de rep maximum
  583. value = document.getElementById('exo'+(i+1)+'nbRepMax') ? document.getElementById('exo'+(i+1)+'nbRepMax').value : '';
  584. value = value === '' && id !== null ? seance.exercices[i].max : '';
  585. html += '<tr><td><label for="exo'+(i+1)+'nbRepMax">Maximum de répétitions atteintes</label></td>';
  586. html += '<td><input type="text" id="exo'+(i+1)+'nbRepMax" value="'+value+'" /></td></tr>';
  587. // Repos intersérie
  588. value = document.getElementById('exo'+(i+1)+'ris') ? document.getElementById('exo'+(i+1)+'ris').value : '';
  589. value = value === '' && id !== null ? seance.exercices[i].ris : '';
  590. html += '<tr><td><label for="exo'+(i+1)+'ris">Repos intersérie <i>(en secondes)</i></label></td>';
  591. html += '<td><input type="text" id="exo'+(i+1)+'ris" value="'+value+'" /></td></tr>';
  592. // Repos à la fin de l'exercice
  593. value = document.getElementById('exo'+(i+1)+'repos') ? document.getElementById('exo'+(i+1)+'repos').value : '';
  594. value = value === '' && id !== null ? seance.exercices[i].repos : '';
  595. html += '<tr><td><label for="exo'+(i+1)+'repos">Repos à la fin de l\'exercice <i>(en secondes)</i></label></td>';
  596. html += '<td><input type="text" id="exo'+(i+1)+'repos" value="'+value+'" /></td></tr>';
  597. html += '</table>';
  598. }
  599. // Ajout du bouton pour changer d'étape
  600. html += '<table><tr><td><input class="bouton add" onClick="etape2('+id+');" value="Etape précédente" /></td><td><input class="bouton add" onClick="enregistrer('+id+');" value="Enregistrer la séance" /></td></tr></table>';
  601.  
  602. document.getElementById('etape3').innerHTML = html;
  603. afficherDiv('etape3');
  604. };
  605.  
  606. unsafeWindow.enregistrer = function(id)
  607. {
  608. var tmp;
  609. // S'il s'agit d'un bbcode perso
  610. if(bbcode)
  611. {
  612. tmp = {'general':{},'bbcode':document.getElementById('bbcodeValue').value,'historique':[]};
  613. tmp.general = {
  614. 'titre' : document.getElementById('titreSeance').value,
  615. 'bbcode' : 1
  616. };
  617. }
  618. else
  619. {
  620. tmp = {'general' : {}, 'echauffement' : [], 'exercices' : [], 'historique' : []};
  621. var nbExercices = document.getElementById('nbExos').value;
  622.  
  623. // Configuration générale
  624. tmp.general = {
  625. 'titre' : document.getElementById('titreSeance').value,
  626. 'nbSeances' : document.getElementById('numSeance').value,
  627. 'nbEchauffement' : nbEchauffement,
  628. 'nbExercices' : nbExercices,
  629. 'bbcode' : 0
  630. };
  631. // Echauffement
  632. for(i = 0; i < nbEchauffement; i++)
  633. {
  634. value = document.getElementById('echauffement'+(i+1)).value;
  635.  
  636. // S'il y a moins d'exercice que prévu, on coupe net la boucle
  637. if(value === '')
  638. break;
  639.  
  640. tmp.echauffement.push(value);
  641. }
  642.  
  643. // Exercices
  644. tmp.exercices = [];
  645. for(i = 0; i < nbExercices; i++)
  646. {
  647. // S'il y a moins d'exercice que prévu, on coupe net la boucle
  648. if(document.getElementById('exo'+(i+1)+'nom').value === '')
  649. break;
  650.  
  651. value = {
  652. 'nom' : document.getElementById('exo'+(i+1)+'nom').value,
  653. 'nombbcode' : document.getElementById('exo'+(i+1)+'nomBBcode').value,
  654. 'nbSeries' : parseInt(document.getElementById('exo'+(i+1)+'nbSeries').value),
  655. 'nbRep' : parseInt(document.getElementById('exo'+(i+1)+'nbRep').value),
  656. 'max' : parseInt(document.getElementById('exo'+(i+1)+'nbRepMax').value),
  657. 'ris' : parseInt(document.getElementById('exo'+(i+1)+'ris').value),
  658. 'repos' : parseInt(document.getElementById('exo'+(i+1)+'repos').value),
  659. 'variante' : document.getElementById('exo'+(i+1)+'variante').value
  660. };
  661.  
  662. tmp.exercices.push(value);
  663. }
  664. }
  665. // On sauvegarde la séance type
  666. if(id === null)
  667. id = seances.seances.length;
  668.  
  669. seances.seances[id] = tmp;
  670. sauvegarder(seances);
  671.  
  672. quitterApplication();
  673. alert("Votre séance type a bien été "+(id == seances.seances.length ? 'ajoutée.' : 'modifiée.'));
  674. };
  675.  
  676. /**
  677. * Définit si la séance aura un bbcode perso ou non
  678. **/
  679. unsafeWindow.bbcodePerso = function()
  680. {
  681. // On cache ou affiche ce qui doit l'etre
  682. var bbcodeHideDiv = document.getElementsByClassName('bbcodehide');
  683. var nb = bbcodeHideDiv.length;
  684. for(i = 0; i < nb; i++)
  685. {
  686. bbcodeHideDiv[i].style.display = (bbcode ? '' : 'none');
  687. }
  688. bbcode = bbcode ? 0 : 1;
  689. };
  690.  
  691. /**
  692. * Affiche l'historique d'une séance
  693. **/
  694. unsafeWindow.historiqueSeance = function(id)
  695. {
  696. var historique = seances.seances[id].historique;
  697. var html = '<h3>Historique de la séance : '+seances.seances[id].general.titre+'</h3>';
  698. if(!historique.length)
  699. {
  700. html += '<p>Vous n\'avez pas encore effectué de séance.</p>';
  701. }
  702. else
  703. {
  704. var d, j, m , a;
  705. var moyenneTxt, totalRep, totalSerie;
  706. html += '<table id="histo">';
  707. html += '<tr>';
  708. html += '<th>Date</th><th>Lien</th><th>Séance n°</th><th>Gain total de répétitions</th><th>Durée de la séance</th><th>&nbsp;</th><th>&nbsp;</th>';
  709. html += '</tr>';
  710. for(i = 0; i < historique.length; i++)
  711. {
  712. totalRep = 0;
  713. totalSerie = 0;
  714.  
  715. html += '<tr>';
  716. // date
  717. d = new Date(historique[i].date);
  718. j = d.getDate();
  719. m = d.getMonth()+1;
  720. a = d.getFullYear();
  721.  
  722. j = j < 10 ? '0'+j : j;
  723. m = m < 10 ? '0'+m : m;
  724.  
  725. html += '<td>'+j+'/'+m+'/'+a+'</td>';
  726. // Lien de la séance
  727. html += '<td>'+(historique[i].lien ? '<a href="'+historique[i].lien+'">Lien</a>' : 'Séance non postée.')+'</td>';
  728. // n° de séance
  729. html += '<td>N°'+(i + parseInt(seances.seances[id].general.nbSeances))+'</td>';
  730. // gain moyen
  731. for(k = 0; k < seances.seances[id].general.nbExercices; k++)
  732. {
  733. for(l = 0; l < seances.seances[id].exercices[k].nbSeries; l++)
  734. {
  735. if(i == 0)
  736. totalRep += (historique[i].exercices[k][l] - seances.seances[id].exercices[k].nbRep);
  737. else
  738. totalRep += (historique[i].exercices[k][l] - historique[(i-1)].exercices[k][l]);
  739. }
  740. }
  741. moyenneTxt = (totalRep >= 0 ? '<span style="color:#61d13f">+': '<span style="color:#e14848">');
  742. moyenneTxt += totalRep+'</span>';
  743. html += '<td>'+moyenneTxt+'</td>';
  744. // durée de la séance
  745. html += '<td>'+historique[i].duree+'</td>';
  746. // details
  747. html += '<td><input class="bouton add" onclick="detailsHistorique('+id+', '+i+');" value="Détails" /></td>';
  748. // supprimer seance
  749. html += '<td><input class="bouton delete" onclick="supprimerHistorique('+id+', '+i+');" value="Supprimer séance" /></td>';
  750. html += '</tr>';
  751. }
  752. html += '</table>';
  753. }
  754.  
  755. document.getElementById('historique').innerHTML = html;
  756. afficherDiv('historique');
  757. };
  758.  
  759. /**
  760. * Permet de voir la séance en détail
  761. * @param int id l'id de la séance
  762. * @param int i l'id de l'exercice
  763. **/
  764. unsafeWindow.detailsHistorique = function(id, i)
  765. {
  766. var historique = seances.seances[id].historique[i];
  767. var numSeance = parseInt(seances.seances[id].general.nbSeances) + i;
  768. var html = '<h3>Historique de la séance : '+seances.seances[id].general.titre+' n°'+numSeance+'</h3>';
  769. var variante, total, totalPrec, mode;
  770.  
  771. html += (historique.lien ? '<a href="'+historique.lien+'">Lien vers la séance</a>' : 'Séance non postée.')+'<br />';
  772.  
  773. // On parcourt les exercices
  774. for(k = 0; k < seances.seances[id].general.nbExercices; k++)
  775. {
  776. // On affiche le nom avec la variante
  777. variante = seances.seances[id].exercices[k].variante === '' ? '' : ' <i>('+seances.seances[id].exercices[k].variante+')</i>';
  778. html += '<u>'+seances.seances[id].exercices[k].nom+variante+'</u> :';
  779.  
  780. total = 0; totalPrec = 0;
  781. // Affichage des séries
  782. for(l = 0; l < seances.seances[id].exercices[k].nbSeries; l++)
  783. {
  784. html += ' ' + historique.exercices[k][l];
  785. total += historique.exercices[k][l];
  786. totalPrec += (i == 0 ? seances.seances[id].exercices[k].nbRep : seances.seances[id].historique[(i-1)].exercices[k][l]);
  787. }
  788. // Affichage du total
  789. if(i != 0)
  790. {
  791. if(total - totalPrec > 0)
  792. {
  793. html += ' <span style="color:#61d13f">(+'+(total - totalPrec)+')</span>';
  794. }
  795. else if(total - totalPrec < 0)
  796. {
  797. html += ' <span style="color:#e14848">('+(total - totalPrec)+')</span>';
  798. }
  799. else
  800. {
  801. html += ' <span style="color:#6899ef">(=)</span>';
  802. }
  803. }
  804. // Affichage du max
  805. mode = (seances.seances[id].exercices[k].max / seances.seances[id].exercices[k].nbSeries);
  806. mode = (mode | 0) == mode ? mode : mode.toFixed(2);
  807. html += ' <span style="color: #FF0080;">Total : '+total+'</span> | <span style="color: #a1552b;">MAX : '+seances.seances[id].exercices[k].max+' (mode '+mode+')</span>';
  808. // Affichage des éventuelles TAS utilisées
  809. tas = '';
  810. if(historique.tas[k].ASC){
  811. tas += ' ASC ';
  812. }
  813. if(historique.tas[k].MB){
  814. tas += ' MB ';
  815. }
  816. if(historique.tas[k].DB){
  817. tas += ' DB ';
  818. }
  819. if(historique.tas[k].ODT){
  820. tas += ' ODT ';
  821. }
  822. if(historique.tas[k].DM){
  823. tas += ' Demi-mode ';
  824. }
  825. if(historique.tas[k].TM){
  826. tas += ' Tiers-mode ';
  827. }
  828. if(historique.tas[k].P){
  829. tas += ' Punisher ';
  830. }
  831.  
  832. if(tas != ''){
  833. html += '<br /><b>TAS utilisées</b> : '+tas;
  834. }
  835. // Affichage du ressenti
  836. if(historique['ressenti'][k] !== '')
  837. {
  838. html += '<br /><b>Ressenti</b> : '+historique.ressenti[k];
  839. }
  840.  
  841. html += '<br /><br />';
  842. }
  843.  
  844. document.getElementById('historique').innerHTML = html;
  845. afficherDiv('historique');
  846. };
  847.  
  848. /**
  849. * Permet de supprimer une séance d'un historique
  850. * @param int id l'id de la séance
  851. * @param int i l'id de l'exercice
  852. **/
  853. unsafeWindow.supprimerHistorique = function(id, i)
  854. {
  855. if(confirm("Etes-vous sur de vouloir supprimer cette séance ?"))
  856. {
  857. seances.seances[id].historique.splice(i, 1);
  858. sauvegarder(seances);
  859. quitterApplication();
  860. historiqueSeance(id);
  861. }
  862. };
  863.  
  864. /**
  865. * Affiche la séance type, permettant ainsi d'indiquer notre ressenti, notre performance
  866. **/
  867. unsafeWindow.lancerSeance = function(id)
  868. {
  869. var exercices = seances.seances[id].exercices;
  870. var echauffement = seances.seances[id].echauffement;
  871. var historique = seances.seances[id].historique;
  872. var numSeance = parseInt(seances.seances[id].general.nbSeances) + historique.length;
  873. var html = '<h3>'+seances.seances[id].general.titre+' n°'+numSeance+'</h3>';
  874. var value = '';
  875. var total, total_prec, mode;
  876.  
  877. // On affiche les exercices d'échauffements
  878. if(seances.seances[id].general.nbEchauffement)
  879. {
  880. html += '<u>Echauffement</u><br />';
  881. for(i = 0; i < seances.seances[id].general.nbEchauffement; i++)
  882. {
  883. html += ' - '+echauffement[i]+ '<br />';
  884. }
  885. }
  886.  
  887. html += '<br />';
  888.  
  889. // On affiche les exercices eux meme
  890. for(i = 0; i < seances.seances[id].general.nbExercices; i++)
  891. {
  892. total = 0;
  893. totaux[i] = 0;
  894.  
  895. html += '<div class="exercice">';
  896. html += '<b>'+exercices[i].nom+'</b> ';
  897. html += '<i><abbr title="Repos Inter-Série">RIS</abbr> : '+exercices[i].ris+'s; Suivi de : '+exercices[i].repos+'s</i>';
  898. mode = (exercices[i].max / exercices[i].nbSeries);
  899. mode = (mode | 0) == mode ? mode : mode.toFixed(2);
  900. html += ' <span style="color: #a1552b;">MAX : '+exercices[i].max+' (mode '+mode+')</span>';
  901.  
  902. // Variante ou delta
  903. value = exercices[i].variante == '' ? 'Variante/delta/poids' : exercices[i].variante;
  904. html += '<br /><input type="text" id="variante_'+i+'" value="'+value+'" onBlur="if(this.value == \'\') this.value = \'Variante/delta/poids\';" onClick="if(this.value == \'Variante/delta/poids\') this.value = \'\';" /><br />';
  905. html += '<table class="exercices">';
  906. // On parcourt les séries
  907. html += '<tr>';
  908. for(j = 0; j < exercices[i].nbSeries; j++)
  909. {
  910. value = historique.length ? historique[(historique.length - 1)].exercices[i][j] + 1 : exercices[i].nbRep;
  911. // Gestion des TAS
  912. if(historique.length && (parseInt(historique[(historique.length - 1)].tas[i].ODT) == 1 || parseInt(historique[(historique.length - 1)].tas[i].DM) == 1 || parseInt(historique[(historique.length - 1)].tas[i].TM) == 1))
  913. {
  914. --value;
  915. totaux[i] += value;
  916. }
  917. else
  918. {
  919. totaux[i] += historique.length ? value - 1: value;
  920. }
  921.  
  922. total += value;
  923. html += '<td><input type="text" style="background: #61d13f;" class="serie serie_'+i+'" id="serie_'+i+'_'+j+'" value="'+value+'" onblur="this.style.border=\'1px solid #1c1c1c\';" onfocus="this.style.border = \'1px solid red\'; changerLienDecompte('+id+','+i+', '+j+');" onkeyup="if(this.value != \'\') modifierTotal('+i+');" /></td>';
  924. }
  925. html += '<td id="total_'+i+'">Total : '+(total)+' <i style="color:#00AA00;">(+'+(total - totaux[i])+')</i></td>';
  926. html += '</tr>';
  927. // On ajoute les selecteurs de difficultés
  928. html += '<tr>';
  929. for(j = 0; j < exercices[i].nbSeries; j++)
  930. {
  931. html += '<td>'+difficulte(i, j)+'</td>';
  932. }
  933. html += '<td>&nbsp;</td>';
  934. html += '</tr>';
  935. html += '</table>';
  936. // On ajoute les ressentis
  937. html += '<input type="text" id="ressenti_'+i+'" class="ressenti" value="Ressenti" onBlur="if(this.value == \'\') this.value = \'Ressenti\';" onClick="if(this.value == \'Ressenti\') this.value = \'\';" /><br />';
  938. // On ajoute les différentes TAS
  939. html += '<br /><label title="Mini-Boucle">MB <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].MB) == 1 ? 'CHECKED' : '')+' id="MB_'+i+'"></label>';
  940. html += ' <label>Ascension <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].ASC) == 1 ? 'CHECKED' : '')+' id="ASC_'+i+'"></label>';
  941. html += ' <label title="Occupation de terrain">ODT <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].ODT) == 1 ? 'CHECKED' : '')+' id="ODT_'+i+'"></label>';
  942. html += ' <label title="Double-Boucle">DB <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].DB) == 1 ? 'CHECKED' : '')+' id="DB_'+i+'"></label>';
  943. html += ' <label>Punisher <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].P) == 1 ? 'CHECKED' : '')+' id="P_'+i+'"></label>';
  944. html += ' <label title="Demi-mode">Demi-mode <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].DM) == 1 ? 'CHECKED' : '')+' id="DM_'+i+'"></label>';
  945. html += ' <label title="Tiers-mode">Tiers-mode <input type="checkbox" '+(historique.length && parseInt(historique[(historique.length - 1)].tas[i].TM) == 1 ? 'CHECKED' : '')+' id="TM_'+i+'"></label><br /><br />';
  946. html += '</div>';
  947. }
  948.  
  949. // Lien youtube pour ajouter des musiques
  950. html += '<div id="youtube">';
  951. html += '<input type="text" id="youtube_0" class="youtube" value="Lien youtube" onBlur="if(this.value == \'\') this.value = \'Lien youtube\';" onClick="if(this.value == \'Lien youtube\') this.value = \'\';" /><br />';
  952. html += '</div>';
  953. html += '<input class="bouton add" onClick="addYoutube();" value="Ajouter un lien" />';
  954.  
  955. // Bouton 70%
  956. html += '<input class="bouton go" onClick="soixanteDix('+id+');" value="70%" />';
  957.  
  958. // Bouton poster la séance
  959. html += '<input class="bouton add" onClick="posterSeance('+id+');" value="Poster la séance" />';
  960.  
  961. document.getElementById('seance').innerHTML = html;
  962. afficherDiv('seance');
  963.  
  964. // On affiche le chrono
  965. lancerChrono(id);
  966.  
  967. };
  968.  
  969. /**
  970. * Génère le bbcode associé à la séance
  971. * @param int id de la séance
  972. **/
  973. unsafeWindow.posterSeance = function(id)
  974. {
  975. // On stop le chrono
  976. pause();
  977.  
  978. var seance = seances.seances[id];
  979. var historyI = seances.seances[id].historique;
  980. var history = historyI.length == 0 ? null : historyI[historyI.length - 1];
  981.  
  982. if(seance.general.bbcode == 1)
  983. {
  984. var bbcode = seance.bbcode;
  985. }
  986. else
  987. {
  988. var ressenti = '';
  989.  
  990. // Date de la séance
  991. var d = new Date();
  992. var date = d.getTime();
  993.  
  994. // Durée de la séance
  995. var time = end - start;
  996. if(time != 0)
  997. {
  998. var H = time > 3600 ? Math.floor(time / 3600) : 0;
  999. var M = time > 60 ? Math.floor(time / 60) : 0;
  1000. var S = time % 60;
  1001. M = M < 10 ? '0' + M : M;
  1002. S = S < 10 ? '0' + S : S;
  1003. duree = H+'h'+M+':'+S;
  1004. }
  1005. else
  1006. duree = '0h00:00';
  1007.  
  1008. var tmp = {'exercices':[],'date':date,'tas':[],'lien':'','ressenti':[],'duree':duree};
  1009.  
  1010. // Numero de seance
  1011. var numSeance = parseInt(seance.general.nbSeances) + historyI.length;
  1012.  
  1013. // Titre
  1014. var bbcode = '[size=200][b][color=#e14848]'+seance.general.titre+(soixDix ? ' 70%' : '')+' n°'+numSeance+'[/color][/b][/size]'+"\n";
  1015. // Echauffement
  1016. if(seance.general.nbEchauffement != 0)
  1017. {
  1018. bbcode += "\n[b]Echauffement[/b]\n";
  1019. for(i = 0; i < seance.general.nbEchauffement; i++)
  1020. {
  1021. bbcode += " - [i]"+seance.echauffement[i]+"[/i]\n";
  1022. }
  1023. }
  1024.  
  1025. // Exercices
  1026. bbcode += "\n[b]Exercices[/b]\n";
  1027. var couleur, serie, valeur, total, texte, tas, ress;
  1028. // Parcourt des exercices
  1029. for(i = 0; i < seance.general.nbExercices; i++)
  1030. {
  1031. // initialisation des TAS
  1032. tmp['tas'][i] = {'DB':0,'MB':0,'ODT':0,'TM':0,'DM':0,'P':0,'ASC':0};
  1033.  
  1034. // Nom de l'exercice
  1035. bbcode += "[color=#0080FF][u]"+seance.exercices[i].nombbcode;
  1036. // Variante/delta
  1037. if(document.getElementById('variante_'+i).value != 'Variante/delta/poids' && document.getElementById('variante_'+i).value != '')
  1038. {
  1039. bbcode += ' [i]('+document.getElementById('variante_'+i).value+')[/i]';
  1040. seances.seances[id].exercices[i].variante = document.getElementById('variante_'+i).value;
  1041. }
  1042. bbcode += '[/u][/color]: ';
  1043.  
  1044. total = 0;
  1045. diff = 0;
  1046.  
  1047. tmp.exercices[i] = [];
  1048.  
  1049. for(j = 0; j < seance.exercices[i].nbSeries; j++)
  1050. {
  1051. couleur = '';
  1052. serie = document.getElementById(i+'_'+j);
  1053. valeur = parseInt(serie.value);
  1054.  
  1055. tmp.exercices[i][j] = valeur;
  1056.  
  1057. diff += (valeur - (history == null ? seance.exercices[i].nbRep : history.exercices[i][j]));
  1058.  
  1059. total += valeur;
  1060.  
  1061. if(rgb2hex(serie.style.backgroundColor) == couleur){
  1062. bbcode += ' '+valeur;
  1063. }else{
  1064. couleur = rgb2hex(serie.style.backgroundColor);
  1065. if(j == 0)
  1066. bbcode += '[color=' + couleur + '][b]' + valeur;
  1067. else
  1068. bbcode += '[/b][/color] [color=' + couleur + '][b]' + valeur;
  1069. }
  1070. }
  1071. bbcode += '[/b][/color]';
  1072. // Affichage des TAS
  1073. tas = '';
  1074. if(document.getElementById('ASC_'+ i).checked){
  1075. tas += ' ASC ';
  1076. tmp.tas[i].ASC = 1;
  1077. }
  1078. if(document.getElementById('MB_'+ i).checked){
  1079. tas += ' MB ';
  1080. tmp.tas[i].MB = 1;
  1081. }
  1082. if(document.getElementById('DB_'+ i).checked){
  1083. tas += ' DB ';
  1084. tmp.tas[i].DB = 1;
  1085. }
  1086. if(document.getElementById('ODT_'+ i).checked){
  1087. tas += ' ODT ';
  1088. tmp.tas[i].ODT = 1;
  1089. }
  1090. if(document.getElementById('DM_'+ i).checked){
  1091. tas += ' Demi-mode ';
  1092. tmp.tas[i].DM = 1;
  1093. }
  1094. if(document.getElementById('TM_'+ i).checked){
  1095. tas += ' Tiers-mode ';
  1096. tmp.tas[i].TM = 1;
  1097. }
  1098. if(document.getElementById('P_'+ i).checked){
  1099. tas += ' Punisher ';
  1100. tmp.tas[i].P = 1;
  1101. }
  1102.  
  1103. if(tas != ''){
  1104. bbcode += ' [i]('+tas+')';
  1105. }
  1106. else
  1107. bbcode += ' [i]';
  1108.  
  1109. // Affichage de la progression
  1110. if(diff > 0)
  1111. {
  1112. couleur = '61d13f';
  1113. texte = '+'+diff ;
  1114. }
  1115. else if(diff < 0){
  1116. couleur = 'e14848';
  1117. texte = diff ;
  1118. }
  1119. else if(diff == 0 && historyI.length)
  1120. {
  1121. couleur = '0080FF';
  1122. texte = '=';
  1123. }
  1124. if(historyI.length)
  1125. bbcode += ' [b][color=#' + couleur + '](' + texte + ')[/color][/b]';
  1126.  
  1127. // Total et max
  1128. if(total > seance.exercices[i].max)
  1129. seances.seances[id].exercices[i].max = total;
  1130.  
  1131. bbcode += ' [color=#FF0080](Total : '+total+'[/color] | [color=#a1552b]MAX : '+seance.exercices[i].max+')[/color][/i]';
  1132.  
  1133. // Saut de ligne (fin de l'exercice)
  1134. bbcode += "\n";
  1135.  
  1136. // On récupère le ressenti
  1137. ress = document.getElementById('ressenti_'+i).value;
  1138. if(ress != '' && ress != 'Ressenti')
  1139. {
  1140. tmp.ressenti[i] = ress;
  1141. ressenti += '\n - [i][color=#0080FF]'+ seance.exercices[i].nombbcode +'[/i][/color] : ' + ress;
  1142. }
  1143. else
  1144. tmp.ressenti[i] = '';
  1145. }
  1146.  
  1147. // Ajout de la musique
  1148. var liens_youtube = document.getElementById('youtube').getElementsByTagName('input');
  1149. var nb = liens_youtube.length;
  1150. var youtubeL = '';
  1151. for(i = 0; i < nb; i++)
  1152. {
  1153. if(liens_youtube[i].value != '' && liens_youtube[i].value != 'Lien youtube')
  1154. youtubeL += '[youtube]'+id_youtube(liens_youtube[i].value)+'[/youtube]'+"\n\n";
  1155. }
  1156. if(youtubeL != '')
  1157. bbcode += "\n[b]Musique écoutée[/b]\n\n"+youtubeL;
  1158.  
  1159. // Ajouts des ressentis
  1160. if(ressenti != ''){
  1161. bbcode += '\n' + '[b]Ressenti[/b]';
  1162. bbcode += ressenti;
  1163. }
  1164.  
  1165. // Ajout de la durée de la séance
  1166. if(time != 0)
  1167. bbcode += "\n\n"+'[u]Durée totale de la séance[/u] : '+duree;
  1168. }
  1169. if(historyI.length != 0)
  1170. bbcode += "\n\n[url="+history.lien+"]Lien vers la dernière séance[/url]";
  1171.  
  1172. // Insertion du bbcode dans la zone de saisie
  1173. document.getElementById('message').innerHTML += bbcode;
  1174.  
  1175. // On demande au navigateur d'enregistrer la prochaine page
  1176. seances.savelink.push(id);
  1177.  
  1178. // On enregistre la séance dans l'historique
  1179. seances.seances[id].historique[historyI.length] = tmp;
  1180. sauvegarder(seances);
  1181. quitterApplication();
  1182. };
  1183.  
  1184. /**
  1185. * Lancer le chrono
  1186. **/
  1187. unsafeWindow.lancerChrono = function(id)
  1188. {
  1189. var d = new Date();
  1190. start = Math.floor(d.getTime() / 1000);
  1191. end = start;
  1192.  
  1193. var html = '<span id="heure">0</span>h<span id="minute">00</span>:<span id="seconde">00</span><br />';
  1194. html += '<input class="button edit" onClick="reset();" value="Reset" />';
  1195. html += '<span id="pause"><input class="button go" onClick="play();" value="Play" /></span>';
  1196. document.getElementById('chrono').innerHTML = html;
  1197.  
  1198. // On gère le futur décompte
  1199. var nbSecondes = parseInt(seances.seances[id].exercices[0].ris) % 60;
  1200. var nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[0].ris) / 60);
  1201. nbMinutes = (nbMinutes < 10 ? '0' + nbMinutes : nbMinutes);
  1202. nbSecondes = (nbSecondes < 10 ? '0' + nbSecondes : nbSecondes);
  1203. html = '<span id="heureD">0</span>h<span id="minuteD">'+nbMinutes+'</span>:<span id="secondeD">'+nbSecondes+'</span><br />';
  1204. html += '<div id="inputs"><input id="decompteC" getI="0" getJ="1" getID="'+id+'" class="button edit" onClick="decompte('+id+',0,1);" value="Decompte" />';
  1205. html += '<input class="button delete" onClick="suivantDecompte('+id+',0,1);" value="Suivant" /></div>';
  1206. document.getElementById('decompte').innerHTML = html;
  1207.  
  1208. // On donne le focus à la case courante
  1209. donnerFocus(0,0);
  1210. };
  1211.  
  1212. /**
  1213. * Change les boutons decompte
  1214. * @param int id l'id de la séance
  1215. * @param int i l'id de l'exercice
  1216. * @param int j l'id de la série
  1217. **/
  1218. unsafeWindow.changerLienDecompte = function(id, i, j)
  1219. {
  1220. var html = '<div id="inputs"><input id="decompteC" getI="'+i+'" getJ="'+j+'" getID="'+id+'" class="button edit" onClick="decompte('+id+','+i+','+j+');" value="Decompte" />';
  1221. html += '<input class="button delete" onClick="suivantDecompte('+id+','+i+','+j+');" value="Suivant" /></div>';
  1222.  
  1223. document.getElementById('inputs').innerHTML = html;
  1224. }
  1225.  
  1226. /**
  1227. * Donne le focus à la case demandée
  1228. * @param int i l'id de l'exercice
  1229. * @param int j l'id de la série
  1230. **/
  1231. function donnerFocus(i, j)
  1232. {
  1233. var series = document.getElementsByClassName('series');
  1234. var nb = series.length;
  1235. for(k = 0; k < nb; k++)
  1236. {
  1237. series[i].style.border = '1px solid #1c1c1c';
  1238. }
  1239. var el = document.getElementById('serie_'+i+'_'+j);
  1240. el.focus();
  1241. el.style.border = '1px solid red';
  1242. }
  1243.  
  1244. /**
  1245. * Lance le décompte
  1246. * @param int id l'id de la séance
  1247. * @param int i l'id de l'exercice
  1248. * @param int j l'id de la série
  1249. **/
  1250. unsafeWindow.decompte = function(id, i, j)
  1251. {
  1252. if(i == seances.seances[id].general.nbExercices)
  1253. return;
  1254.  
  1255. decompteEnCours = true;
  1256.  
  1257. var seconde = document.getElementById('secondeD');
  1258. var minute = document.getElementById('minuteD');
  1259. var nbMinutes = parseInt(minute.innerHTML);
  1260. var nbSecondes = parseInt(seconde.innerHTML);
  1261.  
  1262. if(j != -1 && 60*nbMinutes + nbSecondes == parseInt(seances.seances[id].exercices[i].ris))
  1263. donnerFocus(i, j);
  1264.  
  1265. --nbSecondes;
  1266.  
  1267. // On joue le bip sonore
  1268. if(nbSecondes < 5 && nbSecondes >= 0 && nbMinutes == 0)
  1269. {
  1270. lancerSon();
  1271.  
  1272. if(nbSecondes == 0)
  1273. {
  1274. timerDecompte = setTimeout(function()
  1275. {
  1276. lancerSon();
  1277. }, 200);
  1278. }
  1279. }
  1280.  
  1281. if(nbSecondes == -1)
  1282. {
  1283. nbSecondes = 59;
  1284. if(nbMinutes != 0)
  1285. --nbMinutes;
  1286. else
  1287. {
  1288. decompteEnCours = false;
  1289.  
  1290. // Fin du décompte
  1291. if(j == seances.seances[id].exercices[i].nbSeries -1)
  1292. {
  1293. nbSecondes = parseInt(seances.seances[id].exercices[i].repos) % 60;
  1294. nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[i].repos) / 60);
  1295. j = -1;
  1296. ++i;
  1297. }
  1298. else
  1299. {
  1300. clearTimeout(timerDecompte);
  1301. ++j;
  1302. nbSecondes = parseInt(seances.seances[id].exercices[i].ris) % 60;
  1303. nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[i].ris) / 60);
  1304. }
  1305.  
  1306. // Fin de séance
  1307. if(i == seances.seances[id].general.nbExercices)
  1308. {
  1309. nbMinutes = '0';
  1310. nbSecondes = '0';
  1311. }
  1312. }
  1313. }
  1314. nbMinutes = (nbMinutes < 10 ? '0' + nbMinutes : nbMinutes);
  1315. nbSecondes = (nbSecondes < 10 ? '0' + nbSecondes : nbSecondes);
  1316.  
  1317. minute.innerHTML = nbMinutes;
  1318. seconde.innerHTML = nbSecondes;
  1319.  
  1320. if(!decompteEnCours)
  1321. {
  1322. var html = '<input id="decompteC" getI="'+i+'" getJ="'+j+'" getID="'+id+'" class="button edit" onClick="decompte('+id+','+i+','+j+');" value="Decompte" />';
  1323. }
  1324. else
  1325. {
  1326. var html = '<input class="button edit" id="decompteC" getI="'+i+'" getJ="'+j+'" getID="'+id+'" onClick="resetDecompte('+id+','+i+', '+j+');" value="Reset" />';
  1327. }
  1328. html += '<input class="button delete" onClick="suivantDecompte('+id+', '+i+', '+j+');" value="Suivant" />';
  1329. document.getElementById('inputs').innerHTML = html;
  1330.  
  1331. if(decompteEnCours)
  1332. {
  1333. timerDecompte = setTimeout(function()
  1334. {
  1335. decompte(id, i, j);
  1336. }, 1000);
  1337. }
  1338. }
  1339.  
  1340. /**
  1341. * Lance le bip sonore
  1342. **/
  1343. function lancerSon()
  1344. {
  1345. snd.load();
  1346. snd.play();
  1347. }
  1348.  
  1349. /**
  1350. * Réinitialise le décompte
  1351. * @param int id l'id de la séance
  1352. * @param int i l'id de l'exercice
  1353. **/
  1354. unsafeWindow.resetDecompte = function(id, i, j)
  1355. {
  1356. decompteEnCours = false;
  1357.  
  1358. var seconde = document.getElementById('secondeD');
  1359. var minute = document.getElementById('minuteD');
  1360. var nbSecondes = parseInt(seances.seances[id].exercices[i].ris) % 60;
  1361. var nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[i].ris) / 60);
  1362. nbMinutes = (nbMinutes < 10 ? '0' + nbMinutes : nbMinutes);
  1363. nbSecondes = (nbSecondes < 10 ? '0' + nbSecondes : nbSecondes);
  1364.  
  1365. minute.innerHTML = nbMinutes;
  1366. seconde.innerHTML = nbSecondes;
  1367.  
  1368. clearTimeout(timerDecompte);
  1369.  
  1370. // On donne le focus à la case courante
  1371. donnerFocus(i, j);
  1372.  
  1373. changerLienDecompte(id, i, j);
  1374. };
  1375.  
  1376. /**
  1377. * Change le décompte courant par le suivant
  1378. * @param int id l'id de la séance
  1379. * @param int i l'id de l'exercice
  1380. * @param int j l'id de la série
  1381. **/
  1382. unsafeWindow.suivantDecompte = function(id, i, j)
  1383. {
  1384. if(i == seances.seances[id].general.nbExercices)
  1385. return;
  1386.  
  1387. decompteEnCours = false;
  1388.  
  1389. var seconde = document.getElementById('secondeD');
  1390. var minute = document.getElementById('minuteD');
  1391. ++j;
  1392.  
  1393. if(j >= seances.seances[id].exercices[i]['nbSeries'])
  1394. {
  1395. var nbSecondes = parseInt(seances.seances[id].exercices[i].repos) % 60;
  1396. var nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[i].repos) / 60);
  1397. nbMinutes = (nbMinutes < 10 ? '0' + nbMinutes : nbMinutes);
  1398. nbSecondes = (nbSecondes < 10 ? '0' + nbSecondes : nbSecondes);
  1399. j = -1;
  1400. ++i;
  1401. }
  1402. else
  1403. {
  1404. var nbSecondes = parseInt(seances.seances[id].exercices[i].ris) % 60;
  1405. var nbMinutes = Math.floor(parseInt(seances.seances[id].exercices[i].ris) / 60);
  1406. nbMinutes = (nbMinutes < 10 ? '0' + nbMinutes : nbMinutes);
  1407. nbSecondes = (nbSecondes < 10 ? '0' + nbSecondes : nbSecondes);
  1408.  
  1409. // On donne le focus à la case courante
  1410. donnerFocus(i, j);
  1411. }
  1412. if(i == seances.seances[id].general.nbExercices)
  1413. {
  1414. var nbSecondes = '00';
  1415. var nbMinutes = '00';
  1416. }
  1417.  
  1418. minute.innerHTML = nbMinutes;
  1419. seconde.innerHTML = nbSecondes;
  1420.  
  1421. var html = '<input id="decompteC" getI="'+i+'" getJ="'+j+'" getID="'+id+'" class="button edit" onClick="decompte('+id+','+i+','+j+');" value="Decompte" />';
  1422. html += '<input class="button delete" onClick="suivantDecompte('+id+', '+i+', '+j+');" value="Suivant" />';
  1423. document.getElementById('inputs').innerHTML = html;
  1424.  
  1425. clearTimeout(timerDecompte);
  1426. };
  1427.  
  1428. /**
  1429. * Affiche le chrono
  1430. * @param int courant le nombre de seconde écoulées
  1431. **/
  1432. function afficherChrono(courant)
  1433. {
  1434. var seconde = document.getElementById('seconde');
  1435.  
  1436. if(courant % 60 == 0)
  1437. {
  1438. var minute = document.getElementById('minute');
  1439. nbMinutes = Math.floor(courant / 60);
  1440.  
  1441. if(nbMinutes < 10)
  1442. nbMinutes = '0'+nbMinutes;
  1443.  
  1444. if(nbMinutes == 60)
  1445. {
  1446. nbMinutes = '00';
  1447. var heure = document.getElementById('heure');
  1448. nbHeure = Math.floor(courant / 3600);
  1449. heure.innerHTML = nbHeure;
  1450. }
  1451.  
  1452. minute.innerHTML = nbMinutes;
  1453. }
  1454. nbSecondes = courant % 60;
  1455. if(nbSecondes < 10)
  1456. nbSecondes = '0'+nbSecondes;
  1457.  
  1458. seconde.innerHTML = nbSecondes;
  1459.  
  1460. timer = setTimeout(function()
  1461. {
  1462. afficherChrono(courant + 1);
  1463. }, 1000);
  1464. }
  1465.  
  1466. /**
  1467. * Permet de réinitialiser le chrono
  1468. **/
  1469. unsafeWindow.reset = function()
  1470. {
  1471. clearTimeout(timer);
  1472. document.getElementById('seconde').innerHTML = '00';
  1473. document.getElementById('minute').innerHTML = '00';
  1474. document.getElementById('heure').innerHTML = '0';
  1475.  
  1476. var d = new Date();
  1477. start = Math.floor(d.getTime() / 1000);
  1478. end = start;
  1479.  
  1480. var bouton = document.getElementById('pause').getElementsByTagName('input')[0];
  1481. if(bouton.value == "Stop !")
  1482. {
  1483. afficherChrono(0);
  1484. }
  1485. };
  1486.  
  1487. /**
  1488. * Permet d'arreter le chrono
  1489. **/
  1490. unsafeWindow.pause = function()
  1491. {
  1492. if(timer)
  1493. {
  1494. clearTimeout(timer);
  1495. var d = new Date();
  1496. end = Math.floor(d.getTime() / 1000);
  1497.  
  1498. var divBouton = document.getElementById('pause');
  1499. var html = '<input class="button go" onClick="play();" value="Play" />';
  1500. divBouton.innerHTML = html;
  1501. }
  1502. };
  1503.  
  1504. /**
  1505. * Permet de relancer le chrono
  1506. **/
  1507. unsafeWindow.play = function()
  1508. {
  1509. var d = new Date();
  1510. var tmp = Math.floor(d.getTime() / 1000);
  1511. start -= (end - tmp);
  1512.  
  1513. var secondes = parseInt(document.getElementById('seconde').innerHTML);
  1514. var minutes = parseInt(document.getElementById('minute').innerHTML);
  1515. var heures = parseInt(document.getElementById('heure').innerHTML);
  1516. var total = (heures * 3600) + (minutes * 60) + secondes;
  1517.  
  1518. var divBouton = document.getElementById('pause');
  1519. var html = '<input class="button delete" onClick="pause();" value="Stop !" />';
  1520. divBouton.innerHTML = html;
  1521.  
  1522. afficherChrono(total);
  1523. };
  1524.  
  1525. /**
  1526. * Mets tous les exercices à 70% hormis ceux à 2 modes du repmin
  1527. * @param int id l'id de la séance
  1528. **/
  1529. unsafeWindow.soixanteDix = function(id)
  1530. {
  1531. var exercices = document.getElementsByClassName('exercices');
  1532. var nb = exercices.length;
  1533. var series;
  1534.  
  1535. // On parcourt tous les exercices
  1536. for(i = 0; i < nb; i++)
  1537. {
  1538. series = exercices[i].getElementsByClassName('serie');
  1539. nbSeries = series.length;
  1540.  
  1541. // On parcourt toutes les séries
  1542. for(j = 0; j < nbSeries; j++)
  1543. {
  1544. if(parseInt(series[j].value) >= parseInt(seances.seances[id].exercices[i].nbRep) + 2)
  1545. series[j].value = Math.round(series[j].value * 0.7);
  1546. }
  1547. }
  1548.  
  1549. // On modifie le titre de la séance
  1550. var h3 = document.getElementById('seance').getElementsByTagName('h3')[0];
  1551. h3.innerHTML = seances.seances[id].general.titre + ' 70%';
  1552. soixDix = true;
  1553. };
  1554.  
  1555. /**
  1556. * Modifie le total en live
  1557. * @param int i l'id de l'exercice
  1558. **/
  1559. unsafeWindow.modifierTotal = function(id)
  1560. {
  1561. var total_courant = 0;
  1562. var series = document.getElementsByClassName('serie_'+id);
  1563. var nb = series.length;
  1564.  
  1565. for(i = 0; i < nb; i++)
  1566. {
  1567. total_courant += parseInt(series[i].value);
  1568. }
  1569. var diff = (total_courant - totaux[id]);
  1570. diff = diff >= 0 ? '+'+diff : diff;
  1571. var html = 'Total : '+(total_courant)+' <i style="color:#'+(diff >= 0 ? '00AA00' : 'e14848')+';">('+diff+')</i>';
  1572.  
  1573. document.getElementById('total_'+id).innerHTML = html;
  1574. };
  1575.  
  1576. /**
  1577. * Ajoute un input pour les liens youtube
  1578. **/
  1579. unsafeWindow.addYoutube = function()
  1580. {
  1581. var youtube = document.getElementById('youtube');
  1582. var inputs = youtube.getElementsByClassName('youtube');
  1583. var nb = inputs.length;
  1584. var html = '';
  1585. var value = '';
  1586. for(i = 0; i < nb; i++)
  1587. {
  1588. value = inputs[i].value;
  1589. html += '<input type="text" id="youtube_0" class="youtube" value="'+value+'" onBlur="if(this.value == \'\') this.value = \'Lien youtube\';" onClick="if(this.value == \'Lien youtube\') this.value = \'\';" /><br />';
  1590. }
  1591. html += '<input type="text" id="youtube_0" class="youtube" value="Lien youtube" onBlur="if(this.value == \'\') this.value = \'Lien youtube\';" onClick="if(this.value == \'Lien youtube\') this.value = \'\';" /><br />';
  1592. youtube.innerHTML = html;
  1593. };
  1594.  
  1595. /**
  1596. * Génère toutes les cases permettant de changer la difficulté ressentie
  1597. * @param int i l'id de l'exercice
  1598. * @param int j l'id de la série
  1599. - @return string difficulte le code html à afficher
  1600. **/
  1601. function difficulte(i, j)
  1602. {
  1603. var difficulte = '<span class="difficulte" id="d_' + i + '_' + j + '">';
  1604. difficulte += '<span onclick="changer_couleur('+i+', '+j+', \'#61d13f\');" class="changerCouleur" style="background: #61d13f;"></span>';
  1605. difficulte += '<span onclick="changer_couleur('+i+', '+j+', \'#ccab0f\');" class="changerCouleur" style="background: #ccab0f;"></span>';
  1606. difficulte += '<span onclick="changer_couleur('+i+', '+j+', \'#cb2424\');" class="changerCouleur" style="background: #cb2424;"></span>';
  1607. difficulte += '</span>';
  1608. return difficulte;
  1609. }
  1610.  
  1611. /**
  1612. * Permet de changer le background pour la difficulté
  1613. * @param int i l'id de l'exercice
  1614. * @param int j l'id de la série
  1615. * @param string color la couleur en hexadécimal
  1616. **/
  1617. unsafeWindow.changer_couleur = function (i, j, color)
  1618. {
  1619. var id = 'serie_'+i+'_'+j;
  1620. document.getElementById(id).style.backgroundColor = color;
  1621. };
  1622.  
  1623. /**
  1624. * Centre un élément
  1625. **/
  1626. function centrerEl(el)
  1627. {
  1628. var w_el = el.clientWidth;
  1629. var h_el = el.clientHeight;
  1630. var w_sc = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1631. var h_sc = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  1632. el.style.left = (w_sc - w_el) / 2 + 'px';
  1633. el.style.top = (h_sc - h_el) < 0 ? 0 : (h_sc - h_el) / 2 + 'px';
  1634. }
  1635.  
  1636. /**
  1637. * Convertir une couleur rgb en hexadecimal
  1638. * @param text rgb la couleur au format rgb
  1639. * @return text la couleur au format hexadecimal
  1640. **/
  1641. function rgb2hex(rgb)
  1642. {
  1643. rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
  1644. return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
  1645. }
  1646. /**
  1647. * Convertir un décimal en hexadecimal
  1648. * @param int x la couleur entre 0 et 255
  1649. * @return int x la couleur entre 00 et FF
  1650. **/
  1651. function hex(x)
  1652. {
  1653. return isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
  1654. }
  1655. /**
  1656. * Récupère l'id d'un lien youtube
  1657. * @param str le lien youtube
  1658. * @return str l'id du lien
  1659. **/
  1660. function id_youtube(lien)
  1661. {
  1662. var regex = lien.match(/\?v=([A-Za-z0-9\-_]+)&?/);
  1663. return regex[1];
  1664. }