Guest User

Untitled

a guest
Jul 1st, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.08 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TopicLive
  3. // @description Charge les nouveaux messages d'un topic de JVC en direct
  4. // @author kiwec
  5. // @downloadURL https://github.com/kiwec/TopicLive/raw/master/topiclive.user.js
  6. // @updateURL https://github.com/kiwec/TopicLive/raw/master/topiclive.user.js
  7. // @match https://www.jeuxvideo.com/*
  8. // @match https://m.jeuxvideo.com/*
  9. // @run-at document-end
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  11. // @version 5.4.2
  12. // @grant none
  13. // @noframes
  14. // ==/UserScript==
  15.  
  16. class Page {
  17. constructor($page) {
  18. // TL.log('Nouvelle page.');
  19. this.$page = $page;
  20. }
  21.  
  22. obtenirMessages() {
  23. // TL.log('page.obtenirMessages()');
  24. const msgs = [];
  25. this.trouver(`${TL.class_msg}:not(.msg-pseudo-blacklist)`).each(function() {
  26. msgs.push(new Message($(this)));
  27. });
  28. return msgs;
  29. }
  30.  
  31. // Appele quand il y a des nouveaux messages
  32. maj() {
  33. TL.log('Nouveaux messages ! Execution favicon/son/spoilers');
  34. if(localStorage.topiclive_son == 'true') {
  35. try { TL.son.play(); }
  36. catch(err) { TL.log(`### Erreur son : ${err}`); }
  37. }
  38. try { if(!TL.ongletActif) TL.favicon.maj(`${TL.nvxMessages}`); }
  39. catch(err) { TL.log(`### Erreur favicon (maj) : ${err}`); }
  40. try { this.Transformation(); }
  41. catch(err) { TL.log(`### Erreur jsli.Transformation() : ${err}`); }
  42.  
  43. // Nettoyage des anciens messages
  44. const nb_messages = $(`${TL.class_msg}:not(.msg-pseudo-blacklist)`).size();
  45. if(nb_messages > 100) {
  46. $(`${TL.class_msg}:not(.msg-pseudo-blacklist)`)
  47. .slice(0, nb_messages - 100)
  48. .remove();
  49. }
  50.  
  51. TL.log('Envoi de topiclive:doneprocessing');
  52. dispatchEvent(new CustomEvent('topiclive:doneprocessing', {
  53. 'detail': { jvcake: TL.jvCake }
  54. }));
  55. }
  56.  
  57. scan() {
  58. // TL.log('Scan de la page');
  59. TL.ajaxTs = this.trouver('#ajax_timestamp_liste_messages').val();
  60. TL.ajaxHash = this.trouver('#ajax_hash_liste_messages').val();
  61.  
  62. // Maj du nombre de connectes
  63. $('.nb-connect-fofo').text(this.trouver('.nb-connect-fofo').text());
  64.  
  65. if($(TL.class_msg).length === 0 || $(TL.class_page_fin).length !== 0) {
  66. TL.log('Pas sur une derniere page : loop');
  67. TL.majUrl(this);
  68. TL.loop();
  69. return;
  70. }
  71.  
  72. let messages_a_afficher = [];
  73.  
  74. // TL.log('Verification des nouveaux messages et editions');
  75. const nvMsgs = this.obtenirMessages();
  76. try {
  77. for(let nvMsg of nvMsgs) {
  78. // TODO: On n'a pas besoin de ce hack. On sait que les IDs
  79. // s'incrémentent, il faut juste tenir compte de 8 liste
  80. // d'IDs différents, car il y a 8 listes séparées d'IDs qui
  81. // s'incrémentent (logique de sharing de JVC). On peut donc
  82. // en théorie retirer le check de contenu des messages et
  83. // avoir des résultats plus stables.
  84. let nv = true;
  85. for(let ancienMsg of TL.messages) {
  86. if(TL.estMP) {
  87. if(ancienMsg.trouver('.bloc-spoil-jv').length !== 0) {
  88. const ancienneDate = ancienMsg.trouver(TL.class_date).text();
  89. const nouvelleDate = nvMsg.trouver(TL.class_date).text();
  90. if(ancienneDate == nouvelleDate) {
  91. nv = false;
  92. break;
  93. }
  94. } else if(ancienMsg.$message.text() == nvMsg.$message.text()) {
  95. nv = false;
  96. break;
  97. }
  98. } else {
  99. if(ancienMsg.id_message == nvMsg.id_message) {
  100. nv = false;
  101. ancienMsg.update(nvMsg);
  102. break;
  103. }
  104. }
  105. }
  106. if(nv) {
  107. // TL.log('Nouveau message !');
  108. TL.messages.push(nvMsg);
  109. TL.nvxMessages++;
  110.  
  111. nvMsg.$message.hide();
  112. nvMsg.fixAvatar();
  113. nvMsg.fixBlacklist();
  114. nvMsg.fixCitation();
  115. nvMsg.fixDeroulerCitation();
  116. if(TL.mobile) {
  117. nvMsg.fixMobile();
  118. }
  119. $(`${TL.class_pagination}:last`).before(nvMsg.$message);
  120.  
  121. const evt = {
  122. message: nvMsg,
  123. cancelled: false
  124. };
  125. messages_a_afficher.push(evt);
  126.  
  127. dispatchEvent(new CustomEvent('topiclive:newmessage', {
  128. 'detail': {
  129. id: nvMsg.id_message,
  130. jvcake: TL.jvCake,
  131. cancel: () => { evt.cancelled = true; }
  132. }
  133. }));
  134. }
  135. }
  136. } catch(err) { TL.log(`Erreur nouveaux messages : ${err}`); }
  137.  
  138. TL.majUrl(this);
  139.  
  140. if(messages_a_afficher.length > 0) {
  141. setTimeout(() => {
  142. let maj = false;
  143. for(let msg of messages_a_afficher) {
  144. if(msg.cancelled) {
  145. TL.nvxMessages--;
  146. } else {
  147. TL.log(`Affichage du message ${msg.message.id_message}`);
  148. msg.message.$message.fadeIn('slow');
  149. maj = true;
  150. }
  151. }
  152.  
  153. if(maj) {
  154. this.maj();
  155. }
  156. }, 1000);
  157. }
  158.  
  159. TL.loop();
  160. }
  161.  
  162. // Version perso de JvCare
  163. Transformation() {
  164. $('.JvCare').each(function () {
  165. const $span = $(this);
  166. let classes = $span.attr('class');
  167. const href = TL.jvCake(classes);
  168.  
  169. // Suppression de JvCare
  170. classes = classes.split(' ');
  171. const index = classes.indexOf('JvCare');
  172. classes.splice(index, index + 2);
  173. classes.unshift('xXx');
  174. classes = classes.join(' ');
  175.  
  176. $span.replaceWith(`<a href="${href}" class="${classes}">${$span.html()}</a>`);
  177. });
  178.  
  179. // Fix temporaire des avatars
  180. $('.user-avatar-msg').each(function () {
  181. const $elem = $(this);
  182. const newsrc = $elem.attr('data-srcset');
  183. if(newsrc != 'undefined') {
  184. $elem.attr('src', newsrc);
  185. $elem.removeAttr('data-srcset');
  186. }
  187. });
  188. }
  189.  
  190. trouver(chose) {
  191. // TL.log('Page.trouver : ' + chose);
  192. return this.$page.find(chose);
  193. }
  194. }
  195.  
  196. class TLOption {
  197. constructor(nom, id) {
  198. this.actif = localStorage[id] == 'true';
  199. this.nom = nom;
  200. this.id = id;
  201.  
  202. this.injecter();
  203. }
  204.  
  205. injecter() {
  206. // Ajout de l'option aux options JVC
  207. let option = `<li><span class="pull-left">TopicLive - ${this.nom}</span>`;
  208. option += `<input type="checkbox" class="input-on-off" id="${this.id}" `;
  209. option += this.actif ? 'checked>' : '>';
  210. option += `<label for="${this.id}" class="btn-on-off"></label></li>`;
  211. $('.menu-user-forum').append(option);
  212.  
  213. // Register des events lors du toggle de l'option
  214. this.bouton = $(`#${this.id}`);
  215. this.bouton.change(() => {
  216. this.actif = !this.actif;
  217. localStorage[this.id] = this.actif;
  218. });
  219. }
  220. }
  221.  
  222. class Message {
  223. constructor($message) {
  224. if(TL.estMP) {
  225. this.id_message = 'MP';
  226. } else if(TL.mobile) {
  227. let id = $message.attr('id');
  228. id = id.slice(id.indexOf('_') + 1);
  229. this.id_message = parseInt(id, 10);
  230. } else {
  231. this.id_message = parseInt($message.attr('data-id'), 10);
  232. }
  233.  
  234. this.date = $(TL.class_date, $message).text().replace(/[\r\n]|#[0-9]+$/g, '');
  235. this.edition = $message.find('.info-edition-msg').text();
  236. this.$message = $message;
  237. this.pseudo = $('.bloc-pseudo-msg', $message).text().replace(/[\r\n]/g, '');
  238. this.supprime = false;
  239. }
  240.  
  241. fixAvatar() {
  242. let avatar = this.trouver('.user-avatar-msg');
  243. avatar.attr('src', avatar.data('src'));
  244. }
  245.  
  246. fixBlacklist() {
  247. this.trouver('.bloc-options-msg > .picto-msg-tronche, .msg-pseudo-blacklist .btn-blacklist-cancel').on('click', function () {
  248. $.ajax({
  249. url: '/forums/ajax_forum_blacklist.php',
  250. data: {
  251. id_alias_msg: this.$message.attr('data-id-alias'),
  252. action: this.$message.attr('data-action'),
  253. ajax_hash: $('#ajax_hash_preference_user')
  254. },
  255. dataType: 'json',
  256. success({erreur}) {
  257. if(erreur && erreur.length) {
  258. TL.alert(erreur);
  259. } else {
  260. document.location.reload();
  261. }
  262. }
  263. });
  264. });
  265. }
  266.  
  267. fixCitation() {
  268. TL.log(`Obtention de la citation du message ${this.id_message}`);
  269. this.$message.find('.bloc-options-msg .picto-msg-quote').on('click', () => {
  270. $.ajax({
  271. type: 'POST',
  272. url: '/forums/ajax_citation.php',
  273. data: {
  274. id_message: this.id_message,
  275. ajax_timestamp: TL.ajaxTs,
  276. ajax_hash: TL.ajaxHash
  277. },
  278. dataType: 'json',
  279. timeout: 5000,
  280. success: ({txt}) => {
  281. TL.log(`Citation du message ${this.id_message} recue avec succes`);
  282. const $msg = TL.formu.obtenirMessage();
  283. let nvmsg = `> Le ${this.date} ${this.pseudo} a écrit :\n>`;
  284. nvmsg += `${txt.split('\n').join('\n> ')}\n\n`;
  285. if($msg.val() === '') {
  286. $msg.val(nvmsg);
  287. } else {
  288. $msg.val(`${$msg.val()}\n\n${nvmsg}`);
  289. }
  290. },
  291. error: this.fixCitation.bind(this)
  292. });
  293. });
  294. }
  295.  
  296. fixDeroulerCitation() {
  297. this.trouver('blockquote').click(function() {
  298. $(this).attr('data-visible', '1');
  299. });
  300. }
  301.  
  302. fixMobile() {
  303. this.trouver('.message').addClass('show-all');
  304. }
  305.  
  306. trouver(chose) {
  307. return this.$message.find(chose);
  308. }
  309.  
  310. update(nvMessage) {
  311. if(this.edition == nvMessage.edition) return;
  312. TL.log(`Message ${this.id_message} edite : mise a jour`);
  313.  
  314. this.edition = nvMessage.edition;
  315. this.trouver(TL.class_contenu).html(nvMessage.trouver(TL.class_contenu).html());
  316.  
  317. dispatchEvent(new CustomEvent('topiclive:edition', {
  318. 'detail': {
  319. id: this.id_message,
  320. jvcake: TL.jvCake
  321. }
  322. }));
  323.  
  324. // Clignotement du messages
  325. const defColor = this.$message.css('backgroundColor');
  326. this.$message.animate({
  327. backgroundColor: '#FF9900'
  328. }, 50);
  329. this.$message.animate({
  330. backgroundColor: defColor
  331. }, 500);
  332. }
  333. }
  334.  
  335. class Formulaire {
  336. constructor() {
  337. // TL.log('Nouveau formulaire.');
  338. this.hook();
  339. }
  340.  
  341. afficherErreurs(msg) {
  342. if(typeof msg !== 'undefined') {
  343. let message_erreur = '';
  344. for(let i = 0; i < msg.length; i++) {
  345. message_erreur += msg[i];
  346. if(i < msg.length) message_erreur += '<br />';
  347. }
  348. TL.alert(message_erreur);
  349. }
  350. }
  351.  
  352. envoyer(e) {
  353. // Si le message est invalide selon JVC
  354. if(typeof e !== 'undefined' && typeof e.errors !== 'undefined' && e.errors.length) {
  355. this.afficherErreurs(e.erreurs);
  356. } else {
  357. TL.log('Message valide. Envoi en cours');
  358. this.trouver('.btn-poster-msg').attr('disabled', 'disabled');
  359. this.trouver('.conteneur-editor').fadeOut();
  360.  
  361. window.clearTimeout(TL.idanalyse);
  362. $.ajax({
  363. type: 'POST',
  364. url: TL.url,
  365. data: this.obtenirFormulaire().serializeArray(),
  366. timeout: 5000,
  367. success: data => {
  368. switch(typeof data) {
  369. case 'object':
  370. // MaJ du formulaire via JSON
  371. if(data.hidden_reset) {
  372. this.trouver('input[type="hidden"]').remove();
  373. this.obtenirFormulaire().append(data.hidden_reset);
  374. }
  375.  
  376. // Erreur lors de l'envoi du message
  377. if(data.errors) {
  378. this.afficherErreurs(data.errors);
  379. this.trouver('.btn-poster-msg').removeAttr('disabled');
  380. this.trouver('.conteneur-editor').fadeIn();
  381. }
  382.  
  383. // Redirection via JSON (wtf)
  384. if(data.redirect_uri) {
  385. TL.log(`Redirection du formulaire vers ${data.redirect_uri}`);
  386. TL.url = data.redirect_uri;
  387. TL.GET(this.verifEnvoi.bind(this));
  388. }
  389. break;
  390. case 'string':
  391. this.verifEnvoi($(data.substring(data.indexOf('<!DOCTYPE html>'))));
  392. break;
  393. case 'undefined': /* falls through */
  394. default:
  395. TL.alert('Erreur inconnue lors de l\'envoi du message.');
  396. this.trouver('.btn-poster-msg').removeAttr('disabled');
  397. this.trouver('.conteneur-editor').fadeIn();
  398. break;
  399. }
  400.  
  401. TL.loop();
  402. },
  403. error: err => TL.alert(`Erreur lors de l'envoi du message : ${err}`)
  404. });
  405. }
  406. }
  407.  
  408. hook() {
  409. // Remplacement du bouton de post
  410. const $form = this.obtenirFormulaire();
  411. const $bouton = $form.find('.btn-poster-msg');
  412. $bouton.off();
  413. $bouton.removeAttr('data-push');
  414. $bouton.attr('type', 'button');
  415. $bouton.on('click', this.verifMessage.bind(this));
  416. }
  417.  
  418. maj($nvform) {
  419. TL.log('Mise a jour du formulaire');
  420. const $form = this.obtenirFormulaire();
  421. const $cap = this.obtenirCaptcha($form);
  422. const $ncap = this.obtenirCaptcha($nvform);
  423.  
  424. // Remplacement hashs formulaire
  425. this.trouver('input[type="hidden"]').remove();
  426. $nvform.find('input[type="hidden"]').each(function() {
  427. $form.append($(this));
  428. });
  429.  
  430. // Reactivation des boutons
  431. this.trouver('.btn-poster-msg').removeAttr('disabled');
  432. this.trouver('.conteneur-editor').fadeIn();
  433.  
  434. // Remplacement du captcha
  435. $cap.remove();
  436. this.trouver('.jv-editor').after($ncap);
  437.  
  438. // Maj banniere erreur
  439. this.trouver('.alert-danger').remove();
  440. this.trouver('.row:first').before($nvform.find('.alert-danger'));
  441.  
  442. // Remplacement du message (JVC n'effacera pas le message en erreur)
  443. this.obtenirMessage().val(this.obtenirMessage($nvform).val());
  444.  
  445. this.hook();
  446. }
  447.  
  448. obtenirCaptcha($form) {
  449. if(typeof $form === 'undefined') $form = this.obtenirFormulaire();
  450. return $form.find('.jv-editor').next('div');
  451. }
  452.  
  453. obtenirMessage($form) {
  454. if(typeof $form == 'undefined') $form = this.obtenirFormulaire();
  455. return $form.find(TL.estMP ? '#message' : '#message_topic');
  456. }
  457.  
  458. obtenirFormulaire($page) {
  459. if(typeof $page === 'undefined') $page = $(document);
  460. return $page.find(TL.estMP ? '#repondre-mp > form' : '.form-post-message');
  461. }
  462.  
  463. verifEnvoi(data) {
  464. const nvPage = new Page(data);
  465. const $formu = this.obtenirFormulaire(nvPage.$page);
  466. this.maj($formu);
  467. TL.majUrl(nvPage);
  468. nvPage.scan();
  469. }
  470.  
  471. verifMessage() {
  472. TL.log('Verification du message avant envoi');
  473.  
  474. if(TL.estMP) {
  475. this.envoyer();
  476. } else {
  477. $.ajax({
  478. type: 'POST',
  479. url: '/forums/ajax_check_poste_message.php',
  480. data: {
  481. id_topic, /* globals id_topic */
  482. new_message: this.obtenirMessage().val(),
  483. ajax_timestamp: TL.ajaxTs,
  484. ajax_hash: TL.ajaxHash
  485. },
  486. dataType: 'json',
  487. timeout: 5000,
  488. success: this.envoyer.bind(this),
  489. error: this.verifMessage.bind(this)
  490. });
  491. }
  492.  
  493. return false;
  494. }
  495.  
  496. trouver(chose) {
  497. return this.obtenirFormulaire().find(chose);
  498. }
  499. }
  500.  
  501. // Code de Spawnkill
  502. class Favicon {
  503. constructor() {
  504. try {
  505. this.canv = $('<canvas>').get(0);
  506. this.canv.width = 192;
  507. this.canv.height = 192;
  508. this.context = this.canv.getContext('2d');
  509. this.context.font = 'bold 120px Courier New';
  510. this.context.textBaseline = 'bottom';
  511. this.image = new Image();
  512. this.image.src = 'https://www.jeuxvideo.com/favicon.png';
  513. this.maj('');
  514. } catch(err) {
  515. TL.log(`### Erreur init favicon : ${err}`);
  516. }
  517. }
  518.  
  519. clear() {
  520. this.context.clearRect(0, 0, this.canv.width, this.canv.height);
  521. this.context.drawImage(this.image, 0, 0);
  522. }
  523.  
  524. maj(txt) {
  525. this.clear();
  526.  
  527. if(txt !== '')
  528. {
  529. this.context.fillStyle = 'red';
  530. this.context.fillRect(0, 0, this.context.measureText(txt).width + 36, 132);
  531. this.context.fillStyle = 'white';
  532. this.context.fillText(txt, 12, 132);
  533. }
  534.  
  535. this.replace();
  536. }
  537.  
  538. replace() {
  539. $('link[rel*="icon"]').remove();
  540. this.lien = $('<link>', {
  541. href: this.canv.toDataURL('image/png'),
  542. rel: 'shortcut icon',
  543. type: 'image/png'
  544. });
  545. $('head').append(this.lien);
  546. }
  547. }
  548.  
  549. class TopicLive {
  550. constructor() {
  551. this.log('Initialisation');
  552. this.instance = 0;
  553. this.ongletActif = true;
  554. }
  555.  
  556. ajouterOptions() {
  557. if(this.mobile) return;
  558. this.options = {
  559. optionSon: new TLOption('Son', 'topiclive_son')
  560. };
  561. }
  562.  
  563. charger() {
  564. if(this.oldInstance != this.instance) {
  565. this.log('Nouvelle instance detectee : arret du chargement');
  566. return;
  567. }
  568.  
  569. TL.GET(data => {
  570. new Page(data).scan();
  571. });
  572. }
  573.  
  574. // Sera initialise a chaque changement de page
  575. init() {
  576. if(typeof $ === 'undefined') {
  577. return this.log('### jQuery introuvable !');
  578. }
  579.  
  580. this.instance++;
  581. this.ajaxTs = $('#ajax_timestamp_liste_messages').val();
  582. this.ajaxHash = $('#ajax_hash_liste_messages').val();
  583. this.estMP = $('.mp-page').length;
  584. this.url = this.estMP ? document.URL.substring(0, document.URL.indexOf('&')) : document.URL;
  585. this.mobile = document.URL.includes('//m.jeuxvideo.com');
  586.  
  587. this.class_msg = this.mobile ? '.post' : '.bloc-message-forum';
  588. this.class_num_page = this.mobile ? '.num-page' : '.page-active';
  589. this.class_page_fin = this.mobile ? '.right-elt > a' : '.pagi-fin-actif';
  590. this.class_date = this.mobile ? '.date-post' : '.bloc-date-msg';
  591. this.class_contenu = this.mobile ? '.contenu' : '.bloc-contenu';
  592. this.class_pagination = this.mobile ? '.pagination-b' : '.bloc-pagi-default';
  593.  
  594. this.ajouterOptions();
  595.  
  596. // Actif sur les URL de forums ou de messages privés, tant qu'il y a un
  597. // message dans la page.
  598. // -> Sera compatible respeed, sans pour autant s'exécuter sur des pages
  599. // non supportées (ex. GTA)
  600. const analysable = (document.URL.match(/\/forums\/\d/) || document.URL.match(/\/messages-prives\//));
  601. if(analysable && $(this.class_msg).length > 0) {
  602. this.log('TopicLive actif sur cette page.');
  603. this.page = new Page($(document));
  604. this.formu = new Formulaire();
  605. this.messages = this.page.obtenirMessages();
  606. this.nvxMessages = 0;
  607. this.page.scan();
  608. this.loop();
  609. } else {
  610. this.log('TopicLive sera inactif sur cette page');
  611. }
  612. }
  613.  
  614. // Ne sera pas initialise a chaque changement de page
  615. initStatic() {
  616. this.favicon = new Favicon();
  617. this.son = new Audio('https://raw.githubusercontent.com/Kiwec/TopicLive/master/notification.ogg');
  618.  
  619. this.suivreOnglets();
  620. this.init();
  621. addEventListener('instantclick:newpage', this.init.bind(this));
  622.  
  623. $("head").append("<style type='text/css'>\
  624. .topiclive-loading:after { content: ' ○' }\
  625. .topiclive-loaded:after { content: ' ●' }\
  626. </style>");
  627.  
  628. this.log('Fin de l\'initialisation');
  629. }
  630.  
  631. // Transforme une classe chiffree par JvCare en un lien
  632. jvCake(classe) {
  633. const base16 = '0A12B34C56D78E9F';
  634. let lien = '';
  635. const s = classe.split(' ')[1];
  636. for (let i = 0; i < s.length; i += 2) {
  637. lien += String.fromCharCode(base16.indexOf(s.charAt(i)) * 16 + base16.indexOf(s.charAt(i + 1)));
  638. }
  639. return lien;
  640. }
  641.  
  642. alert(message) {
  643. /* globals modal */
  644. try {
  645. modal('erreur', { message });
  646. this.log(message);
  647. } catch(err) {
  648. this.log('### Fonction modal() inaccessible');
  649. alert(message);
  650. }
  651. }
  652.  
  653. log(message) {
  654. console.log(`[TopicLive] ${message}`);
  655. }
  656.  
  657. loop() {
  658. if(typeof this.idanalyse !== 'undefined') window.clearTimeout(this.idanalyse);
  659.  
  660. let duree = this.ongletActif ? 5000 : 10000;
  661.  
  662. if(this.mobile)
  663. duree = 10000;
  664.  
  665. this.oldInstance = this.instance;
  666. this.idanalyse = setTimeout(this.charger.bind(this), duree);
  667. }
  668.  
  669. majUrl(page) {
  670. if(this.estMP) return;
  671.  
  672. const $bouton = page.trouver(this.class_page_fin);
  673. const numPage = page.trouver(`${this.class_num_page}:first`).text();
  674. const testUrl = this.url.split('-');
  675.  
  676. // Si le bouton page suivante est present
  677. if($bouton.length > 0) {
  678. TL.log('Nouvelle URL (loop)');
  679. this.messages = [];
  680. if($bouton.prop('tagName') == 'A') {
  681. this.url = $bouton.attr('href');
  682. } else {
  683. this.url = this.jvCake($bouton.attr('class'));
  684. }
  685. // Si la page n'est pas la meme (ex. post d'un message sur nouvelle page)
  686. } else if(testUrl[3] != numPage) {
  687. TL.log('Nouvelle URL (formulaire)');
  688. this.messages = [];
  689. testUrl[3] = numPage;
  690. this.url = testUrl.join('-');
  691. }
  692. }
  693.  
  694. suivreOnglets() {
  695. $(window).bind('focus', () => {
  696. if(!this.ongletActif) {
  697. this.ongletActif = true;
  698. this.favicon.maj('');
  699. this.nvxMessages = 0;
  700. }
  701. });
  702. $(window).bind('blur', () => {
  703. if(this.ongletActif) {
  704. this.ongletActif = false;
  705. this.favicon.maj('');
  706. this.nvxMessages = 0;
  707. }
  708. });
  709. }
  710.  
  711. GET(cb) {
  712. const blocChargement = this.mobile ? $('.bloc-nom-sujet:last > span') : $('#bloc-formulaire-forum .titre-bloc');
  713. blocChargement.addClass('topiclive-loading');
  714.  
  715. window.clearTimeout(this.idanalyse);
  716. $.ajax({
  717. type: 'GET',
  718. url: this.url,
  719. timeout: 5000,
  720. success: data => {
  721. if(this.oldInstance != this.instance) {
  722. this.log('Nouvelle instance detectee : arret du chargement');
  723. return;
  724. }
  725.  
  726. blocChargement.removeClass('topiclive-loading');
  727. blocChargement.addClass('topiclive-loaded');
  728. cb($(data.substring(data.indexOf('<!DOCTYPE html>'))));
  729. setTimeout(() => { blocChargement.removeClass('topiclive-loaded'); }, 100);
  730.  
  731. TL.loop();
  732. },
  733. error() {
  734. TL.loop();
  735. }
  736. });
  737. }
  738. }
  739.  
  740. var TL = new TopicLive();
  741. TL.initStatic();
  742.  
Advertisement
Add Comment
Please, Sign In to add comment