Advertisement
Guest User

Untitled

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