Advertisement
Guest User

Untitled

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