Advertisement
Guest User

Untitled

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