Advertisement
Guest User

Untitled

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