Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
1,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name AveNoel
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  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. //Et si tu pouvais add une messagerie facebook like avec les mp qui s'affiche en bas, ça serait pas mal.
  15. //Et un je sais pas si c'est possible, mais recevoir une notif quand on nous cite serait parfait, des fois on rate des échanges intéressant juste parce qu'on oublie de check tout les mp
  16. //-----------------------------------------------------
  17.  
  18. //Profils
  19. var regexList;
  20. var bansRegex;
  21. var favProfiles;
  22. var banProfiles;
  23. var currentProfile;
  24. var colorListProfil = [
  25. "White",
  26. "LightBlue",
  27. "LightCoral",
  28. "LightCyan",
  29. "LightGoldenRodYellow",
  30. "LightGrey",
  31. "LightGreen",
  32. "LightPink",
  33. "LightSalmon",
  34. "LightSeaGreen",
  35. "LightSkyBlue",
  36. "LightSlateGrey",
  37. "LightSteelBlue"
  38. ];
  39.  
  40. //Topic
  41. var favs;
  42. var bans;
  43.  
  44. // Global
  45. var id = 0;
  46. var profil = {name:"rien"};
  47. const space = "&nbsp";
  48. const url = "https://avenoel.org";
  49. const imgQuote = "<img src=\"/images/topic/quote.png\" alt=\"Icône citation\" width=\"20\">";
  50. const imgEdit = "<img src=\"/images/topic/edit.png\" alt=\"Icône éditer\" title=\"Éditer le message\" width=\"20\">";
  51. const imgDelete = "<img src=\"/images/topic/delete.png\" alt=\"Icône suppression\" width=\"20\">";
  52.  
  53. (function() {
  54. 'use strict';
  55.  
  56. var t0 = performance.now();
  57.  
  58. //debugger;
  59. //localStorage.removeItem("favs");
  60. //localStorage.removeItem("bans");
  61. //localStorage.removeItem("favProfiles");
  62. //localStorage.removeItem("banProfiles");
  63.  
  64. initProfil();
  65. initFunctions();
  66. setInterval(initCache, 1500);
  67. initCache();
  68.  
  69. var path = window.location.pathname;
  70.  
  71. if (path.startsWith('/profil')) {
  72. traiterProfil();
  73. } else {
  74. ajouterBarFav();
  75. if (path.startsWith('/forum')) {
  76. traiterForum();
  77. } else if (path.startsWith('/topic')) {
  78. traiterTopic();
  79. } else if (path.startsWith('/messagerie')) {
  80. traiterMessagerie();
  81. } else {
  82. console.log('Cas ' + path + " non traité.");
  83. }
  84. }
  85.  
  86. enhanceTextArea();
  87. controlVersion();
  88.  
  89. var t1 = performance.now();
  90. console.log("Call to AveNoel took " + (t1 - t0) + " milliseconds.");
  91.  
  92. })();
  93.  
  94. function initProfil() {
  95. var split = document.getElementsByClassName('navbar-user-avatar')[0].parentElement.href.split("/");
  96. profil.name = split[split.length-1];
  97. }
  98.  
  99. function initFunctions() {
  100. if (!String.prototype.splice) {
  101. /**
  102. * {JSDoc}
  103. *
  104. * The splice() method changes the content of a string by removing a range of
  105. * characters and/or adding new characters.
  106. *
  107. * @this {String}
  108. * @param {number} start Index at which to start changing the string.
  109. * @param {number} delCount An integer indicating the number of old chars to remove.
  110. * @param {string} newSubStr The String that is spliced in.
  111. * @return {string} A new string with the spliced substring.
  112. */
  113. String.prototype.splice = function(start, delCount, newSubStr) {
  114. return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
  115. };
  116. }
  117. }
  118.  
  119. function initCache() {
  120. regexList = localStorage.regexList === undefined ? [] : JSON.parse(localStorage.regexList);
  121. bansRegex = localStorage.bansRegex === undefined ? [] : JSON.parse(localStorage.bansRegex);
  122. favs = localStorage.favs === undefined ? {} : JSON.parse(localStorage.favs);
  123. bans = localStorage.bans === undefined ? [] : JSON.parse(localStorage.bans);
  124. favProfiles = localStorage.favProfiles === undefined ? [] : JSON.parse(localStorage.favProfiles);
  125. banProfiles = localStorage.banProfiles === undefined ? [] : JSON.parse(localStorage.banProfiles);
  126. }
  127.  
  128. function controlVersion() {
  129. httpGetApiAsync("messages/1611709", function(res) {
  130.  
  131. var match = res.content.match(/[0-9]+\.[0-9]+\.[0-9]+/g);
  132. if (match && version !== match[0]) {
  133.  
  134. var patchNotes = res.content.split(match)[1].match(/[^\r\n]+/g);
  135. var div = document.getElementById('alertversion');
  136. var innerHTML =
  137. "La version " + match[0] + " est disponible => " +
  138. "<a href=\"https://avenoel.org/topic/101099-1-aide-voici-un-script-pour-vous-faciliter-la-vie-sur-avn\">ici</a>.";
  139. for(var i = 1; i < patchNotes.length -1; ++i) {
  140. innerHTML += "<li>" + patchNotes[i] + "</li>";
  141. }
  142. innerHTML +=
  143. "<br>N'oubliez pas de laisser un commentaire." +
  144. "<br><img class=\"board-noelshack\" src=\"https://image.noelshack.com/fichiers/2017/02/1484089609-coeur.png\">";
  145.  
  146. div.innerHTML = innerHTML;
  147. div.style.color = "red";
  148. }
  149. });
  150.  
  151.  
  152. }
  153.  
  154. //-----------------------------------------------------
  155. // Editeur de texte
  156. //-----------------------------------------------------
  157.  
  158. function enhanceTextArea() {
  159.  
  160. var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
  161. if (!textArea) {
  162. return;
  163. }
  164.  
  165. if (textArea.value.length > 0) {
  166. textArea.selectionStart = textArea.value.length;
  167. textArea.focus();
  168. }
  169.  
  170. var edit = function(tagIn, tagOut) {
  171.  
  172. var start = textArea.selectionStart;
  173. var end = textArea.selectionEnd;
  174. textArea.value = textArea.value.splice(textArea.selectionEnd, 0, tagOut).splice(textArea.selectionStart, 0, tagIn);
  175. textArea.selectionStart = start + tagIn.length;
  176. textArea.selectionEnd = end + tagIn.length;
  177. textArea.focus();
  178.  
  179. };
  180.  
  181. var textAreaButtons = document.getElementsByClassName("form-group bbcodes")[document.getElementsByClassName("form-group bbcodes").length - 1];
  182.  
  183. var list = [
  184. {name:"R", tagIn:"<color=red>", tagOut:"</color>", color:"red"},
  185. {name:"G", tagIn:"<color=green>", tagOut:"</color>", color:"green"},
  186. {name:"B", tagIn:"<color=blue>", tagOut:"</color>", color:"blue"}
  187. ];
  188. var div = document.createElement('div');
  189. list.forEach(function(each) {
  190.  
  191. div.innerHTML = "<button type=\"button\" class=\"btn\" tabindex=\"-1\" data-type=\"tag\"><span>" + each.name + "</span></button>";
  192. var btn = div.firstChild;
  193. textAreaButtons.appendChild(btn);
  194. btn.style.color = each.color;
  195. btn.onclick = function() {edit(each.tagIn, each.tagOut);};
  196.  
  197. });
  198.  
  199. div.remove();
  200.  
  201. textArea.onfocusout = function () {
  202. var value = textArea.value;
  203. regexList.forEach(function(each) {
  204. value = value.replace(new RegExp(each.reg, "gm"), each.res);
  205. });
  206.  
  207. // Mort aux cucks
  208. textArea.value = value
  209. .replace(new RegExp("cuck", "gm"), "candaule")
  210. .replace(new RegExp("Cuck", "gm"), "Candaule")
  211. .replace(new RegExp("CUCK", "gm"), "CANDAULE");
  212. };
  213.  
  214. }
  215.  
  216. //-----------------------------------------------------
  217. // Fav/Courriers
  218. //-----------------------------------------------------
  219.  
  220. function ajouterBarFav() {
  221.  
  222. var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
  223. if (barFav.length === 0) {
  224. return;
  225. }
  226.  
  227. var idCourrier = getId();
  228. var idFavoris = getId();
  229. barFav[0].replaceChild(barFav[0].children[0].cloneNode(true), barFav[0].children[0]);
  230.  
  231. var listDiv = barFav[0].children[1];
  232. listDiv.classList = [];
  233. listDiv.innerHTML =
  234. "<section>"+
  235. " <div id=\"alertversion\"></div>"+
  236. " <div id=\""+idCourrier+"\"></div>"+
  237. " <div id=\""+idFavoris+"\"></div>"+
  238. "</section>";
  239.  
  240. var rect = listDiv.getBoundingClientRect(),
  241. scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  242. var top = rect.top + scrollTop;
  243. var event = function(e) {
  244. if (window.scrollY > top) {
  245. listDiv.style.position = "absolute";
  246. listDiv.style.top = window.scrollY + 'px';
  247. } else {
  248. listDiv.style.position = null;
  249. listDiv.style.top = top + 'px';
  250. }
  251. };
  252. window.addEventListener('scroll', event);
  253. event.apply();
  254.  
  255. var documentTitle = document.title;
  256. var setMails = function(){
  257. httpGetAsync("https://avenoel.org/messagerie", function (html) {
  258. var mails = html.getElementsByClassName("active");
  259.  
  260. if (mails.length > 2) {
  261. document.title = "(" + (mails.length-2) + ") " + documentTitle;
  262. var innerHTMLCourrier = "Courrier" + ((mails.length-2) > 1 ? "s" : "") + " (" + (mails.length-2) + ")";
  263.  
  264. for(var i = 1; i < mails.length -1; ++i) {
  265. innerHTMLCourrier += "<li>";
  266. innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
  267. innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
  268. innerHTMLCourrier += "</li>";
  269. }
  270.  
  271. document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
  272. } else {
  273. document.title = documentTitle;
  274. document.getElementById(idCourrier).innerHTML = "";
  275. }
  276. });
  277. };
  278. setInterval(setMails, 30000);
  279. setMails.apply();
  280.  
  281. var setFavs = function(){
  282. httpGetAsync("https://avenoel.org/favoris", function (html) {
  283. var list = html.getElementsByTagName("tBody")[0].children;
  284. var buttonBar = document.getElementById(idFavoris);
  285. var innerHTMLFav = "Favoris";
  286.  
  287. for(var i = 0; i < list.length; i++) {
  288.  
  289. var fav = list[i];
  290. var nbDiff = "";
  291.  
  292. var href = fav.children[1].children[0].href;
  293. var nb = fav.children[3].innerHTML.trim();
  294.  
  295. if (fav.children[0].children[0].href === window.location.href) {
  296. favs[href] = nb;
  297. localStorage.setItem("favs", JSON.stringify(favs));
  298. }
  299.  
  300. if (favs[href]) {
  301. if( favs[href] !== nb) {
  302. nbDiff = "(" + (nb - favs[href]) + ") ";
  303. }
  304. } else {
  305. favs[href] = nb;
  306. localStorage.setItem("favs", JSON.stringify(favs));
  307. }
  308.  
  309. fav.children[1].children[0].href = fav.children[0].children[0].href;
  310.  
  311. fav.removeChild(fav.children[2]);
  312. fav.removeChild(fav.children[2]);
  313. fav.removeChild(fav.children[2]);
  314. fav.removeChild(fav.children[0]);
  315. innerHTMLFav += "<li>" + nbDiff + fav.innerHTML + "</li>";
  316. }
  317.  
  318. document.getElementById(idFavoris).innerHTML = innerHTMLFav;
  319.  
  320. });
  321. };
  322. setInterval(setFavs, 30000);
  323. setFavs.apply();
  324. }
  325.  
  326. //-----------------------------------------------------
  327. // Topic
  328. //-----------------------------------------------------
  329.  
  330. function traiterTopic() {
  331.  
  332. overloadButtonDeleteTopic();
  333.  
  334. var lstTopic = document.getElementsByClassName("topic-messages");
  335.  
  336. var trsTopic = lstTopic[0].children;
  337.  
  338. var listTop = [];
  339. document.onkeydown = function(event) {
  340.  
  341. if (true) {
  342. return;
  343. }
  344.  
  345. var newTop;
  346.  
  347. if (event.key === "ArrowUp") {
  348. newTop = findNewTop(true, listTop);
  349. }
  350.  
  351. if (event.key === "ArrowDown") {
  352. newTop = findNewTop(false, listTop);
  353. }
  354.  
  355. if (Number.isInteger(newTop)) {
  356. window.scrollTo(0, newTop);
  357. }
  358. };
  359.  
  360. listTop.push(0);
  361. for(var iTopic = 0; iTopic < trsTopic.length; ++iTopic) {
  362. listTop.push(traiterTrTopic(trsTopic[iTopic]));
  363. collapseQuote(trsTopic[iTopic]);
  364. overloadButtons(trsTopic[iTopic]);
  365. }
  366.  
  367. traiterNavBarTopic();
  368. }
  369.  
  370. function findNewTop(isUp, listTop) {
  371. for(var i = 0; i < listTop.length - 1; ++i) {
  372. if (listTop[i] <= window.scrollY && window.scrollY <= listTop[i + 1]) {
  373. return isUp ? listTop[i] : listTop[i + 1];
  374. }
  375. }
  376. }
  377.  
  378. function traiterNavBarTopic() {
  379.  
  380. var relativePath = "";
  381. getPath().split("-").splice(2).forEach(function(split) {
  382. relativePath += split + "-";
  383. });
  384. relativePath = relativePath.slice(0, -1);
  385.  
  386. var buttons = addButtonToNavBar(["buttonBan"]);
  387. var buttonBan = buttons[0];
  388.  
  389. // Bouton des bans
  390. var isInBan = contentsString(bans, relativePath) != -1;
  391. if (isInBan) {
  392. buttonBan.innerHTML = "DEBAN";
  393. buttonBan.onclick = function() {
  394. deleteFromCache(bans, "bans");
  395. };
  396. } else {
  397. buttonBan.innerHTML = "BAN";
  398. buttonBan.onclick = function() {
  399. addInCache(bans, "bans");
  400. };
  401. }
  402.  
  403. }
  404.  
  405. function addInCache(cacheList, cacheName) {
  406. console.log("addInCache : " + cacheName);
  407. cacheList.push(getPath());
  408. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  409. ajouterBarFav();
  410. traiterNavBarTopic();
  411. }
  412.  
  413. function deleteFromCache(cacheList, cacheName) {
  414. console.log("deleteFromCache : " + cacheName);
  415.  
  416. var relativePath = "";
  417. getPath().split("-").splice(2).forEach(function(split) {
  418. relativePath += split + "-";
  419. });
  420. relativePath = relativePath.slice(0, -1);
  421.  
  422. var i = contentsString(cacheList, relativePath);
  423. if (i !== -1) {
  424. cacheList.splice(i, 1);
  425. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  426. }
  427.  
  428. ajouterBarFav();
  429. traiterNavBarTopic();
  430. }
  431.  
  432. function traiterTrTopic(tr) {
  433.  
  434. var message = null;
  435. var rank = -1;
  436.  
  437. // Suppression des FDP
  438. banProfiles.some(function(connard) {
  439.  
  440. var id = getId();
  441. message = null;
  442. if (hasProfilLink(tr, connard.name)) {
  443. message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  444. }
  445. if (hasProfilAvatar(tr, connard.name)) {
  446. message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  447. }
  448.  
  449. if (message !== null) {
  450. rank = connard.rank;
  451. return true;
  452. }
  453.  
  454. return false;
  455. });
  456.  
  457. if (rank == 2) {
  458. tr.innerHTML = message;
  459. tr.focus();
  460. } else {
  461. addButtonHiddenTopicMessage(tr, rank == 1);
  462. }
  463.  
  464. return tr.offsetTop;//getBoundingClientRect().top + window.pageYOffset;
  465. }
  466.  
  467. function collapseQuote(tr) {
  468.  
  469. var content = tr.getElementsByClassName("message-content")[0];
  470. if (!content) {
  471. return;
  472. }
  473.  
  474. var lines = content.innerHTML.match(/[^\r\n]+/g);
  475.  
  476. var ids = [];
  477. var currentLine;
  478. var lastRank = -1;
  479. var currentRank = -1;
  480. for(var i = lines.length - 1; i > -1; --i) {
  481. currentRank = calculRank(lines[i]);
  482.  
  483. if (lastRank > 0 && currentRank > lastRank) {
  484. lines.splice(i + 1, 0, "</div>");
  485. } else if (currentRank > 0 && currentRank < lastRank) {
  486.  
  487. var idButton = getId();
  488. var idDiv = getId();
  489. var beforeButton = "";
  490. for(var iGt = 0; iGt < currentRank; ++iGt) {
  491. beforeButton += "&gt; ";
  492. }
  493.  
  494. var buttonAll = "";
  495. if (currentRank === 1) {
  496. var idButtonAll = "buttonAll" + getId();
  497. buttonAll = "<button id=\"" + idButtonAll + "\" ></button>";
  498. ids.push({idButton:idButtonAll, idDiv:idDiv});
  499. }
  500.  
  501. var maskInnerHTML = "<span class=\"message-content-quote\">" + beforeButton + "<i><button id=\"" + idButton + "\" ></button>" + buttonAll + "</i></span><div id=\"" + idDiv + "\" >";
  502. ids.push({idButton:idButton, idDiv:idDiv});
  503. lines.splice(i + 1, 0, maskInnerHTML);
  504. }
  505.  
  506. lastRank = currentRank;
  507. }
  508.  
  509. content.innerHTML = lines.join('');
  510. addCollapseEvent(tr, ids);
  511. }
  512.  
  513. function addCollapseEvent(tr, ids) {
  514. ids.forEach(function(id) {
  515. var button = document.getElementById(id.idButton);
  516. button.style.border = "none";
  517. button.innerHTML = ">";
  518. button.style.textAlign = "center";
  519. var div = document.getElementById(id.idDiv);
  520. div.style.display = "none";
  521.  
  522. if (id.idButton.startsWith("buttonAll")) {
  523. button.innerHTML = "=>";
  524. button.onclick = function() {
  525.  
  526. button.innerHTML = button.innerHTML === "&lt;=" ? "=&gt;" : "&lt;=";
  527. var innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  528. var buttonList = div.getElementsByTagName("button");
  529. for (var i = 0; i < buttonList.length; i++) {
  530. buttonList[i].innerHTML = innerHTML;
  531. }
  532.  
  533. var divList = div.getElementsByTagName("div");
  534. var display = button.innerHTML === "&lt;=" ? "" : "none";
  535. div.style.display = display;
  536. for (var j = 0; j < divList.length; j++) {
  537. divList[j].style.display = display;
  538. }
  539.  
  540. button.previousSibling.innerHTML = button.innerHTML === "&lt;=" ? "&lt;" : "&gt;";
  541.  
  542. };
  543. } else {
  544. button.onclick = function() {
  545.  
  546. button.innerHTML = button.innerHTML === "&lt;" ? "&gt;" : "&lt;";
  547. div.style.display = div.style.display === "none" ? "" : "none";
  548.  
  549. if (button.nextSibling !== null) {
  550. button.nextSibling.innerHTML = button.innerHTML === "&lt;" ? "&lt;=" : "=&gt";
  551. }
  552. };
  553. }
  554. });
  555. }
  556.  
  557. function calculRank(line) {
  558. var rank = -1;
  559. var index;
  560. var matcher = "quote\">&gt; ";
  561.  
  562. while (index != -1) {
  563. rank++;
  564. index = line.indexOf(matcher);
  565. matcher += "&gt; ";
  566. }
  567.  
  568. return rank;
  569. }
  570.  
  571. function addButtonHiddenTopicMessage(tr, isHidden) {
  572.  
  573. var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
  574. var content = tr.getElementsByClassName("message-content")[0];
  575. var header = tr.getElementsByClassName("message-header")[0];
  576. var ulHeader = header.getElementsByClassName("message-actions")[0];
  577. var footer = tr.getElementsByClassName("message-footer")[0];
  578.  
  579. var idButton = getId();
  580.  
  581. content.isHidden = isHidden;
  582. var innerButton = content.isHidden ? "Afficher" : "Masquer";
  583. ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
  584.  
  585. var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
  586. var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
  587.  
  588. var button = document.getElementById(idButton);
  589.  
  590. button.style.backgroundColor = "Transparent";
  591. button.style.border = "none";
  592.  
  593. button.onclick = function() {
  594. content.isHidden = !content.isHidden;
  595. button.innerHTML = content.isHidden ? imageUp : imageDown;
  596. content.style.display = content.isHidden ? "none" : "";
  597. footer.style.display = content.isHidden ? "none" : "";
  598. aside.style.display = content.isHidden ? "none" : "";
  599. };
  600. content.isHidden = !content.isHidden;
  601. button.onclick.apply();
  602. }
  603.  
  604. function overloadButtons(tr) {
  605. var header = tr.getElementsByClassName("message-header")[0];
  606. if (!header) {
  607. return;
  608. }
  609.  
  610. var imgs = header.getElementsByTagName("img");
  611. var img;
  612. for(var i = 0; i < imgs.length; ++i) {
  613. if (imgs[i].src === "https://avenoel.org/images/topic/delete.png") {
  614. img = imgs[i];
  615. }
  616. }
  617.  
  618. if (!img) {
  619. return;
  620. }
  621.  
  622. var button = img.parentElement;
  623. var href = button.href;
  624. button.href = "#";
  625. button.onclick = function() {
  626. if (window.confirm("Voulez vous supprimer le message ?")) {
  627. window.location.href = href;
  628. }
  629. };
  630.  
  631. }
  632.  
  633. function overloadButtonDeleteTopic() {
  634.  
  635. var buttons = document.getElementsByClassName("btn btn-danger");
  636. if (!buttons) {
  637. return;
  638. }
  639.  
  640. for(var i = 0; i < buttons.length; ++i) {
  641.  
  642. var button = buttons[i];
  643. var href = button.href;
  644. button.href = "#";
  645. button.onclick = function() {
  646. if (window.confirm("Voulez vous " + this.innerHTML.toLowerCase() + " le topic ?")) {
  647. window.location.href = href;
  648. }
  649. };
  650. }
  651.  
  652. }
  653.  
  654. //-----------------------------------------------------
  655. // Forum
  656. //-----------------------------------------------------
  657.  
  658.  
  659. function traiterForum() {
  660. var lst = document.getElementsByClassName("table table-striped topics");
  661. var trs = lst[0].children[1].children;
  662. for(var i = 0; i < trs.length; ++i) {
  663. traiterTrForum(trs[i]);
  664. }
  665. }
  666.  
  667. function traiterTrForum(tr) {
  668.  
  669. // Suppression des caracteres ching chong
  670. if (tr.innerText.match(/[\u3400-\u9FBF]/)) {
  671. console.log("Suppression des caracteres ching chong");
  672. tr.innerHTML = "";
  673. return;
  674. }
  675.  
  676. // Suppression des FDP
  677. if (banProfiles.some(function(connard) {
  678. if (hasProfilLink(tr, connard.name)) {
  679. console.log("Suppression du FDP : " + connard.name);
  680. tr.innerHTML = "";
  681. return true;
  682. }
  683. return false;
  684. })) {
  685. return;
  686. }
  687.  
  688. if (bans.some(function(url) {
  689. if (hasUrl(tr, url)) {
  690. console.log("Suppression du sujet : " + url);
  691. tr.innerHTML = "";
  692. return true;
  693. }
  694. return false;
  695. })) {
  696. return;
  697. }
  698.  
  699. if (bansRegex.some(function(regex) {
  700. if (tr.innerHTML.match(new RegExp(regex, "gm"))) {
  701. console.log("Suppression du sujet regex : " + regex);
  702. tr.innerHTML = "";
  703. return true;
  704. }
  705. return false;
  706. })) {
  707. return;
  708. }
  709.  
  710. // Surlignage
  711. if (favProfiles.some(function(surligne) {
  712. if (hasProfilLink(tr, surligne.name)) {
  713. console.log("Surlignage : " + surligne.name);
  714. tr.style.background = colorListProfil[surligne.color];
  715. return true;
  716. }
  717. return false;
  718. })) {
  719. return;
  720. }
  721.  
  722. }
  723.  
  724. //-----------------------------------------------------
  725. // Profil
  726. //-----------------------------------------------------
  727.  
  728. function traiterProfil() {
  729. var isMine = profil.name === document.getElementsByTagName("h2")[0].innerHTML;
  730. var elem = document.getElementsByClassName("profile-wrapper-right");
  731. currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
  732.  
  733. elem[0].innerHTML += "<div " + (isMine ? "hidden" : "") + ">Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div></div>";
  734. elem[0].innerHTML += "Favoris couleur <select id=\"idFavColor\"></select>";
  735.  
  736. // favoris ----------------------------------------------------------
  737. var isFav = false;
  738. var color = 0;
  739. favProfiles.some(function(fav) {
  740. if (fav.name === currentProfile) {
  741. isFav = true;
  742. color = fav.color;
  743. return true;
  744. }
  745. return false;
  746. });
  747.  
  748. var colorList = [];
  749. for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
  750. colorList.push(iColor);
  751. }
  752.  
  753. createComboBox("idFavColor", colorList);
  754. var comboFavColor = document.getElementById("idFavColor");
  755.  
  756. for (var j = 0; j < comboFavColor.length; j++) {
  757. comboFavColor[j].innerHTML = "";
  758. comboFavColor[j].style.backgroundColor = colorListProfil[j];
  759. }
  760.  
  761. if (isFav) {
  762. comboFavColor.selectedIndex = parseInt(color);
  763. comboFavColor.style.backgroundColor = colorListProfil[color];
  764. }
  765.  
  766. comboFavColor.onchange = function(event) {
  767. favProfile(event.target.selectedOptions[0].value);
  768. };
  769.  
  770. // bans ----------------------------------------------------------
  771. detailRankProfile();
  772. var isBan = false;
  773. var rank = 0;
  774. banProfiles.forEach(function(connard) {
  775. if (connard.name === currentProfile) {
  776. isBan = true;
  777. rank = connard.rank;
  778. return;
  779. }
  780. });
  781.  
  782. createComboBox("idBanRank", ["non","0","1","2"]);
  783. var comboBanRank = document.getElementById("idBanRank");
  784. if (isBan) {
  785. comboBanRank.selectedIndex = parseInt(rank) + 1;
  786. }
  787. detailRankProfile(rank);
  788. comboBanRank.onchange = function(event) {
  789. banProfile(event.target.selectedOptions[0].value);
  790. };
  791.  
  792. if (isMine) {
  793. afficherConfig();
  794. }
  795.  
  796. }
  797.  
  798. function afficherConfig() {
  799. var container = document.getElementsByClassName("col-md-7 col-centered profile")[0];
  800. var editorContainer = container.appendChild(container.children[0].cloneNode(true));
  801. editorContainer.style.textAlign = "left";
  802. editorContainer.style.marginTop = "15px";
  803. editorContainer.innerHTML = "";
  804. var config = container.appendChild(container.children[0].cloneNode(true));
  805. config.style.textAlign = "left";
  806. config.style.marginTop = "15px";
  807.  
  808. var idEditor = getId();
  809. var idTopic = getId();
  810. var idBannis = getId();
  811.  
  812. config.innerHTML =
  813. "<div>Liste mots clés de l'éditeur de texte :</div>"+
  814. "<div id=\"" + idEditor + "\"></div>"+
  815. "<br>"+
  816. "<div>Liste mots clés du masques des sujets :</div>"+
  817. "<div id=\"" + idTopic + "\"></div>"+
  818. "<br>"+
  819. "<div>Liste des bannis :</div>"+
  820. "<div id=\"" + idBannis + "\"></div>";
  821.  
  822. addEditorToProfil(editorContainer);
  823. createConfigEditor(document.getElementById(idEditor));
  824. createConfigTopic(document.getElementById(idTopic));
  825. createConfigBannis(document.getElementById(idBannis));
  826. }
  827.  
  828. function addEditorToProfil(container) {
  829. if (true) {
  830. container.style.display = "none";
  831. }
  832. httpGetAsync("https://avenoel.org/forum", function (html) {
  833. var form = html.getElementsByTagName("form")[1];
  834.  
  835. //var risi = html.getElementsByClassName("btn risi-wlogo")[0];
  836. // risi.formAction = "https://avenoel.org/forum/#risibank";
  837. // console.log(risi.formAction);
  838.  
  839. container.appendChild(form.children[2]);
  840. container.appendChild(form.children[2]);
  841. container.appendChild(form.children[2]);
  842. enhanceTextArea();
  843. });
  844. }
  845.  
  846. function createConfigEditor(container) {
  847.  
  848. var lines = [];
  849. var innerHTML = "<li>";
  850. regexList.forEach(function (each) {
  851.  
  852. var res;
  853. if (each.res.startsWith("https://")) {
  854. res = "<img class=\"board-noelshack\" src=\"" + each.res + "\">";
  855. } else {
  856. res = each.res;
  857. }
  858.  
  859. var idButton = getId();
  860. innerHTML +=
  861. each.reg + " => " + res + space +
  862. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  863. "</li>" +
  864. "<li>";
  865. lines.push({id:idButton, each:each});
  866. });
  867.  
  868. var idButtonPlus = getId();
  869. var idInputKey = getId();
  870. var idInputValue = getId();
  871. innerHTML +=
  872. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  873. " => " +
  874. "<input class=\"profile-biography\" id=\"" + idInputValue + "\" type=\"text\" style=\"height: 30px;\"/>" +
  875. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  876. "</li>";
  877.  
  878. container.innerHTML = innerHTML;
  879.  
  880. lines.forEach(function (line, i) {
  881. var button = document.getElementById(line.id);
  882. button.style.backgroundColor = "Transparent";
  883. button.style.border = "none";
  884.  
  885. button.onclick = function() {
  886. regexList.splice(i, 1);
  887. localStorage.setItem("regexList", JSON.stringify(regexList));
  888. createConfigEditor(container);
  889. };
  890. });
  891.  
  892.  
  893. var buttonPlus = document.getElementById(idButtonPlus);
  894. buttonPlus.style.backgroundColor = "Transparent";
  895. buttonPlus.style.border = "none";
  896.  
  897. buttonPlus.onclick = function() {
  898. regexList.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  899. localStorage.setItem("regexList", JSON.stringify(regexList));
  900. createConfigEditor(container);
  901. };
  902. }
  903.  
  904. function createConfigTopic(container) {
  905.  
  906. var lines = [];
  907. var innerHTML = "<li>";
  908. bansRegex.forEach(function (each) {
  909. var idButton = getId();
  910. innerHTML +=
  911. each + space +
  912. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  913. "</li>" +
  914. "<li>";
  915. lines.push({id:idButton, each:each});
  916. });
  917.  
  918. var idButtonPlus = getId();
  919. var idInputKey = getId();
  920. innerHTML +=
  921. "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  922. "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  923. "</li>";
  924.  
  925. container.innerHTML = innerHTML;
  926.  
  927. lines.forEach(function (line, i) {
  928. var button = document.getElementById(line.id);
  929. button.style.backgroundColor = "Transparent";
  930. button.style.border = "none";
  931.  
  932. button.onclick = function() {
  933. bansRegex.splice(i, 1);
  934. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  935. createConfigTopic(container);
  936. };
  937. });
  938.  
  939.  
  940. var buttonPlus = document.getElementById(idButtonPlus);
  941. buttonPlus.style.backgroundColor = "Transparent";
  942. buttonPlus.style.border = "none";
  943.  
  944. buttonPlus.onclick = function() {
  945. bansRegex.push(document.getElementById(idInputKey).value);
  946. localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
  947. createConfigTopic(container);
  948. };
  949.  
  950. }
  951.  
  952. function createConfigBannis(container) {
  953.  
  954. var lines = [];
  955. var idButtonPlus = getId();
  956. var idInputKey = getId();
  957.  
  958. var innerHTML =
  959. // "<li><input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
  960. // "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
  961. // "</li>"+
  962. "<ul style=\" columns: 3; -webkit-columns: 3; -moz-columns: 3;\">";
  963.  
  964. banProfiles.forEach(function (each) {
  965. var idButton = getId();
  966. innerHTML +=
  967. "<li>"+
  968. each.name + " / " + each.rank + space +
  969. "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
  970. "</li>";
  971. lines.push({id:idButton, each:each});
  972. });
  973. innerHTML += "</ul>";
  974. container.innerHTML = innerHTML;
  975.  
  976. lines.forEach(function (line, i) {
  977. var button = document.getElementById(line.id);
  978. button.style.backgroundColor = "Transparent";
  979. button.style.border = "none";
  980.  
  981. button.onclick = function() {
  982. banProfiles.splice(i, 1);
  983. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  984. createConfigBannis(container);
  985. };
  986. });
  987.  
  988.  
  989. // var buttonPlus = document.getElementById(idButtonPlus);
  990. // buttonPlus.style.backgroundColor = "Transparent";
  991. // buttonPlus.style.border = "none";
  992.  
  993. // buttonPlus.onclick = function() {
  994. // banProfiles.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
  995. // localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  996. // createConfigBannis(container);
  997. // };
  998. }
  999.  
  1000. function favProfile(color) {
  1001. console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
  1002.  
  1003. var index = -1;
  1004. for(var i = 0; i < favProfiles.length; ++i) {
  1005. if (stringContents(favProfiles[i].name, currentProfile)) {
  1006. index = i;
  1007. break;
  1008. }
  1009. }
  1010.  
  1011. if (index !== -1) {
  1012. favProfiles.splice(index, 1);
  1013. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1014. }
  1015.  
  1016. if (color !== "0") {
  1017. favProfiles.push({name:currentProfile, color:color});
  1018. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  1019. }
  1020.  
  1021. document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
  1022. }
  1023.  
  1024. function banProfile(rank) {
  1025. console.log("banProfile : " + currentProfile + ", rang : " + rank);
  1026.  
  1027. var index = -1;
  1028. for(var i = 0; i < banProfiles.length; ++i) {
  1029. if (stringContents(banProfiles[i].name, currentProfile)) {
  1030. index = i;
  1031. break;
  1032. }
  1033. }
  1034.  
  1035. if (index !== -1) {
  1036. banProfiles.splice(index, 1);
  1037. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1038. }
  1039.  
  1040. if (rank !== "non") {
  1041. banProfiles.push({name:currentProfile, rank:rank});
  1042. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  1043. }
  1044.  
  1045. detailRankProfile(rank);
  1046. }
  1047.  
  1048. function detailRankProfile(rank) {
  1049. var innerHTML;
  1050. if (rank === "0") {
  1051. innerHTML = "Ses sujets sont supprimés.";
  1052. } else if (rank === "1") {
  1053. innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
  1054. } else if (rank === "2") {
  1055. innerHTML = "Ses sujets et messages sont supprimés.";
  1056. } else {
  1057. innerHTML = "Non banni.";
  1058. }
  1059.  
  1060. document.getElementById("idBanRankDetail").innerHTML = innerHTML;
  1061. }
  1062.  
  1063. //-----------------------------------------------------
  1064. // Messagerie
  1065. //-----------------------------------------------------
  1066.  
  1067. function traiterMessagerie() {
  1068. var button = document.getElementsByClassName("btn btn-danger")[0];
  1069. if (!button) {
  1070. return;
  1071. }
  1072. button.parentElement.onsubmit = function() {
  1073. return window.confirm("Voulez vous quittez le MP ?");
  1074. };
  1075. }
  1076.  
  1077. //-----------------------------------------------------
  1078. // Utils
  1079. //-----------------------------------------------------
  1080.  
  1081. function createImageButton(idButton, buttonHtml) {
  1082. var button = document.getElementById(idButton);
  1083. button.innerHTML = buttonHtml;
  1084. return button;
  1085. }
  1086.  
  1087. function createComboBox(idParent, list) {
  1088. var sel = document.getElementById(idParent);
  1089. var optionoption = null;
  1090.  
  1091. for(i = 0; i < list.length; i++) {
  1092.  
  1093. optionoption = document.createElement('option');
  1094. optionoption.value = list[i];
  1095. optionoption.innerHTML = list[i];
  1096. sel.appendChild(optionoption);
  1097. }
  1098. return sel;
  1099. }
  1100.  
  1101. function httpGetAsync(theUrl, callback) {
  1102. var xmlHttp = new XMLHttpRequest();
  1103. xmlHttp.onreadystatechange = function() {
  1104. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  1105. callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
  1106. };
  1107. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  1108. xmlHttp.send(null);
  1109. }
  1110.  
  1111. function httpGetApiAsync(path, callback) {
  1112. var xmlHttp = new XMLHttpRequest();
  1113. xmlHttp.onreadystatechange = function() {
  1114. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  1115. callback(JSON.parse(xmlHttp.responseText).data);
  1116. };
  1117. xmlHttp.open("GET", "https://avenoel.org/api/v1/" + path, true); // true for asynchronous
  1118. xmlHttp.send(null);
  1119. }
  1120.  
  1121. function contentsString(list, match) {
  1122. for(var i = 0; i < list.length; ++i) {
  1123. if (stringContents(list[i], match)) {
  1124. return i;
  1125. }
  1126. }
  1127. return -1;
  1128. }
  1129.  
  1130. function getPath() {
  1131. return url + window.location.pathname;
  1132. }
  1133.  
  1134. function designTopButton(button) {
  1135. button.style.color = "white";
  1136. button.style.backgroundColor = "transparent";
  1137. button.style.border = "none";
  1138. }
  1139.  
  1140. function hasProfilLink(elem, name) {
  1141. return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
  1142. }
  1143.  
  1144. function hasProfilAvatar(elem, name) {
  1145. return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
  1146. }
  1147.  
  1148. function hasUrl(elem, url) {
  1149. return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
  1150. }
  1151.  
  1152. function stringContents(string, match) {
  1153. return string.indexOf(match) !== -1;
  1154. }
  1155.  
  1156. function addButtonToNavBar(names) {
  1157.  
  1158. var buttons = [];
  1159.  
  1160. if (document.getElementById(names[0]) === null) {
  1161. var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
  1162. var innerHTML = "";
  1163. names.forEach(function(name) {
  1164. innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
  1165. });
  1166. navbar[0].innerHTML += innerHTML;
  1167. names.forEach(function(name) {
  1168. designTopButton(document.getElementById(name));
  1169. });
  1170. }
  1171.  
  1172. names.forEach(function(name) {
  1173. buttons.push(document.getElementById(name));
  1174. });
  1175.  
  1176. return buttons;
  1177. }
  1178.  
  1179. function getId() {
  1180. return "id" + id++;
  1181. }
  1182.  
  1183. //-----------------------------------------------------
  1184. // Patch
  1185. //-----------------------------------------------------
  1186. //
  1187. var version = "3.1.0";
  1188. // 3.1.0 : Pastebin => Etape 3
  1189. // + fin de la gestion des configs des données en cache
  1190. // 3.0.0 : Pastebin => https://pastebin.com/SeqMW35E
  1191. // + début de la page de config dans le profil
  1192. // + Ajout de la gestion des mots clés éditeur dans le profil
  1193. // 2.6.0 : Pastebin => https://pastebin.com/17GWSM7A
  1194. // + initialisation de la page de configuration de l'appli
  1195. // + ajout du ban de topic par mots clés
  1196. // + optimisation de l'affichage des sujets
  1197. // 2.5.0 : Pastebin => https://pastebin.com/JKKB1RJi
  1198. // + ajout d'une liste de mots clés qui seront transformés dans l'éditeur.
  1199. // 2.4.0 : Pastebin => https://pastebin.com/JCfGHLZ4
  1200. // + ajout des dialogs de confirmation pour la suppression des topics/messages et ignorer.
  1201. // + ajout des modifs dans la notifs des patchs.
  1202. // 2.3.0 : Pastebin => https://pastebin.com/QXe2AJ6v
  1203. // + Ajout d'une popup de confirmation pour quitter les MP
  1204. // 2.2.0 : Pastebin => https://pastebin.com/0gPthPD4
  1205. // + ajout d'un bouton pour afficher/masquer toutes les citations.
  1206. // + amélioration de l'affichage de la nouvelle version
  1207. // 2.1.0 : https://pastebin.com/T2dP5ryX
  1208. // + controle de la version
  1209. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  1210. // + controle de la version
  1211. // + affichage du nombre de postes dans les favoris depuis la dernière visite
  1212. // 2.0.8 : Pastebin => https://pastebin.com/21a6u01a
  1213. // + correction du bug sur les citations (redirection bas de page)
  1214. // 2.0.7 : Pastebin => https://pastebin.com/cD6VqLUY
  1215. // + correction d'un bug sur la barre des favoris
  1216. // + ajout de nouvelles actions dans l'éditeur de texte
  1217. // + la barre des courriers est rafraichie toutes les 30s
  1218. // 2.0.6 : Pastebin => https://pastebin.com/GvTLjLaF
  1219. // + l'élément favoris/courrier se déplace avec le scroll
  1220. // 2.0.5 : Pastebin => https://pastebin.com/pNqRphzh
  1221. // + ajout du nombre de courriers non lus sur l'onglet
  1222. // + possibilité d'afficher/masquer les citiations (masquées par défaut)
  1223. // 2.0.4 : Pastebin => https://pastebin.com/4mCdppfi
  1224. // + affichage de la liste des favoris dans les topics noirs
  1225. // + correction bug sur les BL
  1226. // + optimisation des listes
  1227. // 2.0.3 : Pastebin =>https://pastebin.com/nPvLrBbV
  1228. // + correction du bug d'affichage des courriers
  1229. // 2.0.2 : Pastebin => https://pastebin.com/haqi3XRa
  1230. // + Modification du bouton pour afficher/masquer
  1231. // 2.0.1 : Pastebin => https://pastebin.com/vNmgUrCs
  1232. // + Le clique sur le favoris emmene à la dernière page
  1233. // 2.0.0 : Pastebin => https://pastebin.com/eHCt5h8E
  1234. // + Prise en compte de la liste de favoris (affichage reste à droite)
  1235. // L'icone du fichier n'est pas encore mise
  1236. // + Changement du bouton afficher/masquer un commentaire.
  1237. // 1.1.0 : Pastebin => https://pastebin.com/85F6ydsC
  1238. // + gestion de la lovelist sur les profils
  1239. // + plus besoin d'aller dans le code pour gérer ses listes
  1240. // 1.0.3 : Pastebin => https://pastebin.com/RNWPdyyF
  1241. // + suppression de 'Courriers' quand la liste est vide
  1242. // + gestion de la banlist sur les profils
  1243. // 1.0.2 : https://pastebin.com/TJzUnw69
  1244. // + ajout de la liste des messages non lus au niveau de la barre des favs
  1245. // 1.0.1 : https://pastebin.com/mFv7z7wb
  1246. // + correction du bug des bans de topics
  1247. // + detection du favoris/ban à chaque page du topic
  1248. // 1.0.0 : https://pastebin.com/bjVmYYgM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement