Advertisement
Guest User

Untitled

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