Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.47 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AveNoel
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.7.0
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://avenoel.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. //-----------------------------------------------------
  12. // TODO list
  13. //-----------------------------------------------------
  14. //classer les MPs en catégorie
  15. //voir ce que je peux faire des vidéos (possible de synchoniser ?)
  16. //-----------------------------------------------------
  17.  
  18. //Profils
  19. var regexList;
  20. var bansRegex;
  21. var profilUsers;
  22. var favProfiles;
  23. var banProfiles;
  24. var currentProfile;
  25. var colorListProfil = [
  26. "White",
  27. "LightBlue",
  28. "LightCoral",
  29. "LightCyan",
  30. "LightGoldenRodYellow",
  31. "LightGrey",
  32. "LightGreen",
  33. "LightPink",
  34. "LightSalmon",
  35. "LightSeaGreen",
  36. "LightSkyBlue",
  37. "LightSlateGrey",
  38. "LightSteelBlue"
  39. ];
  40.  
  41. //Topic
  42. var favs;
  43. var bans;
  44.  
  45. // Global
  46. var id = 0;
  47. var profil = {name:"rien", quoted:"", noneRead:"", nbMail:"", tabName:document.title};
  48. const space = "&nbsp";
  49. const url = "https://avenoel.org";
  50. const imgQuote = "<img src=\"/images/topic/quote.png\" alt=\"Icône citation\" width=\"20\">";
  51. const imgEdit = "<img src=\"/images/topic/edit.png\" alt=\"Icône éditer\" title=\"Éditer le message\" width=\"20\">";
  52. const imgDelete = "<img src=\"/images/topic/delete.png\" alt=\"Icône suppression\" width=\"20\">";
  53.  
  54. (function() {
  55. 'use strict';
  56.  
  57. var t0 = performance.now();
  58.  
  59. //debugger;
  60. //localStorage.removeItem("favs");
  61. //localStorage.removeItem("bans");
  62. //localStorage.removeItem("favProfiles");
  63. //localStorage.removeItem("banProfiles");
  64. //localStorage.removeItem("profilUsers");
  65.  
  66. initProfil();
  67. initFunctions();
  68. setInterval(initCache, 1500);
  69. initCache();
  70.  
  71. var path = window.location.pathname;
  72.  
  73. if (path.startsWith('/profil')) {
  74. traiterProfil();
  75. } else {
  76. ajouterBarFav();
  77. if (path.startsWith('/forum')) {
  78. traiterForum();
  79. } else if (path.startsWith('/topic')) {
  80. traiterTopic();
  81. } else if (path === '/messagerie') {
  82. traiterMessagerie();
  83. } else if (path.startsWith('/messagerie')) {
  84. } else {
  85. console.log('Cas ' + path + " non traité.");
  86. }
  87. }
  88.  
  89. enhanceTextArea();
  90. controlVersion();
  91.  
  92. var t1 = performance.now();
  93. console.log("Call to AveNoel took " + (t1 - t0) + " milliseconds.");
  94.  
  95. })();
  96.  
  97. function initProfil() {
  98. var split = document.getElementsByClassName('navbar-user-avatar')[0].parentElement.href.split("/");
  99. profil.name = split[split.length-1];
  100. }
  101.  
  102. function initFunctions() {
  103. if (!String.prototype.splice) {
  104. /**
  105. * {JSDoc}
  106. *
  107. * The splice() method changes the content of a string by removing a range of
  108. * characters and/or adding new characters.
  109. *
  110. * @this {String}
  111. * @param {number} start Index at which to start changing the string.
  112. * @param {number} delCount An integer indicating the number of old chars to remove.
  113. * @param {string} newSubStr The String that is spliced in.
  114. * @return {string} A new string with the spliced substring.
  115. */
  116. String.prototype.splice = function(start, delCount, newSubStr) {
  117. return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
  118. };
  119. }
  120. }
  121.  
  122. function initCache() {
  123. profilUsers = localStorage.profilUsers === undefined ? {} : JSON.parse(localStorage.profilUsers);
  124. regexList = localStorage.regexList === undefined ? [] : JSON.parse(localStorage.regexList);
  125. bansRegex = localStorage.bansRegex === undefined ? [] : JSON.parse(localStorage.bansRegex);
  126. favs = localStorage.favs === undefined ? {} : JSON.parse(localStorage.favs);
  127. bans = localStorage.bans === undefined ? [] : JSON.parse(localStorage.bans);
  128. favProfiles = localStorage.favProfiles === undefined ? [] : JSON.parse(localStorage.favProfiles);
  129. banProfiles = localStorage.banProfiles === undefined ? [] : JSON.parse(localStorage.banProfiles);
  130. }
  131.  
  132. function controlVersion() {
  133. httpGetApiAsync("messages/1611709", function(res) {
  134.  
  135. var match = res.content.match(/[0-9]+\.[0-9]+\.[0-9]+/g);
  136. if (match && version !== match[0]) {
  137.  
  138. var patchNotes = res.content.split(match)[1].match(/[^\r\n]+/g);
  139. var div = document.getElementById('alertversion');
  140. var innerHTML =
  141. "La version " + match[0] + " est disponible => " +
  142. "<a href=\"https://avenoel.org/topic/101099-1-aide-voici-un-script-pour-vous-faciliter-la-vie-sur-avn\">ici</a>.";
  143. for(var i = 1; i < patchNotes.length -1; ++i) {
  144. innerHTML += "<li>" + patchNotes[i] + "</li>";
  145. }
  146. innerHTML +=
  147. "<br>N'oubliez pas de laisser un commentaire." +
  148. //"<br><img class=\"board-noelshack\" src=\"https://image.noelshack.com/fichiers/2017/02/1484089609-coeur.png\">";
  149. "<br><img class=\"board-noelshack\" src=\"https://image.noelshack.com/fichiers/2018/11/5/1521213499-antifa-arrete-de-filmer.png\">";
  150.  
  151. div.innerHTML = innerHTML;
  152. div.style.color = "red";
  153. }
  154. });
  155.  
  156.  
  157. }
  158.  
  159. //-----------------------------------------------------
  160. // Editeur de texte
  161. //-----------------------------------------------------
  162.  
  163. function enhanceTextArea() {
  164.  
  165. var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
  166. if (!textArea) {
  167. return;
  168. }
  169.  
  170. // dragElement(document.getElementsByClassName("col-md-10 col-md-offset-1")[0].children[0]);
  171. //document.getElementsByClassName("col-md-10 col-md-offset-1")[0].children[0].id = 'dxy';
  172.  
  173. if (textArea.value.length > 0) {
  174. textArea.selectionStart = textArea.value.length;
  175. textArea.focus();
  176. }
  177.  
  178. var edit = function(tagIn, tagOut) {
  179.  
  180. var start = textArea.selectionStart;
  181. var end = textArea.selectionEnd;
  182. textArea.value = textArea.value.splice(textArea.selectionEnd, 0, tagOut).splice(textArea.selectionStart, 0, tagIn);
  183. textArea.selectionStart = start + tagIn.length;
  184. textArea.selectionEnd = end + tagIn.length;
  185. textArea.focus();
  186.  
  187. };
  188.  
  189. var textAreaButtons = document.getElementsByClassName("form-group bbcodes")[document.getElementsByClassName("form-group bbcodes").length - 1];
  190.  
  191. var list = [
  192. {name:"R", tagIn:"<color=red>", tagOut:"</color>", color:"red"},
  193. {name:"G", tagIn:"<color=green>", tagOut:"</color>", color:"green"},
  194. {name:"B", tagIn:"<color=blue>", tagOut:"</color>", color:"blue"}
  195. ];
  196. var div = document.createElement('div');
  197. list.forEach(function(each) {
  198.  
  199. div.innerHTML = "<button type=\"button\" class=\"btn\" tabindex=\"-1\" data-type=\"tag\"><span>" + each.name + "</span></button>";
  200. var btn = div.firstChild;
  201. textAreaButtons.appendChild(btn);
  202. btn.style.color = each.color;
  203. btn.onclick = function() {edit(each.tagIn, each.tagOut);};
  204.  
  205. });
  206.  
  207. div.remove();
  208.  
  209. textArea.onfocusout = function () {
  210. var value = textArea.value;
  211. regexList.forEach(function(each) {
  212. value = value.replace(new RegExp(each.reg, "gm"), each.res);
  213. });
  214.  
  215. // Mort aux cucks
  216. textArea.value = value
  217. .replace(new RegExp(" cuck", "gm"), " candaule")
  218. .replace(new RegExp(" Cuck", "gm"), " Candaule")
  219. .replace(new RegExp(" CUCK", "gm"), " CANDAULE");
  220. };
  221.  
  222. manageRisiBank();
  223. }
  224.  
  225. function manageRisiBank() {
  226. var risiList = document.getElementsByClassName("risi-rlist")[0];
  227.  
  228. console.log(risiList);
  229.  
  230. risiList.childNodes[1].parentNode.insertBefore(risiList.childNodes[1], risiList.childNodes[0]);
  231.  
  232. }
  233.  
  234. function dragElement(elmnt) {
  235. var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  236. // if (document.getElementById(elmnt.id + "header")) {
  237. /* if present, the header is where you move the DIV from:*/
  238. // document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  239. // } else {
  240. /* otherwise, move the DIV from anywhere inside the DIV:*/
  241. elmnt.onmousedown = dragMouseDown;
  242. // }
  243.  
  244. elmnt.style.position = 'absolute';
  245.  
  246. function dragMouseDown(e) {
  247. e = e || window.event;
  248. // get the mouse cursor position at startup:
  249. pos3 = e.clientX;
  250. pos4 = e.clientY;
  251. document.onmouseup = closeDragElement;
  252. // call a function whenever the cursor moves:
  253. document.onmousemove = elementDrag;
  254. }
  255.  
  256. function elementDrag(e) {
  257. e = e || window.event;
  258. // calculate the new cursor position:
  259. pos1 = pos3 - e.clientX;
  260. pos2 = pos4 - e.clientY;
  261. pos3 = e.clientX;
  262. pos4 = e.clientY;
  263. // set the element's new position:
  264. elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
  265. elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  266. }
  267.  
  268. function closeDragElement() {
  269. /* stop moving when mouse button is released:*/
  270. document.onmouseup = null;
  271. document.onmousemove = null;
  272. }
  273. }
  274.  
  275. //-----------------------------------------------------
  276. // Fav/Courriers
  277. //-----------------------------------------------------
  278.  
  279. function ajouterBarFav() {
  280.  
  281. var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
  282. if (barFav.length === 0) {
  283. return;
  284. }
  285.  
  286. var idCourrier = getId();
  287. var idFavoris = getId();
  288. barFav[0].replaceChild(barFav[0].children[0].cloneNode(true), barFav[0].children[0]);
  289.  
  290. var listDiv = barFav[0].children[1];
  291. listDiv.classList = [];
  292. listDiv.innerHTML =
  293. "<section>"+
  294. " <div id=\"alertversion\"></div>"+
  295. " <div id=\""+idCourrier+"\"></div>"+
  296. " <div id=\""+idFavoris+"\"></div>"+
  297. //"<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/xh_bqcyqp64\"> </iframe>"+
  298. "</section>";
  299.  
  300. var rect = listDiv.getBoundingClientRect(),
  301. scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  302. var top = rect.top + scrollTop;
  303. var event = function(e) {
  304. if (window.scrollY > top) {
  305. listDiv.style.position = "absolute";
  306. listDiv.style.top = window.scrollY + 'px';
  307. } else {
  308. listDiv.style.position = null;
  309. listDiv.style.top = top + 'px';
  310. }
  311. };
  312. window.addEventListener('scroll', event);
  313. event.apply();
  314.  
  315.  
  316. var setMails = function(){
  317. httpGetAsync("https://avenoel.org/messagerie", function (html) {
  318. var mails = html.getElementsByClassName("active");
  319.  
  320. if (mails.length > 2) {
  321. profil.nbMail = "(" + (mails.length-2) + ") ";
  322. var innerHTMLCourrier = "Courrier" + ((mails.length-2) > 1 ? "s" : "") + " (" + (mails.length-2) + ")";
  323.  
  324. for(var i = 1; i < mails.length -1; ++i) {
  325. innerHTMLCourrier += "<li>";
  326. innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
  327. innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
  328. innerHTMLCourrier += "</li>";
  329. }
  330.  
  331. document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
  332. } else {
  333. profil.nbMail = "";
  334. document.getElementById(idCourrier).innerHTML = "";
  335. }
  336. changeTitle();
  337. });
  338. };
  339. setInterval(setMails, 30000);
  340. setMails.apply();
  341.  
  342. var setFavs = function(){
  343. httpGetAsync("https://avenoel.org/favoris", function (html) {
  344. var list = html.getElementsByTagName("tBody")[0].children;
  345. var buttonBar = document.getElementById(idFavoris);
  346. var innerHTMLFav = "Favoris";
  347. var hasNoneRead = false;
  348. profil.quoted = "";
  349.  
  350. for(var i = 0; i < list.length; i++) {
  351.  
  352. var fav = list[i];
  353. var sNbDiff = "";
  354. var nbDiff = 0;
  355.  
  356. var href = fav.children[1].children[0].href;
  357. var nb = fav.children[3].innerHTML.trim();
  358.  
  359. if (fav.children[0].children[0].href === window.location.href) {
  360. favs[href] = nb;
  361. localStorage.setItem("favs", JSON.stringify(favs));
  362. }
  363.  
  364. if (favs[href]) {
  365. if( favs[href] !== nb) {
  366. nbDiff = (nb - favs[href]);
  367. sNbDiff = "(" + nbDiff + ") ";
  368. hasNoneRead = true;
  369. }
  370. } else {
  371. favs[href] = nb;
  372. localStorage.setItem("favs", JSON.stringify(favs));
  373. }
  374.  
  375. var hrefEnd = fav.children[0].children[0].href;
  376. fav.children[1].children[0].href = hrefEnd;
  377.  
  378. fav.removeChild(fav.children[2]);
  379. fav.removeChild(fav.children[2]);
  380. fav.removeChild(fav.children[2]);
  381. fav.removeChild(fav.children[0]);
  382. var idLi = getId();
  383. innerHTMLFav += "<li id=\"" + idLi + "\">" + sNbDiff + fav.innerHTML + "</li>";
  384.  
  385. if (nbDiff !== 0) {
  386. scanQuote(hrefEnd, nbDiff, idLi);
  387. }
  388. }
  389.  
  390. document.getElementById(idFavoris).innerHTML = innerHTMLFav;
  391. profil.noneRead = hasNoneRead ? "*" : "";
  392. changeTitle();
  393. });
  394. };
  395. setInterval(setFavs, 30000);
  396. setFavs.apply();
  397. }
  398.  
  399. function changeTitle() {
  400. document.title = profil.nbMail + profil.noneRead + profil.quoted + profil.tabName;
  401. }
  402.  
  403. function scanQuote(href, nb, idLi) {
  404. deepScan(href, nb, idLi);
  405. }
  406.  
  407. function deepScan(href, nb, idLi) {
  408.  
  409. httpGetAsync(href, function (html) {
  410.  
  411. var commentaires = html.getElementsByClassName("topic-messages")[0].children;
  412. for (var i = commentaires.length - 1; i > -1 && nb !== 0; i--) {
  413. nb--;
  414. if (commentaires[i].children[1].children[1].innerHTML.indexOf("https://avenoel.org/profil/" + profil.name + "\"") !== -1) {
  415. document.getElementById(idLi).children[0].style.color = "red";
  416. nb = 0;
  417. profil.quoted = "! ";
  418. break;
  419. }
  420. }
  421.  
  422. if (nb > 0) {
  423. deepScan(getPageFromUrl(href, false) , nb, idLi);
  424. }
  425. changeTitle();
  426.  
  427. });
  428. }
  429.  
  430. //-----------------------------------------------------
  431. // Topic
  432. //-----------------------------------------------------
  433.  
  434. function traiterTopic() {
  435.  
  436. overloadButtonDeleteTopic();
  437.  
  438. var maxPage = window.location.href;
  439. var lstTopic = document.getElementsByClassName("topic-messages");
  440.  
  441. var trsTopic = lstTopic[0].children;
  442.  
  443. var body = document.body,
  444. html = document.documentElement;
  445. var height = Math.max( body.scrollHeight, body.offsetHeight,
  446. html.clientHeight, html.scrollHeight, html.offsetHeight );
  447.  
  448. var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
  449.  
  450.  
  451. var event = function(e) {
  452. if (
  453. textArea !== document.activeElement &&
  454. document.body.scrollHeight === window.scrollY + window.innerHeight
  455. ) {
  456. maxPage = getPageFromUrl(maxPage, true);
  457. httpGetAsync(maxPage, function (html) {
  458.  
  459. var nbPage = html.getElementsByTagName("title")[0].innerHTML.match(/Page [0-9]+ /g);
  460. if(nbPage[0] === "Page 1 ") {
  461. return;
  462. }
  463. var size = lstTopic[0].children.length;
  464. lstTopic[0].innerHTML += "<div>"+nbPage+"</div>" + html.getElementsByClassName("topic-messages")[0].innerHTML;
  465. enhanceListTopicMessage(lstTopic[0].children, size);
  466. });
  467. }
  468. };
  469. window.addEventListener('scroll', event);
  470.  
  471. enhanceListTopicMessage(trsTopic);
  472. traiterNavBarTopic();
  473. }
  474.  
  475. function enhanceListTopicMessage(trsTopic, start) {
  476. var iTopic = 0;
  477. if (start) {
  478. iTopic = start;
  479. }
  480. for(; iTopic < trsTopic.length; ++iTopic) {
  481. traiterTrTopic(trsTopic[iTopic]);
  482. collapseQuote(trsTopic[iTopic]);
  483. overloadButtons(trsTopic[iTopic]);
  484. }
  485. }
  486.  
  487. function findNewTop(isUp, listTop) {
  488. for(var i = 0; i < listTop.length - 1; ++i) {
  489. if (listTop[i] <= window.scrollY && window.scrollY <= listTop[i + 1]) {
  490. return isUp ? listTop[i] : listTop[i + 1];
  491. }
  492. }
  493. }
  494.  
  495. function traiterNavBarTopic() {
  496.  
  497. var relativePath = "";
  498. getPath().split("-").splice(2).forEach(function(split) {
  499. relativePath += split + "-";
  500. });
  501. relativePath = relativePath.slice(0, -1);
  502.  
  503. var buttons = addButtonToNavBar(["buttonBan"]);
  504. var buttonBan = buttons[0];
  505.  
  506. // Bouton des bans
  507. var isInBan = contentsString(bans, relativePath) != -1;
  508. if (isInBan) {
  509. buttonBan.innerHTML = "DEBAN";
  510. buttonBan.onclick = function() {
  511. deleteFromCache(bans, "bans");
  512. };
  513. } else {
  514. buttonBan.innerHTML = "BAN";
  515. buttonBan.onclick = function() {
  516. addInCache(bans, "bans");
  517. };
  518. }
  519.  
  520. }
  521.  
  522. function addInCache(cacheList, cacheName) {
  523. console.log("addInCache : " + cacheName);
  524. cacheList.push(getPath());
  525. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  526. ajouterBarFav();
  527. traiterNavBarTopic();
  528. }
  529.  
  530. function deleteFromCache(cacheList, cacheName) {
  531. console.log("deleteFromCache : " + cacheName);
  532.  
  533. var relativePath = "";
  534. getPath().split("-").splice(2).forEach(function(split) {
  535. relativePath += split + "-";
  536. });
  537. relativePath = relativePath.slice(0, -1);
  538.  
  539. var i = contentsString(cacheList, relativePath);
  540. if (i !== -1) {
  541. cacheList.splice(i, 1);
  542. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  543. }
  544.  
  545. ajouterBarFav();
  546. traiterNavBarTopic();
  547. }
  548.  
  549. function traiterTrTopic(tr) {
  550.  
  551. if (tr.children.length === 0) {
  552. return;
  553. }
  554.  
  555. var name = tr.getElementsByClassName("message-username")[0].children[0];
  556. if (profilUsers[name.innerHTML]) {
  557. if (profilUsers[name.innerHTML].color) {
  558. name.style.color = profilUsers[name.innerHTML].color;
  559. }
  560. if (profilUsers[name.innerHTML].pdp) {
  561. tr.getElementsByClassName("message-avatar")[0].children[0].src = profilUsers[name.innerHTML].pdp;
  562. }
  563. if (profilUsers[name.innerHTML].name) {
  564. name.innerHTML = profilUsers[name.innerHTML].name;
  565. }
  566. }
  567.  
  568. var message = null;
  569. var rank = -1;
  570.  
  571. // Suppression des FDP
  572. banProfiles.some(function(connard) {
  573.  
  574. var id = getId();
  575. message = null;
  576. if (hasProfilLink(tr, connard.name)) {
  577. message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  578. }
  579. if (hasProfilAvatar(tr, connard.name)) {
  580. message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  581. }
  582.  
  583. if (message !== null) {
  584. rank = connard.rank;
  585. return true;
  586. }
  587.  
  588. return false;
  589. });
  590.  
  591. if (rank == 2) {
  592. tr.innerHTML = message;
  593. tr.focus();
  594. } else {
  595. addButtonHiddenTopicMessage(tr, rank == 1);
  596. }
  597.  
  598. return tr.offsetTop;//getBoundingClientRect().top + window.pageYOffset;
  599. }
  600.  
  601. function collapseQuote(tr) {
  602.  
  603. var content = tr.getElementsByClassName("message-content")[0];
  604. if (!content) {
  605. return;
  606. }
  607.  
  608. var lines = content.innerHTML.match(/[^\r\n]+/g);
  609.  
  610. var ids = [];
  611. var currentLine;
  612. var lastRank = -1;
  613. var currentRank = -1;
  614. for(var i = lines.length - 1; i > -1; --i) {
  615. currentRank = calculRank(lines[i]);
  616.  
  617. if (lastRank > 0 && currentRank > lastRank) {
  618. lines.splice(i + 1, 0, "</div>");
  619. } else if (currentRank > 0 && currentRank < lastRank) {
  620.  
  621. var idButton = getId();
  622. var idDiv = getId();
  623. var beforeButton = "";
  624. for(var iGt = 0; iGt < currentRank; ++iGt) {
  625. beforeButton += "&gt; ";
  626. }
  627.  
  628. var buttonAll = "";
  629. if (currentRank === 1) {
  630. var idButtonAll = "buttonAll" + getId();
  631. buttonAll = "<button id=\"" + idButtonAll + "\" ></button>";
  632. ids.push({idButton:idButtonAll, idDiv:idDiv});
  633. }
  634.  
  635. var maskInnerHTML = "<span class=\"message-content-quote\">" + beforeButton + "<i><button id=\"" + idButton + "\" ></button>" + buttonAll + "</i></span><div id=\"" + idDiv + "\" >";
  636. ids.push({idButton:idButton, idDiv:idDiv});
  637. lines.splice(i + 1, 0, maskInnerHTML);
  638. }
  639.  
  640. lastRank = currentRank;
  641. }
  642.  
  643. content.innerHTML = lines.join('');
  644. addCollapseEvent(tr, ids);
  645. }
  646.  
  647. function addCollapseEvent(tr, ids) {
  648. ids.forEach(function(id) {
  649. var button = document.getElementById(id.idButton);
  650. button.style.border = "none";
  651. button.innerHTML = ">";
  652. button.style.textAlign = "center";
  653. var div = document.getElementById(id.idDiv);
  654. div.style.display = "none";
  655.  
  656. if (id.idButton.startsWith("buttonAll")) {
  657. button.innerHTML = "=>";
  658. button.onclick = function() {
  659.  
  660. button.innerHTML = button.innerHTML === "&lt;=" ? "=&gt;" : "&lt;=";
  661. var innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  662. var buttonList = div.getElementsByTagName("button");
  663. for (var i = 0; i < buttonList.length; i++) {
  664. buttonList[i].innerHTML = innerHTML;
  665. }
  666.  
  667. var divList = div.getElementsByTagName("div");
  668. var display = button.innerHTML === "&lt;=" ? "" : "none";
  669. div.style.display = display;
  670. for (var j = 0; j < divList.length; j++) {
  671. divList[j].style.display = display;
  672. }
  673.  
  674. button.previousSibling.innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  675.  
  676. };
  677. } else {
  678. button.onclick = function() {
  679.  
  680. button.innerHTML = button.innerHTML === "&lt;" ? "&gt;" : "&lt;";
  681. div.style.display = div.style.display === "none" ? "" : "none";
  682.  
  683. if (button.nextSibling !== null) {
  684. button.nextSibling.innerHTML = button.innerHTML === "&lt;" ? "&lt;=" : "=&gt";
  685. }
  686. };
  687. }
  688. });
  689. }
  690.  
  691. function calculRank(line) {
  692. var rank = -1;
  693. var index;
  694. var matcher = "quote\">&gt; ";
  695.  
  696. while (index != -1) {
  697. rank++;
  698. index = line.indexOf(matcher);
  699. matcher += "&gt; ";
  700. }
  701.  
  702. return rank;
  703. }
  704.  
  705. function addButtonHiddenTopicMessage(tr, isHidden) {
  706.  
  707. var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
  708. if (!aside) {
  709. return;
  710. }
  711. var content = tr.getElementsByClassName("message-content")[0];
  712. var header = tr.getElementsByClassName("message-header")[0];
  713. var ulHeader = header.getElementsByClassName("message-actions")[0];
  714. var footer = tr.getElementsByClassName("message-footer")[0];
  715.  
  716. //aside.children[0].children[0].src = "http://4.bp.blogspot.com/-MdNpMeXfP3k/UYkDoyQ32VI/AAAAAAAAcNU/q3Dnc5zB4Ic/s1600/Blocage.jpg";
  717.  
  718. var idButton = getId();
  719.  
  720. content.isHidden = isHidden;
  721. var innerButton = content.isHidden ? "Afficher" : "Masquer";
  722. ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
  723.  
  724. var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
  725. var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
  726.  
  727. var button = document.getElementById(idButton);
  728.  
  729. button.style.backgroundColor = "Transparent";
  730. button.style.border = "none";
  731.  
  732. button.onclick = function() {
  733. content.isHidden = !content.isHidden;
  734. button.innerHTML = content.isHidden ? imageUp : imageDown;
  735. content.style.display = content.isHidden ? "none" : "";
  736. footer.style.display = content.isHidden ? "none" : "";
  737. aside.style.display = content.isHidden ? "none" : "";
  738. };
  739. content.isHidden = !content.isHidden;
  740. button.onclick.apply();
  741. }
  742.  
  743. function overloadButtons(tr) {
  744. var header = tr.getElementsByClassName("message-header")[0];
  745. if (!header) {
  746. return;
  747. }
  748.  
  749. var imgs = header.getElementsByTagName("img");
  750. var img;
  751. for(var i = 0; i < imgs.length; ++i) {
  752. if (imgs[i].src === "https://avenoel.org/images/topic/delete.png") {
  753. img = imgs[i];
  754. }
  755. }
  756.  
  757. if (!img) {
  758. return;
  759. }
  760.  
  761. var button = img.parentElement;
  762. var href = button.href;
  763. button.href = "#";
  764. button.onclick = function() {
  765. if (window.confirm("Voulez vous supprimer le message ?")) {
  766. window.location.href = href;
  767. }
  768. };
  769.  
  770. }
  771.  
  772. function overloadButtonDeleteTopic() {
  773.  
  774. var buttons = document.getElementsByClassName("btn btn-danger");
  775. if (!buttons) {
  776. return;
  777. }
  778.  
  779. for(var i = 0; i < buttons.length; ++i) {
  780.  
  781. var button = buttons[i];
  782. button.href2 = button.href;
  783. button.href = "#";
  784. button.onclick = function() {
  785. if (window.confirm("Voulez vous " + this.innerHTML.toLowerCase() + " le topic ?")) {
  786. window.location.href = this.href2;
  787. }
  788. };
  789. }
  790.  
  791. }
  792.  
  793. //-----------------------------------------------------
  794. // Forum
  795. //-----------------------------------------------------
  796.  
  797.  
  798. function traiterForum() {
  799. var lst = document.getElementsByClassName("table table-striped topics");
  800. var trs = lst[0].children[1].children;
  801. for(var i = 0; i < trs.length; ++i) {
  802. traiterTrForum(trs[i]);
  803. }
  804. }
  805.  
  806. function traiterTrForum(tr) {
  807.  
  808. var name = tr.getElementsByClassName("topics-author")[0].children[0];
  809. if (profilUsers[name.innerHTML]) {
  810. if (profilUsers[name.innerHTML].color) {
  811. name.style.color = profilUsers[name.innerHTML].color;
  812. }
  813. if (profilUsers[name.innerHTML].name) {
  814. name.innerHTML = profilUsers[name.innerHTML].name;
  815. }
  816. }
  817.  
  818. // Suppression des caracteres ching chong
  819. // if (tr.innerText.match(/[\u3400-\u9FBF]/) || tr.innerText.match(/[\u0250-\u02AF)]/)) {
  820. // console.log("Suppression des caracteres ching chong");
  821. // tr.innerHTML = "";
  822. // return;
  823. // }
  824.  
  825. // Suppression des FDP
  826. if (banProfiles.some(function(connard) {
  827. if (hasProfilLink(tr, connard.name)) {
  828. console.log("Suppression du FDP : " + connard.name);
  829. tr.innerHTML = "";
  830. return true;
  831. }
  832. return false;
  833. })) {
  834. return;
  835. }
  836.  
  837. if (bans.some(function(url) {
  838. if (hasUrl(tr, url)) {
  839. console.log("Suppression du sujet : " + url);
  840. tr.innerHTML = "";
  841. return true;
  842. }
  843. return false;
  844. })) {
  845. return;
  846. }
  847.  
  848. if (bansRegex.some(function(regex) {
  849. if (tr.innerHTML.match(new RegExp(regex, "gm"))) {
  850. console.log("Suppression du sujet regex : " + regex);
  851. tr.innerHTML = "";
  852. return true;
  853. }
  854. return false;
  855. })) {
  856. return;
  857. }
  858.  
  859. // Surlignage
  860. if (favProfiles.some(function(surligne) {
  861. if (hasProfilLink(tr, surligne.name)) {
  862. console.log("Surlignage : " + surligne.name);
  863. tr.style.background = colorListProfil[surligne.color];
  864. return true;
  865. }
  866. return false;
  867. })) {
  868. return;
  869. }
  870.  
  871. }
  872.  
  873. //-----------------------------------------------------
  874. // Profil
  875. //-----------------------------------------------------
  876.  
  877. function traiterProfil() {
  878. var isMine = profil.name === document.getElementsByTagName("h2")[0].innerHTML;
  879. var elem = document.getElementsByClassName("profile-wrapper-right");
  880. currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
  881.  
  882. elem[0].innerHTML += "<div " + (isMine ? "hidden" : "") + ">Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div></div>";
  883. elem[0].innerHTML += "Topic couleur <select id=\"idFavColor\"></select><br/>";
  884. elem[0].innerHTML += "Profil couleur <select id=\"idProfilColor\"></select><br/>";
  885. elem[0].innerHTML += "Profil name <input class=\"profile-biography\" id=\"idProfilName\" type=\"text\" style=\"height: 30px;\" placeholder=\"" + currentProfile + "\"/>";
  886. elem[0].innerHTML += "Profil photo <input class=\"profile-biography\" id=\"idProfilPhoto\" type=\"text\" style=\"height: 30px;\" placeholder=\"Pas de photo\"/>";
  887.  
  888. // pdp --------------------------------------------------------------
  889. if (profilUsers[currentProfile] && profilUsers[currentProfile].pdp) {
  890. document.getElementsByClassName("profile-avatar")[0].children[0].src = profilUsers[currentProfile].pdp;
  891. }
  892. document.getElementById("idProfilPhoto").onkeypress = function(e) {
  893. if (e.charCode === 13) {
  894. updatePhotoProfil(document.getElementById("idProfilPhoto").value);
  895. }
  896. };
  897.  
  898. // name -------------------------------------------------------------
  899. if (profilUsers[currentProfile] && profilUsers[currentProfile].name) {
  900. document.getElementsByClassName("profile-title")[0].children[0].innerHTML = profilUsers[currentProfile].name;
  901. }
  902. document.getElementById("idProfilName").onkeypress = function(e) {
  903. if (e.charCode === 13) {
  904. renameProfil(document.getElementById("idProfilName").value);
  905. }
  906. };
  907.  
  908. // color list -------------------------------------------------------
  909. var colorList = [];
  910. for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
  911. colorList.push(iColor);
  912. }
  913. // color ------------------------------------------------------------
  914. var hasColor = false;
  915. var colorProfil;
  916. if (profilUsers[currentProfile]) {
  917. colorProfil = profilUsers[currentProfile].color;
  918. colorizeProfil(colorProfil);
  919. }
  920.  
  921. createComboBox("idProfilColor", colorList);
  922. var comboProfilColor = document.getElementById("idProfilColor");
  923.  
  924. for (var k = 0; k < comboProfilColor.length; k++) {
  925. comboProfilColor[k].innerHTML = "";
  926. comboProfilColor[k].style.backgroundColor = colorListProfil[k];
  927. }
  928.  
  929. if (hasColor) {
  930. comboProfilColor.selectedIndex = parseInt(color);
  931. comboProfilColor.style.backgroundColor = colorListProfil[color];
  932. }
  933.  
  934. comboProfilColor.onchange = function(event) {
  935. colorizeProfil(colorListProfil[event.target.selectedOptions[0].value]);
  936. };
  937.  
  938.  
  939. // favoris ----------------------------------------------------------
  940. var isFav = false;
  941. var color = 0;
  942. favProfiles.some(function(fav) {
  943. if (fav.name === currentProfile) {
  944. isFav = true;
  945. color = fav.color;
  946. return true;
  947. }
  948. return false;
  949. });
  950.  
  951.  
  952.  
  953. createComboBox("idFavColor", colorList);
  954. var comboFavColor = document.getElementById("idFavColor");
  955.  
  956. for (var j = 0; j < comboFavColor.length; j++) {
  957. comboFavColor[j].innerHTML = "";
  958. comboFavColor[j].style.backgroundColor = colorListProfil[j];
  959. }
  960.  
  961. if (isFav) {
  962. comboFavColor.selectedIndex = parseInt(color);
  963. comboFavColor.style.backgroundColor = colorListProfil[color];
  964. }
  965.  
  966. comboFavColor.onchange = function(event) {
  967. favProfile(event.target.selectedOptions[0].value);
  968. };
  969.  
  970. // bans ----------------------------------------------------------
  971. detailRankProfile();
  972. var isBan = false;
  973. var rank = 0;
  974. banProfiles.forEach(function(connard) {
  975. if (connard.name === currentProfile) {
  976. isBan = true;
  977. rank = connard.rank;
  978. return;
  979. }
  980. });
  981.  
  982. createComboBox("idBanRank", ["non","0","1","2"]);
  983. var comboBanRank = document.getElementById("idBanRank");
  984. if (isBan) {
  985. comboBanRank.selectedIndex = parseInt(rank) + 1;
  986. }
  987. detailRankProfile(rank);
  988. comboBanRank.onchange = function(event) {
  989. banProfile(event.target.selectedOptions[0].value);
  990. };
  991.  
  992. if (isMine) {
  993. afficherConfig();
  994. }
  995.  
  996. }
  997.  
  998. function afficherConfig() {
  999. var container = document.getElementsByClassName("col-md-7 col-centered profile")[0];
  1000. var editorContainer = container.appendChild(container.children[0].cloneNode(true));
  1001. editorContainer.style.textAlign = "left";
  1002. editorContainer.style.marginTop = "15px";
  1003. editorContainer.innerHTML = "";
  1004. var config = container.appendChild(container.children[0].cloneNode(true));
  1005. config.style.textAlign = "left";
  1006. config.style.marginTop = "15px";
  1007.  
  1008. var idEditor = getId();
  1009. var idTopic = getId();
  1010. var idBannis = getId();
  1011.  
  1012. config.innerHTML =
  1013. "<div>Liste mots clés de l'éditeur de texte :</div>"+
  1014. "<div id=\"" + idEditor + "\"></div>"+
  1015. "<br>"+
  1016. "<div>Liste mots clés du masques des sujets :</div>"+
  1017. "<div id=\"" + idTopic + "\"></div>"+
  1018. "<br>"+
  1019. "<div>Liste des bannis :</div>"+
  1020. "<div id=\"" + idBannis + "\"></div>";
  1021.  
  1022. addEditorToProfil(editorContainer);
  1023. createConfigEditor(document.getElementById(idEditor));
  1024. createConfigTopic(document.getElementById(idTopic));
  1025. createConfigBannis(document.getElementById(idBannis));
  1026. }
  1027.  
  1028. function addEditorToProfil(container) {
  1029. if (true) {
  1030. container.style.display = "none";
  1031. }
  1032. httpGetAsync("https://avenoel.org/forum", function (html) {
  1033. var form = html.getElementsByTagName("form")[1];
  1034.  
  1035. //var risi = html.getElementsByClassName("btn risi-wlogo")[0];
  1036. // risi.formAction = "https://avenoel.org/forum/#risibank";
  1037. // console.log(risi.formAction);
  1038.  
  1039. container.appendChild(form.children[2]);
  1040. container.appendChild(form.children[2]);
  1041. container.appendChild(form.children[2]);
  1042. enhanceTextArea();
  1043. });
  1044. }
  1045.  
  1046. function createConfigEditor(container) {
  1047.  
  1048. var lines = [];
  1049. var innerHTML = "<li>";
  1050. regexList.forEach(function (each) {
  1051.  
  1052. var res;
  1053. if (each.res.startsWith("https://")) {
  1054. res = "<img class=\"board-noelshack\" src=\"" + each.res + "\">";
  1055. } else {
  1056. res = each.res;
  1057. }
  1058.  
  1059. var idButton = getId();
  1060. innerHTML +=
  1061. each.reg + " => " + res + space +
  1062. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1063. "</li>" +
  1064. "<li>";
  1065. lines.push({id:idButton, each:each});
  1066. });
  1067.  
  1068. var idButtonPlus = getId();
  1069. var idInputKey = getId();
  1070. var idInputValue = getId();
  1071. innerHTML +=
  1072. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1073. " => " +
  1074. "<input class=\"profile-biography\" id=\"" + idInputValue + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1075. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1076. "</li>";
  1077.  
  1078. container.innerHTML = innerHTML;
  1079.  
  1080. lines.forEach(function (line, i) {
  1081. var button = document.getElementById(line.id);
  1082. button.style.backgroundColor = "Transparent";
  1083. button.style.border = "none";
  1084.  
  1085. button.onclick = function() {
  1086. regexList.splice(i, 1);
  1087. localStorage.setItem("regexList", JSON.stringify(regexList));
  1088. createConfigEditor(container);
  1089. };
  1090. });
  1091.  
  1092.  
  1093. var buttonPlus = document.getElementById(idButtonPlus);
  1094. buttonPlus.style.backgroundColor = "Transparent";
  1095. buttonPlus.style.border = "none";
  1096.  
  1097. buttonPlus.onclick = function() {
  1098. regexList.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  1099. localStorage.setItem("regexList", JSON.stringify(regexList));
  1100. createConfigEditor(container);
  1101. };
  1102. }
  1103.  
  1104. function createConfigTopic(container) {
  1105.  
  1106. var lines = [];
  1107. var innerHTML = "<li>";
  1108. bansRegex.forEach(function (each) {
  1109. var idButton = getId();
  1110. innerHTML +=
  1111. each + space +
  1112. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1113. "</li>" +
  1114. "<li>";
  1115. lines.push({id:idButton, each:each});
  1116. });
  1117.  
  1118. var idButtonPlus = getId();
  1119. var idInputKey = getId();
  1120. innerHTML +=
  1121. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1122. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1123. "</li>";
  1124.  
  1125. container.innerHTML = innerHTML;
  1126.  
  1127. lines.forEach(function (line, i) {
  1128. var button = document.getElementById(line.id);
  1129. button.style.backgroundColor = "Transparent";
  1130. button.style.border = "none";
  1131.  
  1132. button.onclick = function() {
  1133. bansRegex.splice(i, 1);
  1134. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  1135. createConfigTopic(container);
  1136. };
  1137. });
  1138.  
  1139.  
  1140. var buttonPlus = document.getElementById(idButtonPlus);
  1141. buttonPlus.style.backgroundColor = "Transparent";
  1142. buttonPlus.style.border = "none";
  1143.  
  1144. buttonPlus.onclick = function() {
  1145. bansRegex.push(document.getElementById(idInputKey).value);
  1146. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  1147. createConfigTopic(container);
  1148. };
  1149.  
  1150. }
  1151.  
  1152. function createConfigBannis(container) {
  1153.  
  1154. var lines = [];
  1155. var idButtonPlus = getId();
  1156. var idInputKey = getId();
  1157.  
  1158. var innerHTML =
  1159. // "<li><input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  1160. // "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  1161. // "</li>"+
  1162. "<ul style=\" columns: 3; -webkit-columns: 3; -moz-columns: 3;\">";
  1163.  
  1164. banProfiles.forEach(function (each) {
  1165. var idButton = getId();
  1166. innerHTML +=
  1167. "<li>"+
  1168. each.name + " / " + each.rank + space +
  1169. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  1170. "</li>";
  1171. lines.push({id:idButton, each:each});
  1172. });
  1173. innerHTML += "</ul>";
  1174. container.innerHTML = innerHTML;
  1175.  
  1176. lines.forEach(function (line, i) {
  1177. var button = document.getElementById(line.id);
  1178. button.style.backgroundColor = "Transparent";
  1179. button.style.border = "none";
  1180.  
  1181. button.onclick = function() {
  1182. banProfiles.splice(i, 1);
  1183. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1184. createConfigBannis(container);
  1185. };
  1186. });
  1187.  
  1188.  
  1189. // var buttonPlus = document.getElementById(idButtonPlus);
  1190. // buttonPlus.style.backgroundColor = "Transparent";
  1191. // buttonPlus.style.border = "none";
  1192.  
  1193. // buttonPlus.onclick = function() {
  1194. // banProfiles.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  1195. // localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1196. // createConfigBannis(container);
  1197. // };
  1198. }
  1199.  
  1200. function updatePhotoProfil(src) {
  1201. if (src.trim().length === 0) {
  1202. if (profilUsers[currentProfile]) {
  1203. delete profilUsers[currentProfile].pdp;
  1204. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1205. }
  1206. } else {
  1207. updateProfilUser("pdp", src.trim());
  1208. }
  1209. document.getElementsByClassName("profile-avatar")[0].children[0].src = src;
  1210. }
  1211.  
  1212. function renameProfil(name) {
  1213. if (name.trim().length === 0) {
  1214. if (profilUsers[currentProfile]) {
  1215. delete profilUsers[currentProfile].name;
  1216. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1217. }
  1218. name = currentProfile;
  1219. } else {
  1220. updateProfilUser("name", name.trim());
  1221. }
  1222. document.getElementsByClassName("profile-title")[0].children[0].innerHTML = name;
  1223. }
  1224.  
  1225. function colorizeProfil(color) {
  1226. document.getElementsByClassName("profile-title")[0].children[0].style.color = color;
  1227. updateProfilUser("color", color);
  1228. document.getElementById("idProfilColor").style.backgroundColor = color;
  1229. }
  1230.  
  1231. function updateProfilUser(property, value) {
  1232. if (!profilUsers[currentProfile]) {
  1233. profilUsers[currentProfile] = {};
  1234. }
  1235. profilUsers[currentProfile][property] = value;
  1236. localStorage.setItem("profilUsers", JSON.stringify(profilUsers));
  1237. }
  1238.  
  1239. function favProfile(color) {
  1240. console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
  1241.  
  1242. var index = -1;
  1243. for(var i = 0; i < favProfiles.length; ++i) {
  1244. if (stringContents(favProfiles[i].name, currentProfile)) {
  1245. index = i;
  1246. break;
  1247. }
  1248. }
  1249.  
  1250. if (index !== -1) {
  1251. favProfiles.splice(index, 1);
  1252. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1253. }
  1254.  
  1255. if (color !== "0") {
  1256. favProfiles.push({name:currentProfile, color:color});
  1257. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1258. }
  1259.  
  1260. document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
  1261. }
  1262.  
  1263. function banProfile(rank) {
  1264. console.log("banProfile : " + currentProfile + ", rang : " + rank);
  1265.  
  1266. var index = -1;
  1267. for(var i = 0; i < banProfiles.length; ++i) {
  1268. if (stringContents(banProfiles[i].name, currentProfile)) {
  1269. index = i;
  1270. break;
  1271. }
  1272. }
  1273.  
  1274. if (index !== -1) {
  1275. banProfiles.splice(index, 1);
  1276. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1277. }
  1278.  
  1279. if (rank !== "non") {
  1280. banProfiles.push({name:currentProfile, rank:rank});
  1281. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1282. }
  1283.  
  1284. detailRankProfile(rank);
  1285. }
  1286.  
  1287. function detailRankProfile(rank) {
  1288. var innerHTML;
  1289. if (rank === "0") {
  1290. innerHTML = "Ses sujets sont supprimés.";
  1291. } else if (rank === "1") {
  1292. innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
  1293. } else if (rank === "2") {
  1294. innerHTML = "Ses sujets et messages sont supprimés.";
  1295. } else {
  1296. innerHTML = "Non banni.";
  1297. }
  1298.  
  1299. document.getElementById("idBanRankDetail").innerHTML = innerHTML;
  1300. }
  1301.  
  1302. //-----------------------------------------------------
  1303. // Messagerie
  1304. //-----------------------------------------------------
  1305.  
  1306. function traiterMessagerie() {
  1307.  
  1308. overideDeleteButtonMessagerie();
  1309. var title = document.getElementsByTagName("thead")[0].children[0];
  1310. title.insertBefore(title.children[1].cloneNode(true), title.children[1]);
  1311. title.children[1].innerHTML = "COMMENTAIRE";
  1312.  
  1313. var mails = document.getElementsByTagName("tbody")[0].children;
  1314. for(var i = 0; i < mails.length; ++i) {
  1315. mails[i].insertBefore(mails[i].children[1].cloneNode(true), mails[i].children[1]);
  1316. getLastCommenter(mails[i].children[1], mails[i].children[0].children[0].href);
  1317. }
  1318.  
  1319. }
  1320.  
  1321. function getLastCommenter(node, href) {
  1322. var replace = node.children[0].innerHTML;
  1323. node.innerHTML = node.innerHTML.replace(replace, "error").replace(replace, "error");
  1324. replace = "error";
  1325.  
  1326. httpGetAsync(href, function (html) {
  1327.  
  1328. var commentaires = html.getElementsByClassName("topic-messages")[0].children;
  1329. var name = commentaires[commentaires.length-1].getElementsByClassName("message-username")[0].children[0].innerHTML;
  1330. node.innerHTML = node.innerHTML.replace(replace, name).replace(replace, name);
  1331.  
  1332. });
  1333.  
  1334. }
  1335.  
  1336. function overideDeleteButtonMessagerie() {
  1337. var button = document.getElementsByClassName("btn btn-danger")[0];
  1338. if (!button) {
  1339. return;
  1340. }
  1341. button.parentElement.onsubmit = function() {
  1342. return window.confirm("Voulez vous quittez le MP ?");
  1343. };
  1344. }
  1345.  
  1346. //-----------------------------------------------------
  1347. // Utils
  1348. //-----------------------------------------------------
  1349.  
  1350. function createImageButton(idButton, buttonHtml) {
  1351. var button = document.getElementById(idButton);
  1352. button.innerHTML = buttonHtml;
  1353. return button;
  1354. }
  1355.  
  1356. function createComboBox(idParent, list) {
  1357. var sel = document.getElementById(idParent);
  1358. var optionoption = null;
  1359.  
  1360. for(i = 0; i < list.length; i++) {
  1361.  
  1362. optionoption = document.createElement('option');
  1363. optionoption.value = list[i];
  1364. optionoption.innerHTML = list[i];
  1365. sel.appendChild(optionoption);
  1366. }
  1367. return sel;
  1368. }
  1369.  
  1370. function httpGetAsync(theUrl, callback) {
  1371. var xmlHttp = new XMLHttpRequest();
  1372. xmlHttp.onreadystatechange = function() {
  1373. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  1374. callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
  1375. };
  1376. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  1377. xmlHttp.send(null);
  1378. }
  1379.  
  1380. function httpGetApiAsync(path, callback) {
  1381. var xmlHttp = new XMLHttpRequest();
  1382. xmlHttp.onreadystatechange = function() {
  1383. if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  1384. callback(JSON.parse(xmlHttp.responseText).data);
  1385. }
  1386. };
  1387. xmlHttp.open("GET", "https://avenoel.org/api/v1/" + path, true); // true for asynchronous
  1388. xmlHttp.send(null);
  1389. }
  1390.  
  1391. function contentsString(list, match) {
  1392. for(var i = 0; i < list.length; ++i) {
  1393. if (stringContents(list[i], match)) {
  1394. return i;
  1395. }
  1396. }
  1397. return -1;
  1398. }
  1399.  
  1400. function getPath() {
  1401. return url + window.location.pathname;
  1402. }
  1403.  
  1404. function designTopButton(button) {
  1405. button.style.color = "white";
  1406. button.style.backgroundColor = "transparent";
  1407. button.style.border = "none";
  1408. }
  1409.  
  1410. function hasProfilLink(elem, name) {
  1411. return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
  1412. }
  1413.  
  1414. function hasProfilAvatar(elem, name) {
  1415. return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
  1416. }
  1417.  
  1418. function hasUrl(elem, url) {
  1419. return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
  1420. }
  1421.  
  1422. function stringContents(string, match) {
  1423. return string.indexOf(match) !== -1;
  1424. }
  1425.  
  1426. function addButtonToNavBar(names) {
  1427.  
  1428. var buttons = [];
  1429.  
  1430. if (document.getElementById(names[0]) === null) {
  1431. var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
  1432. var innerHTML = "";
  1433. names.forEach(function(name) {
  1434. innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
  1435. });
  1436. navbar[0].innerHTML += innerHTML;
  1437. names.forEach(function(name) {
  1438. designTopButton(document.getElementById(name));
  1439. });
  1440. }
  1441.  
  1442. names.forEach(function(name) {
  1443. buttons.push(document.getElementById(name));
  1444. });
  1445.  
  1446. return buttons;
  1447. }
  1448.  
  1449. function getId() {
  1450. return "id" + id++;
  1451. }
  1452.  
  1453. function getPageFromUrl(url, next) {
  1454. var split = url.split("-");
  1455. if (next) {
  1456. split[1]++;
  1457. }else {
  1458. split[1]--;
  1459. }
  1460. return split.join("-");
  1461.  
  1462. }
  1463.  
  1464. //-----------------------------------------------------
  1465. // Patch
  1466. //-----------------------------------------------------
  1467. //
  1468. // https://avenoel.org/topic/40062-1-api-documentation-de-lapi-davenoel
  1469. // https://pastebin.com/raw/geMuZm39
  1470. var version = "3.7.0";
  1471. // 3.8.0 : Pastebin => Etape 3
  1472. // 3.7.0 : Pastebin => Etape 3
  1473. // + affichage du dernier commentateur d'un MP
  1474. // 3.6.0 : Pastebin => https://pastebin.com/raw/QDRm7nQn
  1475. // + affichage sur l'onglet quand un topic en favoris a un nouveau message
  1476. // + affichage sur l'onglet quand un topic en favoris vous cite
  1477. // 3.5.0 : Pastebin => https://pastebin.com/raw/KWMc09GP
  1478. // + changement des pdp de profil
  1479. // 3.4.0 : Pastebin => https://pastebin.com/raw/aSCAu6hA
  1480. // + changement des noms de profil
  1481. // + changement des couleurs de profil
  1482. // + suppression du controle des caractères ching chong et tamoul
  1483. // 3.3.2 : Pastebin => https://pastebin.com/raw/tHBFbsmW
  1484. // + suppression des caractere tamoul
  1485. // 3.3.1 : Pastebin => https://pastebin.com/raw/L4U0Sd1Z
  1486. // + correction du bug sur les surcharges des boutons
  1487. // 3.3.0 : Pastebin => https://pastebin.com/raw/2RVx8RGc
  1488. // + inifinte scroll
  1489. // + correction bug sur les favoris en citation
  1490. // 3.2.0 : Pastebin => https://pastebin.com/raw/9tfLr09X
  1491. // + correction du bug sur les url avec cuck
  1492. // + le favoris est surligné en rouge quand on est cité
  1493. // 3.1.0 : Pastebin => https://pastebin.com/gFPB9jJA
  1494. // + fin de la gestion des configs des données en cache
  1495. // 3.0.0 : Pastebin => https://pastebin.com/6nFzmeFp
  1496. // + début de la page de config dans le profil
  1497. // + Ajout de la gestion des mots clés éditeur dans le profil
  1498. // 2.6.0 : Pastebin => https://pastebin.com/17GWSM7A
  1499. // + initialisation de la page de configuration de l'appli
  1500. // + ajout du ban de topic par mots clés
  1501. // + optimisation de l'affichage des sujets
  1502. // 2.5.0 : Pastebin => https://pastebin.com/JKKB1RJi
  1503. // + ajout d'une liste de mots clés qui seront transformés dans l'éditeur.
  1504. // 2.4.0 : Pastebin => https://pastebin.com/JCfGHLZ4
  1505. // + ajout des dialogs de confirmation pour la suppression des topics/messages et ignorer.
  1506. // + ajout des modifs dans la notifs des patchs.
  1507. // 2.3.0 : Pastebin => https://pastebin.com/QXe2AJ6v
  1508. // + Ajout d'une popup de confirmation pour quitter les MP
  1509. // 2.2.0 : Pastebin => https://pastebin.com/0gPthPD4
  1510. // + ajout d'un bouton pour afficher/masquer toutes les citations.
  1511. // + amélioration de l'affichage de la nouvelle version
  1512. // 2.1.0 : https://pastebin.com/T2dP5ryX
  1513. // + controle de la version
  1514. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  1515. // + controle de la version
  1516. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  1517. // 2.0.8 : Pastebin => https://pastebin.com/21a6u01a
  1518. // + correction du bug sur les citations (redirection bas de page)
  1519. // 2.0.7 : Pastebin => https://pastebin.com/cD6VqLUY
  1520. // + correction d'un bug sur la barre des favoris
  1521. // + ajout de nouvelles actions dans l'éditeur de texte
  1522. // + la barre des courriers est rafraichie toutes les 30s
  1523. // 2.0.6 : Pastebin => https://pastebin.com/GvTLjLaF
  1524. // + l'élément favoris/courrier se déplace avec le scroll
  1525. // 2.0.5 : Pastebin => https://pastebin.com/pNqRphzh
  1526. // + ajout du nombre de courriers non lus sur l'onglet
  1527. // + possibilité d'afficher/masquer les citiations (masquées par défaut)
  1528. // 2.0.4 : Pastebin => https://pastebin.com/4mCdppfi
  1529. // + affichage de la liste des favoris dans les topics noirs
  1530. // + correction bug sur les BL
  1531. // + optimisation des listes
  1532. // 2.0.3 : Pastebin =>https://pastebin.com/nPvLrBbV
  1533. // + correction du bug d'affichage des courriers
  1534. // 2.0.2 : Pastebin => https://pastebin.com/haqi3XRa
  1535. // + Modification du bouton pour afficher/masquer
  1536. // 2.0.1 : Pastebin => https://pastebin.com/vNmgUrCs
  1537. // + Le clique sur le favoris emmene à la dernière page
  1538. // 2.0.0 : Pastebin => https://pastebin.com/eHCt5h8E
  1539. // + Prise en compte de la liste de favoris (affichage reste à droite)
  1540. // L'icone du fichier n'est pas encore mise
  1541. // + Changement du bouton afficher/masquer un commentaire.
  1542. // 1.1.0 : Pastebin => https://pastebin.com/85F6ydsC
  1543. // + gestion de la lovelist sur les profils
  1544. // + plus besoin d'aller dans le code pour gérer ses listes
  1545. // 1.0.3 : Pastebin => https://pastebin.com/RNWPdyyF
  1546. // + suppression de 'Courriers' quand la liste est vide
  1547. // + gestion de la banlist sur les profils
  1548. // 1.0.2 : https://pastebin.com/TJzUnw69
  1549. // + ajout de la liste des messages non lus au niveau de la barre des favs
  1550. // 1.0.1 : https://pastebin.com/mFv7z7wb
  1551. // + correction du bug des bans de topics
  1552. // + detection du favoris/ban à chaque page du topic
  1553. // 1.0.0 : https://pastebin.com/bjVmYYgM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement