Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.55 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AveNoel
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.22.1
  5. // @description Spartanz en sueur
  6. // @author MrPointVult
  7. // @match https://avenoel.org/*
  8. // @require http://www.chartjs.org/dist/2.7.2/Chart.bundle.js
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
  10. // @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
  11. // @grant GM_addStyle
  12. // @grant GM_getResourceText
  13. // ==/UserScript==
  14.  
  15. //-----------------------------------------------------
  16. // TODO list
  17. //-----------------------------------------------------
  18. //classer les MPs en catégorie
  19. //voir ce que je peux faire des vidéos (possible de synchoniser ?)
  20. //-----------------------------------------------------
  21.  
  22. //Profils
  23. var regexList;
  24. var bansRegex;
  25. var profilUsers;
  26. var favProfiles;
  27. var banProfiles;
  28. var currentProfile;
  29. var colorListProfil = [
  30. "White",
  31. "LightBlue",
  32. "LightCoral",
  33. "LightCyan",
  34. "LightGoldenRodYellow",
  35. "LightGrey",
  36. "LightGreen",
  37. "LightPink",
  38. "LightSalmon",
  39. "LightSeaGreen",
  40. "LightSkyBlue",
  41. "LightSlateGrey",
  42. "LightSteelBlue"
  43. ];
  44.  
  45. //Topic
  46. var favs;
  47. var bans;
  48.  
  49. // Global
  50. var id = 0;
  51. var profil = {name:"rien", quoted:"", noneRead:"", nbMail:"", tabName:document.title};
  52. const space = "&nbsp";
  53. const url = "https://avenoel.org";
  54. const imgQuote = "<img style=\"cursor: pointer;\" src=\"/images/topic/quote.png\" alt=\"Icône citation\" width=\"20\">";
  55. const imgEdit = "<img style=\"cursor: pointer;\" src=\"/images/topic/edit.png\" alt=\"Icône éditer\" title=\"Éditer le message\" width=\"20\">";
  56. const imgDelete = "<img style=\"cursor: pointer;\" src=\"/images/topic/delete.png\" alt=\"Icône suppression\" width=\"20\">";
  57. const imgLivraisonList =
  58. ["https://image.noelshack.com/fichiers/2018/08/1/1519061174-watamote15.png",
  59. "https://image.noelshack.com/fichiers/2018/01/6/1515207003-hif.gif",
  60. "https://image.noelshack.com/fichiers/2017/04/1485268586-hackeur-v1.png",
  61. "https://image.noelshack.com/fichiers/2017/02/1484089609-coeur.png",
  62. "https://image.noelshack.com/fichiers/2017/15/1492271548-alerte.gif",
  63. "https://image.noelshack.com/fichiers/2018/11/6/1521293603-negan3png.png",
  64. "https://image.noelshack.com/fichiers/2017/17/1493408788-modo-eplingle.png",
  65. "https://image.noelshack.com/fichiers/2018/10/3/1520427923-74679246-817a-4df6-8077-a4659b8048e8.jpeg",
  66. "https://i.imgur.com/aHLhmoa.png"];
  67. const imgLivraison = "<img class=\"board-noelshack\" src=\""+imgLivraisonList[Math.floor(Math.random() * imgLivraisonList.length)]+" \">";
  68.  
  69. (function() {
  70. 'use strict';
  71.  
  72. var t0 = performance.now();
  73.  
  74. //debugger;
  75. //localStorage.removeItem("favs");
  76. //localStorage.removeItem("bans");
  77. //localStorage.removeItem("favProfiles");
  78. //localStorage.removeItem("banProfiles");
  79. //localStorage.removeItem("profilUsers");
  80.  
  81. addStyle();
  82. initProfil();
  83. initFunctions();
  84. setInterval(initCache, 1500);
  85. initCache();
  86. scrollBack();
  87.  
  88. var path = window.location.pathname;
  89.  
  90. if (path.startsWith('/profil')) {
  91. traiterProfil();
  92. } else {
  93. ajouterBarFav();
  94. if (path.startsWith('/forum')) {
  95. traiterForum();
  96. } else if (path.startsWith('/topic')) {
  97. traiterTopic();
  98. } else if (path === '/messagerie') {
  99. traiterMessagerie();
  100. } else if (path.startsWith('/stats')) {
  101. traiterStats();
  102. } else if (path.startsWith('/messagerie')) {
  103. } else {
  104. console.log('Cas ' + path + " non traité.");
  105. }
  106. }
  107.  
  108. enhanceTextArea();
  109. controlVersion();
  110.  
  111. var t1 = performance.now();
  112. console.log("Call to AveNoel took " + (t1 - t0) + " milliseconds.");
  113.  
  114. })();
  115.  
  116. function initProfil() {
  117. var navbarUserAvatar = document.getElementsByClassName('navbar-user-avatar')[0];
  118. if (!navbarUserAvatar) {
  119. return;
  120. }
  121. var split = navbarUserAvatar.parentElement.href.split("/");
  122. profil.name = split[split.length-1];
  123. }
  124.  
  125. function initFunctions() {
  126. if (!String.prototype.splice) {
  127. /**
  128. * {JSDoc}
  129. *
  130. * The splice() method changes the content of a string by removing a range of
  131. * characters and/or adding new characters.
  132. *
  133. * @this {String}
  134. * @param {number} start Index at which to start changing the string.
  135. * @param {number} delCount An integer indicating the number of old chars to remove.
  136. * @param {string} newSubStr The String that is spliced in.
  137. * @return {string} A new string with the spliced substring.
  138. */
  139. String.prototype.splice = function(start, delCount, newSubStr) {
  140. return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
  141. };
  142. }
  143.  
  144. if (!Date.prototype.getString) {
  145. Date.prototype.getString = function() {
  146. var yyyy = this.getFullYear();
  147. var mm = this.getMonth() < 9 ? "0" + (this.getMonth() + 1) : (this.getMonth() + 1); // getMonth() is zero-based
  148. var dd = this.getDate() < 10 ? "0" + this.getDate() : this.getDate();
  149. var hh = this.getHours() < 10 ? "0" + this.getHours() : this.getHours();
  150. var min = this.getMinutes() < 10 ? "0" + this.getMinutes() : this.getMinutes();
  151. var ss = this.getSeconds() < 10 ? "0" + this.getSeconds() : this.getSeconds();
  152. //return "".concat(dd).concat("/").concat(mm).concat("/").concat(yyyy).concat(" ").concat(hh).concat(":").concat(min).concat(":").concat(ss);
  153. return "".concat(yyyy).concat("/").concat(mm).concat("/").concat(dd).concat(" ").concat(hh).concat(":").concat(min).concat(":").concat(ss);
  154. };
  155. }
  156. if (!Date.prototype.addHours) {
  157. Date.prototype.addHours = function(hour) {
  158. this.setTime(this.getTime() + (hour*60*60*1000));
  159. return this;
  160. }
  161. }
  162. }
  163.  
  164. function initCache() {
  165. profilUsers = localStorage.profilUsers === undefined ? {} : JSON.parse(localStorage.profilUsers);
  166. regexList = localStorage.regexList === undefined ? [] : JSON.parse(localStorage.regexList);
  167. bansRegex = localStorage.bansRegex === undefined ? [] : JSON.parse(localStorage.bansRegex);
  168. favs = localStorage.favs === undefined ? {} : JSON.parse(localStorage.favs);
  169. bans = localStorage.bans === undefined ? [] : JSON.parse(localStorage.bans);
  170. favProfiles = localStorage.favProfiles === undefined ? [] : JSON.parse(localStorage.favProfiles);
  171. banProfiles = localStorage.banProfiles === undefined ? [] : JSON.parse(localStorage.banProfiles);
  172. }
  173.  
  174. function controlVersion() {
  175. httpGetApiAsync("messages/1611709", function(res) {
  176.  
  177. var matchVersion = res.data.content.match(/[0-9]+\.[0-9]+\.[0-9]+/g);
  178. if (matchVersion && version !== matchVersion[0]) {
  179.  
  180. var patchNotes = res.data.content.split("Je compte l'enrichir")[0].match(/\+.*/g);
  181. var div = document.getElementById('alertversion');
  182. var innerHTML =
  183. "Version <a href=\"https://avenoel.org/topic/101099-1-aide-voici-un-script-pour-vous-faciliter-la-vie-sur-avn\">" + matchVersion[0] + "</a> disponible."+
  184. "<br>N'oubliez pas de laisser un commentaire." +
  185. "<br>"+ imgLivraison;
  186.  
  187. div.innerHTML = innerHTML;
  188. div.style.color = "red";
  189. }
  190. });
  191.  
  192. }
  193.  
  194. function scrollBack() {
  195.  
  196. var buttonUp = createElem(document.getElementsByTagName("body")[0],
  197. "<button id=\"idBtnScrollBackUp\" ><img class=\"board-noelshack\" src=\"https://i.imgur.com/5jJBFmD.png \"></button>");
  198.  
  199. buttonUp.onclick = function() {
  200. document.body.scrollTop = 0; // For Safari
  201. document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
  202. };
  203.  
  204. var buttonDown = createElem(document.getElementsByTagName("body")[0],
  205. "<button id=\"idBtnScrollBackDown\" ><img class=\"board-noelshack\" src=\"https://i.imgur.com/5jJBFmD.png \"></button>");
  206.  
  207. buttonDown.onclick = function() {
  208. document.body.scrollTop = document.body.scrollHeight; // For Safari
  209. document.documentElement.scrollTop = document.body.scrollHeight; // For Chrome, Firefox, IE and Opera
  210. };
  211.  
  212. var event = function(e) {
  213. if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  214. document.getElementById("idBtnScrollBackUp").style.display = "block";
  215. } else {
  216. document.getElementById("idBtnScrollBackUp").style.display = "none";
  217. }
  218.  
  219. if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
  220. document.getElementById("idBtnScrollBackDown").style.display = "none";
  221. } else {
  222. document.getElementById("idBtnScrollBackDown").style.display = "block";
  223. }
  224. };
  225. window.addEventListener('scroll', event);
  226. event.apply();
  227.  
  228. }
  229.  
  230. //-----------------------------------------------------
  231. // Editeur de texte
  232. //-----------------------------------------------------
  233.  
  234. function enhanceTextArea() {
  235.  
  236. var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
  237. if (!textArea) {
  238. return;
  239. }
  240.  
  241. function doc_keyUp(e) {
  242. if (e.ctrlKey && e.keyCode == 81) {
  243. var display = document.getElementById("risi-overlay").style.display;
  244. document.getElementById("risi-overlay").style.display = (display === "") ? "none" : "";
  245.  
  246. if (document.getElementById("risi-overlay").style.display !== "") {
  247. textArea.focus();
  248. } else {
  249. document.getElementById("risi-recherche").focus();
  250. }
  251. }
  252.  
  253. }
  254. document.addEventListener('keyup', doc_keyUp, false);
  255. document.getElementsByClassName("risi-r")[0].innerHTML = "Raccourci => Ctrl+Q" + document.getElementsByClassName("risi-r")[0].innerHTML;
  256.  
  257. // dragElement(document.getElementsByClassName("col-md-10 col-md-offset-1")[0].children[0]);
  258. //document.getElementsByClassName("col-md-10 col-md-offset-1")[0].children[0].id = 'dxy';
  259.  
  260. if (textArea.value.length > 0) {
  261. textArea.selectionStart = textArea.value.length;
  262. textArea.focus();
  263. }
  264.  
  265. var edit = function(tagIn, tagOut) {
  266.  
  267. var start = textArea.selectionStart;
  268. var end = textArea.selectionEnd;
  269. textArea.value = textArea.value.splice(textArea.selectionEnd, 0, tagOut).splice(textArea.selectionStart, 0, tagIn);
  270. textArea.selectionStart = start + tagIn.length;
  271. textArea.selectionEnd = end + tagIn.length;
  272. textArea.focus();
  273.  
  274. };
  275.  
  276. var textAreaButtons = document.getElementsByClassName("form-group bbcodes")[document.getElementsByClassName("form-group bbcodes").length - 1];
  277.  
  278. var list = [
  279. {name:"R", tagIn:"<color=red>", tagOut:"</color>", color:"red"},
  280. {name:"G", tagIn:"<color=green>", tagOut:"</color>", color:"green"},
  281. {name:"B", tagIn:"<color=blue>", tagOut:"</color>", color:"blue"}
  282. ];
  283. var div = document.createElement('div');
  284. list.forEach(function(each) {
  285.  
  286. div.innerHTML = "<button type=\"button\" class=\"btn\" tabindex=\"-1\" data-type=\"tag\"><span>" + each.name + "</span></button>";
  287. var btn = div.firstChild;
  288. textAreaButtons.appendChild(btn);
  289. btn.style.color = each.color;
  290. btn.onclick = function() {edit(each.tagIn, each.tagOut);};
  291.  
  292. });
  293.  
  294. div.innerHTML = "<div style=\"max-height: 122px;overflow-y: scroll;\"></div>";
  295. var risibank = div.firstChild;
  296. textAreaButtons.appendChild(risibank);
  297.  
  298. var risiList = document.getElementsByClassName("risi-rlist")[0];
  299. risiList.childNodes.forEach(function(each) {
  300.  
  301. var img = each.cloneNode(true);
  302. img.classList = [];
  303. img.style.cssText = "position: relative;display: inline-block;padding: 5px;";
  304. img.children[0].classList = [];
  305. img.children[0].style.cssText = "width: 68px;height: 51px;cursor:pointer;";
  306. risibank.appendChild(img);
  307. img.onclick = function() {edit(img.children[0].src+" ", "");};
  308.  
  309. });
  310.  
  311. div.remove();
  312.  
  313. textArea.onfocusout = function () {
  314. var value = textArea.value;
  315. regexList.forEach(function(each) {
  316. value = value.replace(new RegExp(each.reg, "gm"), each.res);
  317. });
  318.  
  319. // Mort aux cucks
  320. textArea.value = value
  321. .replace(new RegExp(" cuck", "gm"), " candaule")
  322. .replace(new RegExp(" Cuck", "gm"), " Candaule")
  323. .replace(new RegExp(" CUCK", "gm"), " CANDAULE");
  324. };
  325.  
  326. //manageRisiBank();
  327. }
  328.  
  329. function manageRisiBank() {
  330. var risiList = document.getElementsByClassName("risi-rlist")[0];
  331.  
  332. console.log(risiList);
  333.  
  334. risiList.childNodes[1].parentNode.insertBefore(risiList.childNodes[1], risiList.childNodes[0]);
  335.  
  336. }
  337.  
  338. function dragElement(elmnt) {
  339. var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  340. // if (document.getElementById(elmnt.id + "header")) {
  341. /* if present, the header is where you move the DIV from:*/
  342. // document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  343. // } else {
  344. /* otherwise, move the DIV from anywhere inside the DIV:*/
  345. elmnt.onmousedown = dragMouseDown;
  346. // }
  347.  
  348. elmnt.style.position = 'absolute';
  349.  
  350. function dragMouseDown(e) {
  351. e = e || window.event;
  352. // get the mouse cursor position at startup:
  353. pos3 = e.clientX;
  354. pos4 = e.clientY;
  355. document.onmouseup = closeDragElement;
  356. // call a function whenever the cursor moves:
  357. document.onmousemove = elementDrag;
  358. }
  359.  
  360. function elementDrag(e) {
  361. e = e || window.event;
  362. // calculate the new cursor position:
  363. pos1 = pos3 - e.clientX;
  364. pos2 = pos4 - e.clientY;
  365. pos3 = e.clientX;
  366. pos4 = e.clientY;
  367. // set the element's new position:
  368. elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
  369. elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  370. }
  371.  
  372. function closeDragElement() {
  373. /* stop moving when mouse button is released:*/
  374. document.onmouseup = null;
  375. document.onmousemove = null;
  376. }
  377. }
  378.  
  379. //-----------------------------------------------------
  380. // Fav/Courriers
  381. //-----------------------------------------------------
  382.  
  383. function loadYoutube(profil) {
  384.  
  385. document.getElementById("youtubeFav").innerHTML = "";
  386. httpGetAsync("https://avenoel.org/profil/" + profil, function(html) {
  387.  
  388. var button = createElem(document.getElementById("youtubeFav"), imgDelete);
  389. button.onclick = function() {
  390. document.getElementById("youtubeFav").innerHTML = "";
  391. };
  392.  
  393.  
  394. var innerHTML = space + space + "Pas de musique."
  395. if (html.getElementsByTagName("iframe")[0]) {
  396. innerHTML =
  397. "<iframe src=\""+
  398. html.getElementsByTagName("iframe")[0].src.split("?")[0]+
  399. "\"> </iframe>";
  400. }
  401.  
  402. createElem(document.getElementById("youtubeFav"), innerHTML);
  403.  
  404. });
  405.  
  406. }
  407.  
  408. function ajouterBarFav() {
  409.  
  410. var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
  411. if (barFav.length === 0) {
  412. return;
  413. }
  414.  
  415. var idCourrier = getId();
  416. var idFavoris = getId();
  417. barFav[0].replaceChild(barFav[0].children[0].cloneNode(true), barFav[0].children[0]);
  418.  
  419. var listDiv = barFav[0].children[1];
  420. listDiv.classList = [];
  421. listDiv.innerHTML =
  422. "<section>"+
  423. //" <div><iframe src=\"https://www.youtube.com/embed/xh_bqcyqp64\"> </iframe></div>"+
  424. " <div id=\"youtubeFav\"></div>"+
  425. " <div id=\"alertversion\"></div>"+
  426. " <div id=\""+idCourrier+"\"></div>"+
  427. " <div id=\""+idFavoris+"\"></div>"+
  428.  
  429. "</section>";
  430.  
  431. var rect = listDiv.getBoundingClientRect(),
  432. scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  433. var top = rect.top + scrollTop;
  434. var event = function(e) {
  435. if (window.scrollY > top) {
  436. listDiv.style.position = "absolute";
  437. listDiv.style.top = window.scrollY + 'px';
  438. } else {
  439. listDiv.style.position = null;
  440. listDiv.style.top = top + 'px';
  441. }
  442. };
  443. window.addEventListener('scroll', event);
  444. event.apply();
  445.  
  446.  
  447. var setMails = function(){
  448. httpGetAsync("https://avenoel.org/messagerie", function (html) {
  449. var mails = html.getElementsByClassName("active");
  450.  
  451. if (mails.length > 2) {
  452. profil.nbMail = "(" + (mails.length-2) + ") ";
  453. var innerHTMLCourrier = "Courrier" + ((mails.length-2) > 1 ? "s" : "") + " (" + (mails.length-2) + ")";
  454.  
  455. for(var i = 1; i < mails.length -1; ++i) {
  456. innerHTMLCourrier += "<li>";
  457. innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
  458. innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
  459. innerHTMLCourrier += "</li>";
  460. }
  461.  
  462. document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
  463. } else {
  464. profil.nbMail = "";
  465. document.getElementById(idCourrier).innerHTML = "";
  466. }
  467. changeTitle();
  468. });
  469. };
  470. setInterval(setMails, 30000);
  471. setMails.apply();
  472.  
  473. var setFavs = function(){
  474. httpGetAsync("https://avenoel.org/favoris", function (html) {
  475. var list = html.getElementsByTagName("tBody")[0].children;
  476. var buttonBar = document.getElementById(idFavoris);
  477. var innerHTMLFav = "Favoris";
  478. var hasNoneRead = false;
  479. profil.quoted = "";
  480.  
  481. for(var i = 0; i < list.length; i++) {
  482.  
  483. var fav = list[i];
  484. var sNbDiff = "";
  485. var nbDiff = 0;
  486.  
  487. var href = fav.children[1].children[0].href;
  488. var nb = fav.children[3].innerHTML.trim();
  489.  
  490. if (fav.children[0].children[0].href === window.location.href) {
  491. favs[href] = nb;
  492. localStorage.setItem("favs", JSON.stringify(favs));
  493. }
  494.  
  495. if (favs[href]) {
  496. if( favs[href] !== nb) {
  497. nbDiff = (nb - favs[href]);
  498. sNbDiff = "(" + nbDiff + ") ";
  499. hasNoneRead = true;
  500. }
  501. } else {
  502. favs[href] = nb;
  503. localStorage.setItem("favs", JSON.stringify(favs));
  504. }
  505.  
  506. var hrefEnd = fav.children[0].children[0].href;
  507. fav.children[1].children[0].href = hrefEnd;
  508.  
  509. fav.removeChild(fav.children[2]);
  510. fav.removeChild(fav.children[2]);
  511. fav.removeChild(fav.children[2]);
  512. fav.removeChild(fav.children[0]);
  513. var idLi = getId();
  514. innerHTMLFav += "<li id=\"" + idLi + "\">" + sNbDiff + fav.innerHTML + "</li>";
  515.  
  516. if (nbDiff !== 0) {
  517. scanQuote(hrefEnd, nbDiff, idLi);
  518. }
  519. }
  520.  
  521. document.getElementById(idFavoris).innerHTML = innerHTMLFav;
  522. profil.noneRead = hasNoneRead ? "*" : "";
  523. changeTitle();
  524. });
  525. };
  526. setInterval(setFavs, 30000);
  527. setFavs.apply();
  528. }
  529.  
  530. function changeTitle() {
  531. document.title = profil.nbMail + profil.noneRead + profil.quoted + profil.tabName;
  532. }
  533.  
  534. function scanQuote(href, nb, idLi) {
  535. deepScan(href, nb, idLi);
  536. }
  537.  
  538. function deepScan(href, nb, idLi) {
  539.  
  540. httpGetAsync(href, function (html) {
  541.  
  542. var commentaires = html.getElementsByClassName("topic-messages")[0].children;
  543. for (var i = commentaires.length - 1; i > -1 && nb !== 0; i--) {
  544. nb--;
  545. var children = commentaires[i].children[1].children;
  546. if (isQuoted(children[1].innerHTML, children[0].children[1].children[0].innerHTML)) {
  547. document.getElementById(idLi).children[0].style.color = "red";
  548. nb = 0;
  549. profil.quoted = "! ";
  550. break;
  551. }
  552. }
  553.  
  554. if (nb > 0) {
  555. deepScan(getPageFromUrl(href, false) , nb, idLi);
  556. }
  557. changeTitle();
  558.  
  559. });
  560. }
  561.  
  562. function isQuoted(innerHTML, author) {
  563. return stringContents(innerHTML, "https://avenoel.org/profil/" + profil.name + "\"")
  564. || author === "MrPointVult" && stringContents(innerHTML, "@tous")
  565. || stringContents(innerHTML, "@" + profil.name);
  566. }
  567.  
  568. //-----------------------------------------------------
  569. // Topic
  570. //-----------------------------------------------------
  571.  
  572. function traiterTopic() {
  573.  
  574. overloadButtonDeleteTopic();
  575.  
  576. var maxPage = window.location.href;
  577. var lstTopic = document.getElementsByClassName("topic-messages");
  578.  
  579. var trsTopic = lstTopic[0].children;
  580.  
  581. var body = document.body,
  582. html = document.documentElement;
  583. var height = Math.max( body.scrollHeight, body.offsetHeight,
  584. html.clientHeight, html.scrollHeight, html.offsetHeight );
  585.  
  586. var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
  587. var event = function(e) {
  588. if (
  589. textArea !== document.activeElement &&
  590. document.body.scrollHeight === window.scrollY + window.innerHeight
  591. ) {
  592. maxPage = getPageFromUrl(maxPage, true);
  593. httpGetAsync(maxPage, function (html) {
  594.  
  595. var nbPage = html.getElementsByTagName("title")[0].innerHTML.match(/Page [0-9]+ /g);
  596. if(nbPage[0] === "Page 1 ") {
  597. return;
  598. }
  599. var size = lstTopic[0].children.length;
  600. lstTopic[0].innerHTML += "<div>"+nbPage+"</div>" + html.getElementsByClassName("topic-messages")[0].innerHTML;
  601. enhanceListTopicMessage(lstTopic[0].children, size);
  602. });
  603. }
  604. };
  605. window.addEventListener('scroll', event);
  606.  
  607. httpGetAsync(getPageFromUrl(maxPage, false), function (html) {
  608.  
  609. var nbPage = html.getElementsByTagName("title")[0].innerHTML.match(/Page [0-9]+ /g);
  610. if(nbPage[0] === "Page 0 ") {
  611. enhanceListTopicMessage(trsTopic);
  612. return;
  613. }
  614. var messages = html.getElementsByClassName("topic-messages")[0].children;
  615.  
  616. lstTopic[0].insertBefore(createElem(html.getElementsByClassName("topic-messages")[0], "<div>Page actuelle</div>"), lstTopic[0].firstChild);
  617. lstTopic[0].insertBefore(messages[19], lstTopic[0].firstChild);
  618. lstTopic[0].insertBefore(messages[18], lstTopic[0].firstChild);
  619. enhanceListTopicMessage(trsTopic);
  620. });
  621.  
  622. traiterNavBarTopic();
  623. }
  624.  
  625. function enhanceListTopicMessage(trsTopic, start) {
  626. var iTopic = 0;
  627. if (start) {
  628. iTopic = start;
  629. }
  630. for(; iTopic < trsTopic.length; ++iTopic) {
  631. traiterTrTopic(trsTopic[iTopic]);
  632. collapseQuote(trsTopic[iTopic]);
  633. overloadButtons(trsTopic[iTopic]);
  634. }
  635. }
  636.  
  637. function findNewTop(isUp, listTop) {
  638. for(var i = 0; i < listTop.length - 1; ++i) {
  639. if (listTop[i] <= window.scrollY && window.scrollY <= listTop[i + 1]) {
  640. return isUp ? listTop[i] : listTop[i + 1];
  641. }
  642. }
  643. }
  644.  
  645. function traiterNavBarTopic() {
  646.  
  647. var relativePath = "";
  648. getPath().split("-").splice(2).forEach(function(split) {
  649. relativePath += split + "-";
  650. });
  651. relativePath = relativePath.slice(0, -1);
  652.  
  653. var buttons = addButtonToNavBar(["buttonBan"]);
  654. var buttonBan = buttons[0];
  655.  
  656. // Bouton des bans
  657. var isInBan = contentsString(bans, relativePath) != -1;
  658. if (isInBan) {
  659. buttonBan.innerHTML = "DEBAN";
  660. buttonBan.onclick = function() {
  661. deleteFromCache(bans, "bans");
  662. };
  663. } else {
  664. buttonBan.innerHTML = "BAN";
  665. buttonBan.onclick = function() {
  666. addInCache(bans, "bans");
  667. };
  668. }
  669.  
  670. }
  671.  
  672. function addInCache(cacheList, cacheName) {
  673. console.log("addInCache : " + cacheName);
  674. cacheList.push(getPath());
  675. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  676. ajouterBarFav();
  677. traiterNavBarTopic();
  678. }
  679.  
  680. function deleteFromCache(cacheList, cacheName) {
  681. console.log("deleteFromCache : " + cacheName);
  682.  
  683. var relativePath = "";
  684. getPath().split("-").splice(2).forEach(function(split) {
  685. relativePath += split + "-";
  686. });
  687. relativePath = relativePath.slice(0, -1);
  688.  
  689. var i = contentsString(cacheList, relativePath);
  690. if (i !== -1) {
  691. cacheList.splice(i, 1);
  692. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  693. }
  694.  
  695. ajouterBarFav();
  696. traiterNavBarTopic();
  697. }
  698.  
  699. function traiterTrTopic(tr) {
  700.  
  701. if (tr.children.length === 0) {
  702. return;
  703. }
  704.  
  705. if (tr.innerHTML.split("<iframe title=\"YouTube video player\"").length > 20) {
  706. tr.getElementsByClassName("message-content")[0].innerHTML = "<b><i>Message supprimé pour cause de flood.</i></b>";
  707. return;
  708. }
  709.  
  710. var name = tr.getElementsByClassName("message-username")[0].children[0];
  711. if (profilUsers[name.innerHTML]) {
  712. if (profilUsers[name.innerHTML].color) {
  713. name.style.color = profilUsers[name.innerHTML].color;
  714. }
  715. if (profilUsers[name.innerHTML].pdp) {
  716. tr.getElementsByClassName("message-avatar")[0].children[0].src = profilUsers[name.innerHTML].pdp;
  717. }
  718. if (profilUsers[name.innerHTML].isHidePdp) {
  719. tr.children[0].children[0].children[0].src = "http://4.bp.blogspot.com/-MdNpMeXfP3k/UYkDoyQ32VI/AAAAAAAAcNU/q3Dnc5zB4Ic/s1600/Blocage.jpg";
  720. }
  721. if (profilUsers[name.innerHTML].name) {
  722. name.innerHTML = profilUsers[name.innerHTML].name;
  723. }
  724. }
  725.  
  726. var message = null;
  727. var rank = -1;
  728.  
  729. // Suppression des FDP
  730. banProfiles.some(function(connard) {
  731.  
  732. var id = getId();
  733. message = null;
  734. if (hasProfilLink(tr, connard.name)) {
  735. message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  736. }
  737. if (hasProfilAvatar(tr, connard.name)) {
  738. message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  739. }
  740.  
  741. if (message !== null) {
  742. rank = connard.rank;
  743. return true;
  744. }
  745.  
  746. return false;
  747. });
  748.  
  749. if (rank == 2) {
  750. tr.innerHTML = message;
  751. tr.focus();
  752. } else {
  753. addButtonHiddenTopicMessage(tr, rank == 1);
  754. }
  755.  
  756. if (tr.getElementsByTagName("ul")[0]) {
  757. var buttonYoutube = createElem(tr.getElementsByTagName("ul")[0],
  758. "<button style=\"background-color:transparent;border:none;\"><li><img class=\"board-noelshack\" src=\"http://simpleicon.com/wp-content/uploads/music-note-1.png\"></li></button>");
  759.  
  760. buttonYoutube.onclick = function() {
  761. loadYoutube(name.innerHTML);
  762. }
  763. }
  764.  
  765. return tr.offsetTop;//getBoundingClientRect().top + window.pageYOffset;
  766. }
  767.  
  768. function collapseQuote(tr) {
  769.  
  770. var content = tr.getElementsByClassName("message-content")[0];
  771. if (!content) {
  772. return;
  773. }
  774.  
  775. var lines = content.innerHTML.match(/[^\r\n]+/g);
  776.  
  777. var ids = [];
  778. var currentLine;
  779. var lastRank = -1;
  780. var currentRank = -1;
  781. for(var i = lines.length - 1; i > -1; --i) {
  782. currentRank = calculRank(lines[i]);
  783.  
  784. if (lastRank !== -1 && Math.abs(currentRank - lastRank) > 1) {
  785. var err = tr.getElementsByClassName("message-edited hidden-xs")[0];
  786. err.style.display = "";
  787. err.innerHTML = "Erreur lors du masquage des citations.";
  788. return;
  789. }
  790.  
  791. if (lastRank > 0 && currentRank > lastRank) {
  792. lines.splice(i + 1, 0, "</div>");
  793. } else if (currentRank > 0 && currentRank < lastRank) {
  794.  
  795. var idButton = getId();
  796. var idDiv = getId();
  797. var beforeButton = "";
  798. for(var iGt = 0; iGt < currentRank; ++iGt) {
  799. beforeButton += "&gt; ";
  800. }
  801.  
  802. var buttonAll = "";
  803. if (currentRank === 1) {
  804. var idButtonAll = "buttonAll" + getId();
  805. buttonAll = "<button id=\"" + idButtonAll + "\" ></button>";
  806. ids.push({idButton:idButtonAll, idDiv:idDiv});
  807. }
  808.  
  809. var maskInnerHTML = "<span class=\"message-content-quote\">" + beforeButton + "<i><button id=\"" + idButton + "\" ></button>" + buttonAll + "</i></span><div id=\"" + idDiv + "\" >";
  810. ids.push({idButton:idButton, idDiv:idDiv});
  811. lines.splice(i + 1, 0, maskInnerHTML);
  812. }
  813.  
  814. lastRank = currentRank;
  815. }
  816.  
  817. content.innerHTML = lines.join('');
  818. addCollapseEvent(tr, ids);
  819. }
  820.  
  821. function addCollapseEvent(tr, ids) {
  822. ids.forEach(function(id) {
  823. var button = document.getElementById(id.idButton);
  824. button.style.border = "none";
  825. button.innerHTML = ">";
  826. button.style.textAlign = "center";
  827. var div = document.getElementById(id.idDiv);
  828. div.style.display = "none";
  829.  
  830. if (id.idButton.startsWith("buttonAll")) {
  831. button.innerHTML = "=>";
  832. button.onclick = function() {
  833.  
  834. button.innerHTML = button.innerHTML === "&lt;=" ? "=&gt;" : "&lt;=";
  835. var innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  836. var buttonList = div.getElementsByTagName("button");
  837. for (var i = 0; i < buttonList.length; i++) {
  838. buttonList[i].innerHTML = innerHTML;
  839. }
  840.  
  841. var divList = div.getElementsByTagName("div");
  842. var display = button.innerHTML === "&lt;=" ? "" : "none";
  843. div.style.display = display;
  844. for (var j = 0; j < divList.length; j++) {
  845. divList[j].style.display = display;
  846. }
  847.  
  848. button.previousSibling.innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  849.  
  850. };
  851. } else {
  852. button.onclick = function() {
  853.  
  854. button.innerHTML = button.innerHTML === "&lt;" ? "&gt;" : "&lt;";
  855. div.style.display = div.style.display === "none" ? "" : "none";
  856.  
  857. if (button.nextSibling !== null) {
  858. button.nextSibling.innerHTML = button.innerHTML === "&lt;" ? "&lt;=" : "=&gt";
  859. }
  860. };
  861. }
  862. });
  863. }
  864.  
  865. function calculRank(line) {
  866. var rank = -1;
  867. var index;
  868. var matcher = "quote\">&gt; ";
  869.  
  870. while (index != -1) {
  871. rank++;
  872. index = line.indexOf(matcher);
  873. matcher += "&gt; ";
  874. }
  875.  
  876. return rank;
  877. }
  878.  
  879. function addButtonHiddenTopicMessage(tr, isHidden) {
  880.  
  881. var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
  882. if (!aside) {
  883. return;
  884. }
  885. var content = tr.getElementsByClassName("message-content")[0];
  886. var header = tr.getElementsByClassName("message-header")[0];
  887. var ulHeader = header.getElementsByClassName("message-actions")[0];
  888. var footer = tr.getElementsByClassName("message-footer")[0];
  889.  
  890. var idButton = getId();
  891. content.isHidden = isHidden;
  892. var innerButton = content.isHidden ? "Afficher" : "Masquer";
  893. ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
  894.  
  895. var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
  896. var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
  897.  
  898. var button = document.getElementById(idButton);
  899.  
  900. button.style.backgroundColor = "Transparent";
  901. button.style.border = "none";
  902.  
  903. button.onclick = function() {
  904. content.isHidden = !content.isHidden;
  905. button.innerHTML = content.isHidden ? imageUp : imageDown;
  906. content.style.display = content.isHidden ? "none" : "";
  907. footer.style.display = content.isHidden ? "none" : "";
  908. aside.style.display = content.isHidden ? "none" : "";
  909. };
  910. content.isHidden = !content.isHidden;
  911. button.onclick.apply();
  912. }
  913.  
  914. function overloadButtons(tr) {
  915. var header = tr.getElementsByClassName("message-header")[0];
  916. if (!header) {
  917. return;
  918. }
  919.  
  920. var imgs = header.getElementsByTagName("img");
  921. var img;
  922. for(var i = 0; i < imgs.length; ++i) {
  923. if (imgs[i].src === "https://avenoel.org/images/topic/delete.png") {
  924. img = imgs[i];
  925. }
  926. }
  927.  
  928. if (!img) {
  929. return;
  930. }
  931.  
  932. var button = img.parentElement;
  933. var href = button.href;
  934. button.href = "#";
  935. button.onclick = function() {
  936. if (window.confirm("Voulez vous supprimer le message ?")) {
  937. window.location.href = href;
  938. }
  939. };
  940.  
  941. }
  942.  
  943. function overloadButtonDeleteTopic() {
  944.  
  945. var buttons = document.getElementsByClassName("btn btn-danger");
  946. if (!buttons) {
  947. return;
  948. }
  949.  
  950. for(var i = 0; i < buttons.length; ++i) {
  951.  
  952. var button = buttons[i];
  953. button.href2 = button.href;
  954. button.href = "#";
  955. button.onclick = function() {
  956. if (window.confirm("Voulez vous " + this.innerHTML.toLowerCase() + " le topic ?")) {
  957. window.location.href = this.href2;
  958. }
  959. };
  960. }
  961.  
  962. }
  963.  
  964. //-----------------------------------------------------
  965. // Forum
  966. //-----------------------------------------------------
  967.  
  968.  
  969. function traiterForum() {
  970.  
  971. if (window.location.href.indexOf("?") !== -1) {
  972. return;
  973. }
  974.  
  975. var page = Number(getPath().split("/")[4]);
  976. if (!page) {
  977. page = 1;
  978. }
  979. page = (page-1)*2 + page;
  980.  
  981. httpGetAsync("https://avenoel.org/forum/"+(page+1), function (html1) {
  982.  
  983.  
  984. httpGetAsync("https://avenoel.org/forum/"+(page+2), function (html2) {
  985. var innerHTML2 = traiterTrsForum(html2).getElementsByClassName("table table-striped topics")[0].children[1].innerHTML;
  986. document.getElementsByClassName("table table-striped topics")[0].children[1].innerHTML += innerHTML2;
  987.  
  988. });
  989.  
  990. var innerHTML1 = traiterTrsForum(html1).getElementsByClassName("table table-striped topics")[0].children[1].innerHTML;
  991. document.getElementsByClassName("table table-striped topics")[0].children[1].innerHTML += innerHTML1;
  992.  
  993. });
  994.  
  995. traiterTrsForum(document);
  996.  
  997. }
  998.  
  999. function traiterTrsForum(html) {
  1000. var trs = html.getElementsByClassName("table table-striped topics")[0].children[1].children;
  1001. for(var i = 0; i < trs.length; ++i) {
  1002. traiterTrForum(trs[i]);
  1003. }
  1004. return html;
  1005. }
  1006.  
  1007. function traiterTrForum(tr) {
  1008.  
  1009. var name = tr.getElementsByClassName("topics-author")[0].children[0];
  1010. if (profilUsers[name.innerHTML]) {
  1011. if (profilUsers[name.innerHTML].color) {
  1012. name.style.color = profilUsers[name.innerHTML].color;
  1013. }
  1014. if (profilUsers[name.innerHTML].name) {
  1015. name.innerHTML = profilUsers[name.innerHTML].name;
  1016. }
  1017. }
  1018.  
  1019. // Suppression des caracteres ching chong
  1020. // if (tr.innerText.match(/[\u3400-\u9FBF]/) || tr.innerText.match(/[\u0250-\u02AF)]/)) {
  1021. // console.log("Suppression des caracteres ching chong");
  1022. // tr.innerHTML = "";
  1023. // return;
  1024. // }
  1025.  
  1026. var test = [];// document.getElementsByClassName("topic-icon");
  1027. for(var i = 0; i < test.length; ++i) {
  1028. test[i].children[0].children[0].src = "https://i.imgur.com/K5gqpN2.png";
  1029. }
  1030.  
  1031. //
  1032.  
  1033. // Suppression des FDP
  1034. if (banProfiles.some(function(connard) {
  1035. if (hasProfilLink(tr, connard.name)) {
  1036. console.log("Suppression du FDP : " + connard.name);
  1037. tr.innerHTML = "";
  1038. return true;
  1039. }
  1040. return false;
  1041. })) {
  1042. return;
  1043. }
  1044.  
  1045. if (bans.some(function(url) {
  1046. if (hasUrl(tr, url)) {
  1047. console.log("Suppression du sujet : " + url);
  1048. tr.innerHTML = "";
  1049. return true;
  1050. }
  1051. return false;
  1052. })) {
  1053. return;
  1054. }
  1055.  
  1056. if (bansRegex.some(function(regex) {
  1057. if (tr.innerHTML.match(new RegExp(regex, "gm"))) {
  1058. console.log("Suppression du sujet regex : " + regex);
  1059. tr.innerHTML = "";
  1060. return true;
  1061. }
  1062. return false;
  1063. })) {
  1064. return;
  1065. }
  1066.  
  1067. // Surlignage
  1068. if (favProfiles.some(function(surligne) {
  1069. if (hasProfilLink(tr, surligne.name)) {
  1070. console.log("Surlignage : " + surligne.name);
  1071. tr.style.background = colorListProfil[surligne.color];
  1072. return true;
  1073. }
  1074. return false;
  1075. })) {
  1076. return;
  1077. }
  1078.  
  1079. }
  1080.  
  1081. //-----------------------------------------------------
  1082. // Profil
  1083. //-----------------------------------------------------
  1084.  
  1085. function traiterProfil() {
  1086. var isMine = profil.name === document.getElementsByTagName("h2")[0].innerHTML;
  1087. currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
  1088.  
  1089. // Partie droite
  1090. var elem = document.getElementsByClassName("profile-wrapper-right");
  1091.  
  1092. elem[0].innerHTML += "<div " + (isMine ? "hidden" : "") + ">Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div></div>";
  1093. elem[0].innerHTML += "<div>Topic couleur <select id=\"idFavColor\"></select><br/></div>";
  1094. elem[0].innerHTML += "<div>Profil couleur <select id=\"idProfilColor\"></select><br/></div>";
  1095. elem[0].innerHTML += "<div>Profil name <input class=\"profile-biography\" id=\"idProfilName\" type=\"text\" style=\"height: 30px;\" placeholder=\"" + currentProfile + "\"/></div>";
  1096. elem[0].innerHTML += "<div>Profil photo <input class=\"profile-biography\" id=\"idProfilPhoto\" type=\"text\" style=\"height: 30px;\" placeholder=\"Pas de photo\"/></div>";
  1097. elem[0].innerHTML += "<div>Ami : <input class=\"profile-biography\" id=\"idProfilFriend\" type=\"checkbox\" /></div>";
  1098. elem[0].innerHTML += "<div>Cacher pdp : <input class=\"profile-biography\" id=\"idProfilHidePdp\" type=\"checkbox\" /></div>";
  1099.  
  1100. // ami --------------------------------------------------------------
  1101. if (profilUsers[currentProfile] && profilUsers[currentProfile].isFriend) {
  1102. document.getElementById("idProfilFriend").checked = true;
  1103. }
  1104. document.getElementById("idProfilFriend").onclick = function(e) {
  1105. updateFriendProfil(e.currentTarget.checked);
  1106. };
  1107.  
  1108. // pdp --------------------------------------------------------------
  1109. if (profilUsers[currentProfile] && profilUsers[currentProfile].isHidePdp) {
  1110. document.getElementsByClassName("profile-avatar")[0].children[0].src = "http://4.bp.blogspot.com/-MdNpMeXfP3k/UYkDoyQ32VI/AAAAAAAAcNU/q3Dnc5zB4Ic/s1600/Blocage.jpg";
  1111. document.getElementById("idProfilHidePdp").checked = (profilUsers[currentProfile] && profilUsers[currentProfile].isHidePdp);
  1112. }
  1113. document.getElementById("idProfilHidePdp").onclick = function(e) {
  1114. updateHidePdp(e.currentTarget.checked);
  1115. };
  1116.  
  1117. if (profilUsers[currentProfile] && profilUsers[currentProfile].pdp) {
  1118. document.getElementsByClassName("profile-avatar")[0].children[0].src = profilUsers[currentProfile].pdp;
  1119. }
  1120. document.getElementById("idProfilPhoto").onkeypress = function(e) {
  1121. if (e.charCode === 13) {
  1122. updatePhotoProfil(document.getElementById("idProfilPhoto").value);
  1123. }
  1124. };
  1125.  
  1126. // name -------------------------------------------------------------
  1127. if (profilUsers[currentProfile] && profilUsers[currentProfile].name) {
  1128. document.getElementsByClassName("profile-title")[0].children[0].innerHTML = profilUsers[currentProfile].name;
  1129. }
  1130. document.getElementById("idProfilName").onkeypress = function(e) {
  1131. if (e.charCode === 13) {
  1132. renameProfil(document.getElementById("idProfilName").value);
  1133. }
  1134. };
  1135.  
  1136. // color list -------------------------------------------------------
  1137. var colorList = [];
  1138. for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
  1139. colorList.push(iColor);
  1140. }
  1141. // color ------------------------------------------------------------
  1142. var hasColor = false;
  1143. var colorProfil;
  1144. if (profilUsers[currentProfile]) {
  1145. colorProfil = profilUsers[currentProfile].color;
  1146. colorizeProfil(colorProfil);
  1147. }
  1148.  
  1149. createComboBox("idProfilColor", colorList);
  1150. var comboProfilColor = document.getElementById("idProfilColor");
  1151.  
  1152. for (var k = 0; k < comboProfilColor.length; k++) {
  1153. comboProfilColor[k].innerHTML = "";
  1154. comboProfilColor[k].style.backgroundColor = colorListProfil[k];
  1155. }
  1156.  
  1157. if (hasColor) {
  1158. comboProfilColor.selectedIndex = parseInt(color);
  1159. comboProfilColor.style.backgroundColor = colorListProfil[color];
  1160. }
  1161.  
  1162. comboProfilColor.onchange = function(event) {
  1163. colorizeProfil(colorListProfil[event.target.selectedOptions[0].value]);
  1164. };
  1165.  
  1166.  
  1167. // favoris ----------------------------------------------------------
  1168. var isFav = false;
  1169. var color = 0;
  1170. favProfiles.some(function(fav) {
  1171. if (fav.name === currentProfile) {
  1172. isFav = true;
  1173. color = fav.color;
  1174. return true;
  1175. }
  1176. return false;
  1177. });
  1178.  
  1179.  
  1180.  
  1181. createComboBox("idFavColor", colorList);
  1182. var comboFavColor = document.getElementById("idFavColor");
  1183.  
  1184. for (var j = 0; j < comboFavColor.length; j++) {
  1185. comboFavColor[j].innerHTML = "";
  1186. comboFavColor[j].style.backgroundColor = colorListProfil[j];
  1187. }
  1188.  
  1189. if (isFav) {
  1190. comboFavColor.selectedIndex = parseInt(color);
  1191. comboFavColor.style.backgroundColor = colorListProfil[color];
  1192. }
  1193.  
  1194. comboFavColor.onchange = function(event) {
  1195. favProfile(event.target.selectedOptions[0].value);
  1196. };
  1197.  
  1198. // bans ----------------------------------------------------------
  1199. detailRankProfile();
  1200. var isBan = false;
  1201. var rank = 0;
  1202. banProfiles.forEach(function(connard) {
  1203. if (connard.name === currentProfile) {
  1204. isBan = true;
  1205. rank = connard.rank;
  1206. return;
  1207. }
  1208. });
  1209.  
  1210. createComboBox("idBanRank", ["non","0","1","2"]);
  1211. var comboBanRank = document.getElementById("idBanRank");
  1212. if (isBan) {
  1213. comboBanRank.selectedIndex = parseInt(rank) + 1;
  1214. }
  1215. detailRankProfile(rank);
  1216. comboBanRank.onchange = function(event) {
  1217. banProfile(event.target.selectedOptions[0].value);
  1218. };
  1219.  
  1220. // Partie gauche
  1221. var elemLeft = document.getElementsByClassName("profile-wrapper-left")[0];
  1222.  
  1223. var div = document.createElement('div');
  1224. div.innerHTML = "<button>Statistiques</button>";
  1225. var statsButton = div.firstChild;
  1226. elemLeft.appendChild(statsButton);
  1227. statsButton.onclick = function() {window.open('https://avenoel.org/stats/' + currentProfile);};
  1228. div.remove();
  1229.  
  1230. // Partie config
  1231. if (isMine) {
  1232. afficherConfig(isMine);
  1233. }
  1234.  
  1235. }
  1236.  
  1237. function afficherConfig(isMine) {
  1238. var container = document.getElementsByClassName("col-md-7 col-centered profile")[0];
  1239. var editorContainer = container.appendChild(container.children[0].cloneNode(true));
  1240. editorContainer.style.textAlign = "left";
  1241. editorContainer.style.marginTop = "15px";
  1242. editorContainer.innerHTML = "";
  1243. var config = container.appendChild(container.children[0].cloneNode(true));
  1244. config.style.textAlign = "left";
  1245. config.style.marginTop = "15px";
  1246.  
  1247. var idEditor = getId();
  1248. var idTopic = getId();
  1249. var idBannis = getId();
  1250. var idTopicBannis = getId();
  1251. var idCharts = getId();
  1252.  
  1253. config.innerHTML =
  1254. "<div>Liste mots clés de l'éditeur de texte :</div>"+
  1255. "<div id=\"" + idEditor + "\"></div>"+
  1256. "<br>"+
  1257. "<div>Liste mots clés du masques des sujets :</div>"+
  1258. "<div id=\"" + idTopic + "\"></div>"+
  1259. "<br>"+
  1260. "<div>Liste des bannis :</div>"+
  1261. "<div id=\"" + idBannis + "\"></div>"+
  1262. "<br>"+
  1263. "<div>Liste des sujets bannis :</div>"+
  1264. "<div id=\"" + idTopicBannis + "\"></div>";
  1265.  
  1266.  
  1267. addEditorToProfil(editorContainer);
  1268. createConfigEditor(document.getElementById(idEditor));
  1269. createConfigTopic(document.getElementById(idTopic));
  1270. createConfigBannis(document.getElementById(idBannis));
  1271. createConfigTopicBannis(document.getElementById(idTopicBannis));
  1272.  
  1273. }
  1274.  
  1275. function addEditorToProfil(container) {
  1276. if (true) {
  1277. container.style.display = "none";
  1278. }
  1279. httpGetAsync("https://avenoel.org/forum", function (html) {
  1280. var form = html.getElementsByTagName("form")[1];
  1281.  
  1282. //var risi = html.getElementsByClassName("btn risi-wlogo")[0];
  1283. // risi.formAction = "https://avenoel.org/forum/#risibank";
  1284. // console.log(risi.formAction);
  1285.  
  1286. container.appendChild(form.children[2]);
  1287. container.appendChild(form.children[2]);
  1288. container.appendChild(form.children[2]);
  1289. enhanceTextArea();
  1290. });
  1291. }
  1292.  
  1293. function createConfigEditor(container) {
  1294.  
  1295. var lines = [];
  1296. var innerHTML = "<li>";
  1297. regexList.forEach(function (each) {
  1298.  
  1299. var res;
  1300. if (each.res.startsWith("https://")) {
  1301. res = "<img class=\"board-noelshack\" src=\"" + each.res + "\">";
  1302. } else {
  1303. res = each.res;
  1304. }
  1305.  
  1306. var idButton = getId();
  1307. innerHTML +=
  1308. each.reg + " => " + res + space +
  1309. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1310. "</li>" +
  1311. "<li>";
  1312. lines.push({id:idButton, each:each});
  1313. });
  1314.  
  1315. var idButtonPlus = getId();
  1316. var idInputKey = getId();
  1317. var idInputValue = getId();
  1318. innerHTML +=
  1319. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1320. " => " +
  1321. "<input class=\"profile-biography\" id=\"" + idInputValue + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1322. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1323. "</li>";
  1324.  
  1325. container.innerHTML = innerHTML;
  1326.  
  1327. lines.forEach(function (line, i) {
  1328. var button = document.getElementById(line.id);
  1329. button.style.backgroundColor = "Transparent";
  1330. button.style.border = "none";
  1331.  
  1332. button.onclick = function() {
  1333. regexList.splice(i, 1);
  1334. localStorage.setItem("regexList", JSON.stringify(regexList));
  1335. createConfigEditor(container);
  1336. };
  1337. });
  1338.  
  1339.  
  1340. var buttonPlus = document.getElementById(idButtonPlus);
  1341. buttonPlus.style.backgroundColor = "Transparent";
  1342. buttonPlus.style.border = "none";
  1343.  
  1344. buttonPlus.onclick = function() {
  1345. regexList.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  1346. localStorage.setItem("regexList", JSON.stringify(regexList));
  1347. createConfigEditor(container);
  1348. };
  1349. }
  1350.  
  1351. function createConfigTopic(container) {
  1352.  
  1353. var lines = [];
  1354. var innerHTML = "<li>";
  1355. bansRegex.forEach(function (each) {
  1356. var idButton = getId();
  1357. innerHTML +=
  1358. each + space +
  1359. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1360. "</li>" +
  1361. "<li>";
  1362. lines.push({id:idButton, each:each});
  1363. });
  1364.  
  1365. var idButtonPlus = getId();
  1366. var idInputKey = getId();
  1367. innerHTML +=
  1368. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1369. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1370. "</li>";
  1371.  
  1372. container.innerHTML = innerHTML;
  1373.  
  1374. lines.forEach(function (line, i) {
  1375. var button = document.getElementById(line.id);
  1376. button.style.backgroundColor = "Transparent";
  1377. button.style.border = "none";
  1378.  
  1379. button.onclick = function() {
  1380. bansRegex.splice(i, 1);
  1381. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  1382. createConfigTopic(container);
  1383. };
  1384. });
  1385.  
  1386.  
  1387. var buttonPlus = document.getElementById(idButtonPlus);
  1388. buttonPlus.style.backgroundColor = "Transparent";
  1389. buttonPlus.style.border = "none";
  1390.  
  1391. buttonPlus.onclick = function() {
  1392. bansRegex.push(document.getElementById(idInputKey).value);
  1393. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  1394. createConfigTopic(container);
  1395. };
  1396.  
  1397. }
  1398.  
  1399. function createConfigBannis(container) {
  1400.  
  1401. var lines = [];
  1402. var idButtonPlus = getId();
  1403. var idInputKey = getId();
  1404.  
  1405. var innerHTML =
  1406. // "<li><input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1407. // "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1408. // "</li>"+
  1409. "<ul style=\" columns: 3; -webkit-columns: 3; -moz-columns: 3;\">";
  1410.  
  1411. banProfiles.forEach(function (each) {
  1412. var idButton = getId();
  1413. innerHTML +=
  1414. "<li>"+
  1415. each.name + " / " + each.rank + space +
  1416. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1417. "</li>";
  1418. lines.push({id:idButton, each:each});
  1419. });
  1420. innerHTML += "</ul>";
  1421. container.innerHTML = innerHTML;
  1422.  
  1423. lines.forEach(function (line, i) {
  1424. var button = document.getElementById(line.id);
  1425. button.style.backgroundColor = "Transparent";
  1426. button.style.border = "none";
  1427.  
  1428. button.onclick = function() {
  1429. banProfiles.splice(i, 1);
  1430. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1431. createConfigBannis(container);
  1432. };
  1433. });
  1434.  
  1435. // var buttonPlus = document.getElementById(idButtonPlus);
  1436. // buttonPlus.style.backgroundColor = "Transparent";
  1437. // buttonPlus.style.border = "none";
  1438.  
  1439. // buttonPlus.onclick = function() {
  1440. // banProfiles.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  1441. // localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1442. // createConfigBannis(container);
  1443. // };
  1444. }
  1445.  
  1446. function createConfigTopicBannis(container) {
  1447.  
  1448.  
  1449. var lines = [];
  1450. var innerHTML = "";
  1451. bans.forEach(function (each) {
  1452. var idButton = getId();
  1453. innerHTML += "<li>"+
  1454. each + space +
  1455. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1456. "</li>";
  1457. lines.push({id:idButton, each:each});
  1458. });
  1459.  
  1460. container.innerHTML = innerHTML;
  1461.  
  1462. lines.forEach(function (line, i) {
  1463. var button = document.getElementById(line.id);
  1464. button.style.backgroundColor = "Transparent";
  1465. button.style.border = "none";
  1466.  
  1467. button.onclick = function() {
  1468. bans.splice(i, 1);
  1469. localStorage.setItem("bans", JSON.stringify(bans));
  1470. createConfigTopicBannis(container);
  1471. };
  1472. });
  1473.  
  1474. }
  1475.  
  1476. function updateHidePdp(isChecked) {
  1477. if (isChecked) {
  1478. updateProfilUser("isHidePdp", isChecked);
  1479. } else {
  1480. if (profilUsers[currentProfile]) {
  1481. delete profilUsers[currentProfile].isHidePdp;
  1482. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1483. }
  1484. }
  1485. document.getElementsByClassName("profile-avatar")[0].children[0].src = "http://4.bp.blogspot.com/-MdNpMeXfP3k/UYkDoyQ32VI/AAAAAAAAcNU/q3Dnc5zB4Ic/s1600/Blocage.jpg";
  1486. }
  1487.  
  1488. function updateFriendProfil(isChecked) {
  1489. if (isChecked) {
  1490. updateProfilUser("isFriend", isChecked);
  1491. } else {
  1492. if (profilUsers[currentProfile]) {
  1493. delete profilUsers[currentProfile].isFriend;
  1494. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1495. }
  1496. }
  1497. }
  1498.  
  1499. function updatePhotoProfil(src) {
  1500. if (src.trim().length === 0) {
  1501. if (profilUsers[currentProfile]) {
  1502. delete profilUsers[currentProfile].pdp;
  1503. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1504. }
  1505. } else {
  1506. updateProfilUser("pdp", src.trim());
  1507. }
  1508. document.getElementsByClassName("profile-avatar")[0].children[0].src = src;
  1509. }
  1510.  
  1511. function renameProfil(name) {
  1512. if (name.trim().length === 0) {
  1513. if (profilUsers[currentProfile]) {
  1514. delete profilUsers[currentProfile].name;
  1515. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1516. }
  1517. name = currentProfile;
  1518. } else {
  1519. updateProfilUser("name", name.trim());
  1520. }
  1521. document.getElementsByClassName("profile-title")[0].children[0].innerHTML = name;
  1522. }
  1523.  
  1524. function colorizeProfil(color) {
  1525. document.getElementsByClassName("profile-title")[0].children[0].style.color = color;
  1526. updateProfilUser("color", color);
  1527. document.getElementById("idProfilColor").style.backgroundColor = color;
  1528. }
  1529.  
  1530. function updateProfilUser(property, value) {
  1531. if (!profilUsers[currentProfile]) {
  1532. profilUsers[currentProfile] = {};
  1533. }
  1534. profilUsers[currentProfile][property] = value;
  1535. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1536. }
  1537.  
  1538. function favProfile(color) {
  1539. console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
  1540.  
  1541. var index = -1;
  1542. for(var i = 0; i < favProfiles.length; ++i) {
  1543. if (stringContents(favProfiles[i].name, currentProfile)) {
  1544. index = i;
  1545. break;
  1546. }
  1547. }
  1548.  
  1549. if (index !== -1) {
  1550. favProfiles.splice(index, 1);
  1551. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1552. }
  1553.  
  1554. if (color !== "0") {
  1555. favProfiles.push({name:currentProfile, color:color});
  1556. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1557. }
  1558.  
  1559. document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
  1560. }
  1561.  
  1562. function banProfile(rank) {
  1563. console.log("banProfile : " + currentProfile + ", rang : " + rank);
  1564.  
  1565. var index = -1;
  1566. for(var i = 0; i < banProfiles.length; ++i) {
  1567. if (stringContents(banProfiles[i].name, currentProfile)) {
  1568. index = i;
  1569. break;
  1570. }
  1571. }
  1572.  
  1573. if (index !== -1) {
  1574. banProfiles.splice(index, 1);
  1575. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1576. }
  1577.  
  1578. if (rank !== "non") {
  1579. banProfiles.push({name:currentProfile, rank:rank});
  1580. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1581. }
  1582.  
  1583. detailRankProfile(rank);
  1584. }
  1585.  
  1586. function detailRankProfile(rank) {
  1587. var innerHTML;
  1588. if (rank === "0") {
  1589. innerHTML = "Ses sujets sont supprimés.";
  1590. } else if (rank === "1") {
  1591. innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
  1592. } else if (rank === "2") {
  1593. innerHTML = "Ses sujets et messages sont supprimés.";
  1594. } else {
  1595. innerHTML = "Non banni.";
  1596. }
  1597.  
  1598. document.getElementById("idBanRankDetail").innerHTML = innerHTML;
  1599. }
  1600.  
  1601. //-----------------------------------------------------
  1602. // Messagerie
  1603. //-----------------------------------------------------
  1604.  
  1605. function traiterMessagerie() {
  1606.  
  1607. createFriendList();
  1608. overideDeleteButtonMessagerie();
  1609. var title = document.getElementsByTagName("thead")[0].children[0];
  1610. title.insertBefore(title.children[1].cloneNode(true), title.children[1]);
  1611. title.children[1].innerHTML = "COMMENTAIRE";
  1612.  
  1613. var mails = document.getElementsByTagName("tbody")[0].children;
  1614. for(var i = 0; i < mails.length; ++i) {
  1615. mails[i].insertBefore(mails[i].children[1].cloneNode(true), mails[i].children[1]);
  1616. getLastCommenter(mails[i].children[1], mails[i].children[0].children[0].href);
  1617. }
  1618.  
  1619. }
  1620.  
  1621. function createFriendList() {
  1622. var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
  1623. if (barFav.length === 0) {
  1624. return;
  1625. }
  1626.  
  1627. //" <div style=\"display:flex;justify-content:center;align-items:center;\">"+
  1628.  
  1629. var idFriendList = getId();
  1630.  
  1631. var listDiv = barFav[0].children[0];
  1632. listDiv.classList = [];
  1633. listDiv.style.marginBottom = "20px";
  1634. listDiv.innerHTML =
  1635. "<section>"+
  1636. "<div id=\""+idFriendList+"\"></div>"+
  1637. "</section>";
  1638.  
  1639. var sansAmi = true;
  1640. var innerHTML = "Liste d'amis :";
  1641. for (var user in profilUsers) {
  1642. if (profilUsers[user].isFriend) {
  1643. sansAmi = false;
  1644. innerHTML +=
  1645. "<li>"+
  1646. " <span class=\"message-username \"><a href=\"https://avenoel.org/profil/" + user + "\" target=\"_blank\">" + user + "</a></span>"+
  1647. " <span style=\"height:20px; width:20px;\">"+
  1648. " <button id=\""+user+"\" style=\"background-color:transparent;border:none;\">"+
  1649. " <img src=\"https://www.memoclic.com/medias/var/2014-10/Courrier-Windows-8.png\" style=\"height:20px; width:20px;\">"+
  1650. " </button>"+
  1651. " </span>"+
  1652. "</li>";
  1653. }
  1654. }
  1655.  
  1656. if (sansAmi) {
  1657. innerHTML += "<img src=\"http://www.mon-diplome.fr/Diplome/700-291025-Diplome+du+sans+ami+++amie+++amis+++amies.jpg\" style=\"height:100%; width:100%;\">";
  1658. }
  1659. document.getElementById(idFriendList).innerHTML = innerHTML;
  1660.  
  1661. var input = document.getElementsByTagName("input")[1];
  1662. for (var user in profilUsers) {
  1663. if (profilUsers[user].isFriend) {
  1664. document.getElementById(user).onclick = function(event) {
  1665. input.value = event.currentTarget.id;
  1666. };
  1667. }
  1668. }
  1669. }
  1670.  
  1671. function onclickFirendMail(friend) {
  1672. console.log(friend);
  1673. }
  1674.  
  1675. function getLastCommenter(node, href) {
  1676. var replace = node.children[0].innerHTML;
  1677. node.innerHTML = node.innerHTML.replace(replace, "error").replace(replace, "error");
  1678. replace = "error";
  1679.  
  1680. httpGetAsync(href, function (html) {
  1681.  
  1682. var commentaires = html.getElementsByClassName("topic-messages")[0].children;
  1683. var name = commentaires[commentaires.length-1].getElementsByClassName("message-username")[0].children[0].innerHTML;
  1684. node.innerHTML = node.innerHTML.replace(replace, name).replace(replace, name);
  1685.  
  1686. });
  1687.  
  1688. }
  1689.  
  1690. function overideDeleteButtonMessagerie() {
  1691. var button = document.getElementsByClassName("btn btn-danger")[0];
  1692. if (!button) {
  1693. return;
  1694. }
  1695. button.parentElement.onsubmit = function() {
  1696. return window.confirm("Voulez vous quittez le MP ?");
  1697. };
  1698. }
  1699.  
  1700. //-----------------------------------------------------
  1701. // Stats
  1702. //-----------------------------------------------------
  1703. function traiterStats() {
  1704.  
  1705. currentProfile = getPath().split("/")[4];
  1706. document.title = "Statistiques - " + currentProfile;
  1707. deleteElement(document.getElementsByClassName("nav navbar-nav navbar-right hidden-xs hidden-sm navbar-user")[0]);
  1708. deleteElement(document.getElementsByTagName("img")[1]);
  1709.  
  1710. var idCharts = getId();
  1711. document.getElementsByClassName("row container-content")[0].innerHTML =
  1712. "<div class=\"col-xs-12 col-sm-12 col-md-9\">"+
  1713. "<section style=\"text-align: center;\">"+
  1714. "<div class=\"topic-messages\">Messages postés :</div>"+
  1715. "<div id=\"" + idCharts + "\"><br/><div class=\"loader\" >"+imgLivraison+"</div></div>"+
  1716. "<br>"+
  1717. "<section>"+
  1718. "</div>";
  1719.  
  1720. createChartsEditor(idCharts);
  1721.  
  1722. }
  1723.  
  1724. var count = 0;
  1725. function createChartsEditor(idCharts) {
  1726.  
  1727. //var dateStart = new Date(2018, 3 - 1, 30);
  1728. var dateStart = new Date();
  1729. dateStart.setHours(0,0,0,0);
  1730. var dateEnd;
  1731. if (!dateEnd) {
  1732. dateEnd = new Date();
  1733. dateEnd.setDate(dateEnd.getDate() + 1);
  1734. dateEnd.setHours(0,0,0,0);
  1735. }
  1736.  
  1737. var currentDate = new Date(dateStart.getTime());
  1738. var labelsArray = {};
  1739. while (currentDate < dateEnd) {
  1740. labelsArray[currentDate.getString().splice(13, 6, "h")] = 0;
  1741. currentDate.addHours(1);
  1742. }
  1743.  
  1744. findAllTopicsBetweenDates(0, dateStart, dateEnd, labelsArray);
  1745.  
  1746.  
  1747.  
  1748. setTimeout(function () {
  1749. console.log(count);
  1750. var labels = [];
  1751. var data = [];
  1752. for (var prop in labelsArray) {
  1753. data.push(labelsArray[prop]);
  1754. labels.push(prop);
  1755. }
  1756.  
  1757. var config = {
  1758. label: 'Nombre de commentaires',
  1759. labels: labels,
  1760. data: data
  1761. //labels: ["a", "b", "c", "d", "e", "f"],
  1762. //data: [12, 19, 3, 5, 2, 3]
  1763. };
  1764. //http://www.chartjs.org/docs/latest/charts/line.html
  1765. createChartLine(document.getElementById(idCharts), config);
  1766. }, 10000);
  1767.  
  1768. }
  1769.  
  1770. function findAllTopicsBetweenDates(page, dateStart, dateEnd, labelsArray) {
  1771.  
  1772. httpGetApiAsync("topics?size=50", function(res1) {
  1773.  
  1774. for(var i = 0; i < res1.data.length; ++i) {
  1775.  
  1776. var date = new Date(res1.data[i].updated_at);
  1777. if (date > dateStart && date < dateEnd) {
  1778.  
  1779. for(var j = 0; j < (res1.data[i].messages_count[0].aggregate/50); ++j) {
  1780.  
  1781. httpGetApiAsync("messages?reverse=true&with_user=true&size=50&topic_id="+res1.data[i].id+"&start=" + (j*50), function(res2) {
  1782. count = count+1;
  1783. for(var i = 0; i < res2.messages.length; ++i) {
  1784.  
  1785. if (res2.messages[i].user.username === currentProfile) {
  1786.  
  1787. var messageDate = res2.messages[i].updated_at;
  1788. var date = new Date(messageDate);
  1789. if (date > dateStart && date < dateEnd) {
  1790. labelsArray[date.getString().splice(13, 6, "h")] = labelsArray[date.getString().splice(13, 6, "h")] + 1;
  1791. }
  1792.  
  1793. }
  1794. }
  1795. });
  1796. }
  1797. }
  1798. }
  1799. });
  1800.  
  1801. }
  1802.  
  1803. //-----------------------------------------------------
  1804. // Utils
  1805. //-----------------------------------------------------
  1806.  
  1807. function deleteElement(element) {
  1808. element.outerHTML = "";
  1809. delete element;
  1810. }
  1811.  
  1812. function createImageButton(idButton, buttonHtml) {
  1813. var button = document.getElementById(idButton);
  1814. button.innerHTML = buttonHtml;
  1815. return button;
  1816. }
  1817.  
  1818. function createComboBox(idParent, list) {
  1819. var sel = document.getElementById(idParent);
  1820. var optionoption = null;
  1821.  
  1822. for(i = 0; i < list.length; i++) {
  1823.  
  1824. optionoption = document.createElement('option');
  1825. optionoption.value = list[i];
  1826. optionoption.innerHTML = list[i];
  1827. sel.appendChild(optionoption);
  1828. }
  1829. return sel;
  1830. }
  1831.  
  1832. function httpGetAsync(theUrl, callback) {
  1833. var xmlHttp = new XMLHttpRequest();
  1834. xmlHttp.onreadystatechange = function() {
  1835. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  1836. callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
  1837. };
  1838. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  1839. xmlHttp.send(null);
  1840. }
  1841.  
  1842. function httpGetApiAsync(path, callback) {
  1843. var xmlHttp = new XMLHttpRequest();
  1844. xmlHttp.onreadystatechange = function() {
  1845. if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  1846. callback(JSON.parse(xmlHttp.responseText));
  1847. }
  1848. };
  1849. xmlHttp.open("GET", "https://avenoel.org/api/v1/" + path, true); // true for asynchronous
  1850. xmlHttp.send(null);
  1851. }
  1852.  
  1853. function contentsString(list, match) {
  1854. for(var i = 0; i < list.length; ++i) {
  1855. if (stringContents(list[i], match)) {
  1856. return i;
  1857. }
  1858. }
  1859. return -1;
  1860. }
  1861.  
  1862. function getPath() {
  1863. return url + window.location.pathname;
  1864. }
  1865.  
  1866. function designTopButton(button) {
  1867. button.style.color = "white";
  1868. button.style.backgroundColor = "transparent";
  1869. button.style.border = "none";
  1870. }
  1871.  
  1872. function hasProfilLink(elem, name) {
  1873. return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
  1874. }
  1875.  
  1876. function hasProfilAvatar(elem, name) {
  1877. return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
  1878. }
  1879.  
  1880. function hasUrl(elem, url) {
  1881. return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
  1882. }
  1883.  
  1884. function stringContents(string, match) {
  1885. return string.indexOf(match) !== -1;
  1886. }
  1887.  
  1888. function addButtonToNavBar(names) {
  1889.  
  1890. var buttons = [];
  1891.  
  1892. if (document.getElementById(names[0]) === null) {
  1893. var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
  1894. var innerHTML = "";
  1895. names.forEach(function(name) {
  1896. innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
  1897. });
  1898. navbar[0].innerHTML += innerHTML;
  1899. names.forEach(function(name) {
  1900. designTopButton(document.getElementById(name));
  1901. });
  1902. }
  1903.  
  1904. names.forEach(function(name) {
  1905. buttons.push(document.getElementById(name));
  1906. });
  1907.  
  1908. return buttons;
  1909. }
  1910.  
  1911. function getId() {
  1912. return "id" + id++;
  1913. }
  1914.  
  1915. function getPageFromUrl(url, next) {
  1916. var split = url.split("-");
  1917. if (next) {
  1918. split[1]++;
  1919. }else {
  1920. split[1]--;
  1921. }
  1922. return split.join("-");
  1923.  
  1924. }
  1925.  
  1926. function createChartLine(container, config) {
  1927.  
  1928. console.log(config.data);
  1929. var idChart = getId();
  1930. if (!document.getElementById(idChart)) {
  1931. container.innerHTML = "<canvas id=\"" + idChart + "\" width=\"400\" height=\"400\"></canvas>";
  1932. }
  1933.  
  1934. var ctx = document.getElementById(idChart).getContext('2d');
  1935. var myChart = new Chart(ctx, {
  1936. type: 'line',
  1937. data: {
  1938. labels: config.labels,
  1939. datasets: [{
  1940. label: config.label,
  1941. data: config.data,
  1942. backgroundColor: [
  1943. 'rgba(255, 99, 132, 0.2)'
  1944. ],
  1945. borderColor: [
  1946. 'rgba(255,99,132,1)'
  1947. ],
  1948. borderWidth: 1
  1949. }]
  1950. },
  1951. options: {
  1952. scales: {
  1953. yAxes: [{
  1954. ticks: {
  1955. beginAtZero:true
  1956. }
  1957. }]
  1958. }
  1959. }
  1960. });
  1961. }
  1962.  
  1963. function createElem(parent, innerHTML) {
  1964. var div = document.createElement('div');
  1965. div.innerHTML = innerHTML;
  1966. var elem = div.firstChild;
  1967. parent.appendChild(elem);
  1968. div.remove();
  1969. return elem;
  1970. }
  1971.  
  1972. function invertColor(hex) {
  1973. // invert color components
  1974. var r = (255 - parseInt(hex.slice(4, 7))),
  1975. g = (255 - parseInt(hex.slice(9, 12))),
  1976. b = (255 - parseInt(hex.slice(14, 17)));
  1977. return "rgb("+r+", "+g+", "+b+")";
  1978. }
  1979.  
  1980. function addStyle() {
  1981.  
  1982. var colorBody = window.getComputedStyle(document.getElementsByTagName("body")[0]).getPropertyValue( "background-color" );
  1983.  
  1984. var css =
  1985. "ul li a:visited {color: grey;}"+
  1986. ".loader { animation: spin 2s linear infinite; display: inline-block;}"+
  1987. "@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); }}"+
  1988. "#idBtnScrollBackUp { display: none; position: fixed; bottom: 80px; left: 30px; z-index: 99; font-size: 18px; border: none; outline: none; background-color: "+colorBody+"; color: white; cursor: pointer; border-radius: 4px;}"+
  1989. "#idBtnScrollBackUp:hover { background-color: "+invertColor(colorBody)+";}"+
  1990. "#idBtnScrollBackDown { -webkit-transform: scaleY(-1); position: fixed; bottom: 20px; left: 30px; z-index: 99; font-size: 18px; border: none; outline: none; background-color: "+colorBody+"; color: white; cursor: pointer; border-radius: 4px;}"+
  1991. "#idBtnScrollBackDown:hover { background-color: "+invertColor(colorBody)+";}"
  1992. ;
  1993.  
  1994. GM_addStyle(css);
  1995. }
  1996.  
  1997. //-----------------------------------------------------
  1998. // Patch
  1999. //-----------------------------------------------------
  2000. //
  2001. // https://openuserjs.org/scripts/ImThatGuy/AvenoelExt/source
  2002. // https://avenoel.org/topic/40062-1-api-documentation-de-lapi-davenoel
  2003. // https://pastebin.com/raw/geMuZm39
  2004. var version = "3.22.1";
  2005. // 3.23.0 : Pastebin => pastebin
  2006. // 3.22.1 : Pastebin => pastebin
  2007. // 3.22.0 : Pastebin => https://pastebin.com/raw/cVSGw209
  2008. // + possibilite de citer quelqu'un avec @NomDeProfil (Apparaitra en rouge dans les favoris, si le sujet est en favoris)
  2009. // + gestion du bug des citations
  2010. // + correction du bug de la rechercher des sujets
  2011. // + deplacement du bonton musique
  2012. // 3.21.1 : Pastebin => https://pastebin.com/raw/hc3LYY6S
  2013. // + correction d'un bug sur la 3.21.0 dans la 1ere page
  2014. // 3.21.0 : Pastebin => https://pastebin.com/raw/CiP1fTge
  2015. // + ajout des 2 derniers commentaires de la page précédente
  2016. // 3.20.1 : Pastebin => https://pastebin.com/raw/h2TSHh2H
  2017. // + changement des images des boutons pour aller en haut/bas de la page
  2018. // 3.20.0 : Pastebin => https://pastebin.com/raw/rA2j1K3j
  2019. // + affichage des musiques de profil
  2020. // 3.19.0 : Pastebin => https://pastebin.com/raw/ZYmhNy7G
  2021. // + ajout des boutons pour aller en haut/bas de la page
  2022. // 3.18.0 : Pastebin => https://pastebin.com/raw/cWNkPAfe
  2023. // + Ajout des statistiques à partir du profile
  2024. // 3.17.2 : Pastebin => https://pastebin.com/raw/WV7jEvJh
  2025. // + antiflood moins restrictif
  2026. // 3.17.1 : Pastebin => https://pastebin.com/raw/F5xzCrFn
  2027. // + correction d'encodage pastebin
  2028. // 3.17.0 : Pastebin => https://pastebin.com/raw/bM2CsLGb
  2029. // + correction bug 3.16.0
  2030. // 3.16.0 : Pastebin => https://pastebin.com/raw/NwTQS5mX
  2031. // + optimisation de la liste des sujets
  2032. // + ajout d'un raccourci clavier pour la risibank
  2033. // 3.15.0 : Pastebin => https://pastebin.com/raw/Nm0nTsb2
  2034. // 3.14.0 : Pastebin => https://pastebin.com/raw/9qhpri2C
  2035. // + affichage de 3 pages au lieu d'un pour les sujets.
  2036. // 3.13.0 : Pastebin => https://pastebin.com/raw/tid89WKZ
  2037. // + gestion des sujets bannis
  2038. // 3.12.0 : Pastebin => https://pastebin.com/raw/eyyM9HKm
  2039. // + modif de l'affichage de la version avec images random
  2040. // 3.11.1 : Pastebin => https://pastebin.com/raw/JpfgCQKH
  2041. // + correction bug (les pages d'un topic déjà visitées sont grisées)
  2042. // 3.11.0 : Pastebin => https://pastebin.com/raw/20u9Q15N
  2043. // + les pages d'un topic déjà visitées sont grisées.
  2044. // 3.10.2 : Pastebin => sdfsdf
  2045. // + correction du bug d'affichage de la mise à jour
  2046. // 3.10.1 : Pastebin => https://pastebin.com/raw/D9r4eAax
  2047. // + correction (risitas fav donc l'éditeur de texte)
  2048. // 3.10.0 : Pastebin => https://pastebin.com/raw/SAXEV6L5
  2049. // + risitas fav donc l'éditeur de texte
  2050. // 3.9.0 : Pastebin => https://pastebin.com/raw/bUvBDs7z
  2051. // + possibilité de masquer la pdp
  2052. // 3.8.0 : Pastebin => https://pastebin.com/raw/BFjHXUtX
  2053. // + ajout d'une liste d'ami dans la messagerie
  2054. // 3.7.0 : Pastebin => https://pastebin.com/raw/A1U8UXs5
  2055. // + affichage du dernier commentateur d'un MP
  2056. // 3.6.0 : Pastebin => https://pastebin.com/raw/QDRm7nQn
  2057. // + affichage sur l'onglet quand un topic en favoris a un nouveau message
  2058. // + affichage sur l'onglet quand un topic en favoris vous cite
  2059. // 3.5.0 : Pastebin => https://pastebin.com/raw/KWMc09GP
  2060. // + changement des pdp de profil
  2061. // 3.4.0 : Pastebin => https://pastebin.com/raw/aSCAu6hA
  2062. // + changement des noms de profil
  2063. // + changement des couleurs de profil
  2064. // + suppression du controle des caractères ching chong et tamoul
  2065. // 3.3.2 : Pastebin => https://pastebin.com/raw/tHBFbsmW
  2066. // + suppression des caractere tamoul
  2067. // 3.3.1 : Pastebin => https://pastebin.com/raw/L4U0Sd1Z
  2068. // + correction du bug sur les surcharges des boutons
  2069. // 3.3.0 : Pastebin => https://pastebin.com/raw/2RVx8RGc
  2070. // + inifinte scroll
  2071. // + correction bug sur les favoris en citation
  2072. // 3.2.0 : Pastebin => https://pastebin.com/raw/9tfLr09X
  2073. // + correction du bug sur les url avec cuck
  2074. // + le favoris est surligné en rouge quand on est cité
  2075. // 3.1.0 : Pastebin => https://pastebin.com/gFPB9jJA
  2076. // + fin de la gestion des configs des données en cache
  2077. // 3.0.0 : Pastebin => https://pastebin.com/6nFzmeFp
  2078. // + début de la page de config dans le profil
  2079. // + Ajout de la gestion des mots clés éditeur dans le profil
  2080. // 2.6.0 : Pastebin => https://pastebin.com/17GWSM7A
  2081. // + initialisation de la page de configuration de l'appli
  2082. // + ajout du ban de topic par mots clés
  2083. // + optimisation de l'affichage des sujets
  2084. // 2.5.0 : Pastebin => https://pastebin.com/JKKB1RJi
  2085. // + ajout d'une liste de mots clés qui seront transformés dans l'éditeur.
  2086. // 2.4.0 : Pastebin => https://pastebin.com/JCfGHLZ4
  2087. // + ajout des dialogs de confirmation pour la suppression des topics/messages et ignorer.
  2088. // + ajout des modifs dans la notifs des patchs.
  2089. // 2.3.0 : Pastebin => https://pastebin.com/QXe2AJ6v
  2090. // + Ajout d'une popup de confirmation pour quitter les MP
  2091. // 2.2.0 : Pastebin => https://pastebin.com/0gPthPD4
  2092. // + ajout d'un bouton pour afficher/masquer toutes les citations.
  2093. // + amélioration de l'affichage de la nouvelle version
  2094. // 2.1.0 : https://pastebin.com/T2dP5ryX
  2095. // + controle de la version
  2096. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  2097. // + controle de la version
  2098. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  2099. // 2.0.8 : Pastebin => https://pastebin.com/21a6u01a
  2100. // + correction du bug sur les citations (redirection bas de page)
  2101. // 2.0.7 : Pastebin => https://pastebin.com/cD6VqLUY
  2102. // + correction d'un bug sur la barre des favoris
  2103. // + ajout de nouvelles actions dans l'éditeur de texte
  2104. // + la barre des courriers est rafraichie toutes les 30s
  2105. // 2.0.6 : Pastebin => https://pastebin.com/GvTLjLaF
  2106. // + l'élément favoris/courrier se déplace avec le scroll
  2107. // 2.0.5 : Pastebin => https://pastebin.com/pNqRphzh
  2108. // + ajout du nombre de courriers non lus sur l'onglet
  2109. // + possibilité d'afficher/masquer les citiations (masquées par défaut)
  2110. // 2.0.4 : Pastebin => https://pastebin.com/4mCdppfi
  2111. // + affichage de la liste des favoris dans les topics noirs
  2112. // + correction bug sur les BL
  2113. // + optimisation des listes
  2114. // 2.0.3 : Pastebin =>https://pastebin.com/nPvLrBbV
  2115. // + correction du bug d'affichage des courriers
  2116. // 2.0.2 : Pastebin => https://pastebin.com/haqi3XRa
  2117. // + Modification du bouton pour afficher/masquer
  2118. // 2.0.1 : Pastebin => https://pastebin.com/vNmgUrCs
  2119. // + Le clique sur le favoris emmene à la dernière page
  2120. // 2.0.0 : Pastebin => https://pastebin.com/eHCt5h8E
  2121. // + Prise en compte de la liste de favoris (affichage reste à droite)
  2122. // L'icone du fichier n'est pas encore mise
  2123. // + Changement du bouton afficher/masquer un commentaire.
  2124. // 1.1.0 : Pastebin => https://pastebin.com/85F6ydsC
  2125. // + gestion de la lovelist sur les profils
  2126. // + plus besoin d'aller dans le code pour gérer ses listes
  2127. // 1.0.3 : Pastebin => https://pastebin.com/RNWPdyyF
  2128. // + suppression de 'Courriers' quand la liste est vide
  2129. // + gestion de la banlist sur les profils
  2130. // 1.0.2 : https://pastebin.com/TJzUnw69
  2131. // + ajout de la liste des messages non lus au niveau de la barre des favs
  2132. // 1.0.1 : https://pastebin.com/mFv7z7wb
  2133. // + correction du bug des bans de topics
  2134. // + detection du favoris/ban à chaque page du topic
  2135. // 1.0.0 : https://pastebin.com/bjVmYYgM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement