Advertisement
Guest User

Untitled

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