Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.51 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. //Mettre à jour la présentation avec des screenshots
  15. //Passer les commentaires avec les fleches du clavier
  16. //Ouvirir et fermer un commentaire
  17. //-----------------------------------------------------
  18.  
  19. //Profils
  20. var favProfiles;
  21. var banProfiles;
  22. var currentProfile;
  23. var colorListProfil = [
  24. "White",
  25. "LightBlue",
  26. "LightCoral",
  27. "LightCyan",
  28. "LightGoldenRodYellow",
  29. "LightGrey",
  30. "LightGreen",
  31. "LightPink",
  32. "LightSalmon",
  33. "LightSeaGreen",
  34. "LightSkyBlue",
  35. "LightSlateGrey",
  36. "LightSteelBlue"
  37. ];
  38.  
  39. //Topic
  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. //debugger;
  54. //localStorage.removeItem("favs");
  55. //localStorage.removeItem("bans");
  56. //localStorage.removeItem("favProfiles");
  57. //localStorage.removeItem("banProfiles");
  58.  
  59. initCache();
  60.  
  61. var path = window.location.pathname;
  62.  
  63. if (path.startsWith('/profil')) {
  64. traiterProfil();
  65. } else {
  66. ajouterBarFav();
  67. if (path.startsWith('/forum')) {
  68. traiterForum();
  69. } else if (path.startsWith('/topic')) {
  70. traiterTopic();
  71. } else {
  72. console.log('Cas ' + path + " non traité.");
  73. }
  74. }
  75.  
  76. })();
  77.  
  78. function initCache() {
  79. bans = localStorage.bans === undefined ? [] : JSON.parse(localStorage.bans);
  80. favProfiles = localStorage.favProfiles === undefined ? [] : JSON.parse(localStorage.favProfiles);
  81. banProfiles = localStorage.banProfiles === undefined ? [] : JSON.parse(localStorage.banProfiles);
  82. }
  83.  
  84. function ajouterBarFav() {
  85.  
  86. var idCourrier = getId();
  87. var idFavoris = getId();
  88. var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
  89. barFav[0].children[1].innerHTML = "<section>"+
  90. " <div id=\""+idCourrier+"\"></div>"+
  91. " <div id=\""+idFavoris+"\">Favoris</div>"+
  92. "</section>";
  93.  
  94.  
  95. httpGetAsync("https://avenoel.org/messagerie", function (html) {
  96. var mails = html.getElementsByClassName("active");
  97.  
  98. if (mails.length > 2) {
  99. var innerHTMLCourrier = "Courriers";
  100.  
  101. for(var i = 1; i < mails.length -1; ++i) {
  102. innerHTMLCourrier += "<li>";
  103. innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
  104. innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
  105. innerHTMLCourrier += "</li>";
  106. }
  107.  
  108. document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
  109. }
  110. });
  111.  
  112. httpGetAsync("https://avenoel.org/favoris", function (html) {
  113. var list = html.getElementsByTagName("tBody")[0].children;
  114. var buttonBar = document.getElementById(idFavoris);
  115. var innerHTMLFav = "";
  116.  
  117. for(var i = 0; i < list.length; i++) {
  118. var fav = list[i];
  119.  
  120. fav.children[1].children[0].href = fav.children[0].children[0].getAttribute("href");
  121.  
  122. fav.removeChild(fav.children[2]);
  123. fav.removeChild(fav.children[2]);
  124. fav.removeChild(fav.children[2]);
  125. fav.removeChild(fav.children[0]);
  126. innerHTMLFav += "<li>" + fav.innerHTML + "</li>";
  127. }
  128.  
  129. document.getElementById(idFavoris).innerHTML += innerHTMLFav;
  130. });
  131.  
  132. }
  133.  
  134. //-----------------------------------------------------
  135. // Topic
  136. //-----------------------------------------------------
  137.  
  138. function traiterTopic() {
  139. var lstTopic = document.getElementsByClassName("topic-messages");
  140. var trsTopic = lstTopic[0].children;
  141. for(var iTopic = 0; iTopic < trsTopic.length; ++iTopic) {
  142. traiterTrTopic(trsTopic[iTopic]);
  143. }
  144.  
  145. traiterNavBarTopic();
  146. }
  147.  
  148.  
  149. function traiterNavBarTopic() {
  150.  
  151. var relativePath = "";
  152. getPath().split("-").splice(2).forEach(function(split) {
  153. relativePath += split + "-";
  154. });
  155. relativePath = relativePath.slice(0, -1);
  156.  
  157. var buttons = addButtonToNavBar(["buttonBan"]);
  158. var buttonBan = buttons[0];
  159.  
  160. // Bouton des bans
  161. var isInBan = contentsString(bans, relativePath) != -1;
  162. if (isInBan) {
  163. buttonBan.innerHTML = "DEBAN";
  164. buttonBan.onclick = function() {
  165. deleteFromCache(bans, "bans");
  166. };
  167. } else {
  168. buttonBan.innerHTML = "BAN";
  169. buttonBan.onclick = function() {
  170. addInCache(bans, "bans");
  171. };
  172. }
  173.  
  174. }
  175.  
  176. function addInCache(cacheList, cacheName) {
  177. console.log("addInCache : " + cacheName);
  178. cacheList.push(getPath());
  179. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  180. ajouterBarFav();
  181. traiterNavBarTopic();
  182. }
  183.  
  184. function deleteFromCache(cacheList, cacheName) {
  185. console.log("deleteFromCache : " + cacheName);
  186.  
  187. var relativePath = "";
  188. getPath().split("-").splice(2).forEach(function(split) {
  189. relativePath += split + "-";
  190. });
  191. relativePath = relativePath.slice(0, -1);
  192.  
  193. var i = contentsString(cacheList, relativePath);
  194. if (i !== -1) {
  195. cacheList.splice(i, 1);
  196. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  197. }
  198.  
  199. ajouterBarFav();
  200. traiterNavBarTopic();
  201. }
  202.  
  203. function traiterTrTopic(tr) {
  204.  
  205. var message = null;
  206. var rank = -1;
  207.  
  208. // Suppression des FDP
  209. banProfiles.forEach(function(connard) {
  210.  
  211. var id = getId();
  212. message = null;
  213. if (hasProfilLink(tr, connard.name)) {
  214. message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  215. }
  216. if (hasProfilAvatar(tr, connard.name)) {
  217. message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  218. }
  219.  
  220. if (message !== null) {
  221. rank = connard.rank;
  222. return;
  223. }
  224. });
  225.  
  226. if (rank == 2) {
  227. tr.innerHTML = message;
  228. } else {
  229. addButtonHiddenTopicMessage(tr, rank == 1);
  230. }
  231.  
  232. }
  233.  
  234. function addButtonHiddenTopicMessage(tr, isHidden) {
  235.  
  236. var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
  237. var content = tr.getElementsByClassName("message-content")[0];
  238. var header = tr.getElementsByClassName("message-header")[0];
  239. var ulHeader = header.getElementsByClassName("message-actions")[0];
  240. var footer = tr.getElementsByClassName("message-footer")[0];
  241.  
  242. var idButton = getId();
  243.  
  244. content.isHidden = isHidden;
  245. var innerButton = content.isHidden ? "Afficher" : "Masquer";
  246. ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
  247.  
  248. var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
  249. var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
  250.  
  251. var button = document.getElementById(idButton);
  252.  
  253. button.style.backgroundColor = "Transparent";
  254. button.style.border = "none";
  255.  
  256. button.onclick = function() {
  257. content.isHidden = !content.isHidden;
  258. button.innerHTML = content.isHidden ? imageUp : imageDown;
  259. content.style.display = content.isHidden ? "none" : "";
  260. footer.style.display = content.isHidden ? "none" : "";
  261. aside.style.display = content.isHidden ? "none" : "";
  262. };
  263. content.isHidden = !content.isHidden;
  264. button.onclick.apply();
  265. }
  266.  
  267. //-----------------------------------------------------
  268. // Forum
  269. //-----------------------------------------------------
  270.  
  271.  
  272. function traiterForum() {
  273. var lst = document.getElementsByClassName("table table-striped topics");
  274. var trs = lst[0].children[1].children;
  275. for(var i = 0; i < trs.length; ++i) {
  276. traiterTrForum(trs[i]);
  277. }
  278. }
  279.  
  280. function traiterTrForum(tr) {
  281.  
  282. // Suppression des caracteres ching chong
  283. if (tr.innerText.match(/[\u3400-\u9FBF]/)) {
  284. console.log("Suppression des caracteres ching chong");
  285. tr.innerHTML = "";
  286. return;
  287. }
  288.  
  289. // Suppression des FDP
  290. banProfiles.forEach(function(connard) {
  291. if (hasProfilLink(tr, connard.name)) {
  292. console.log("Suppression du FDP : " + connard.name);
  293. tr.innerHTML = "";
  294. return;
  295. }
  296. });
  297.  
  298. bans.forEach(function(url) {
  299. if (hasUrl(tr, url)) {
  300. console.log("Suppression du sujet : " + url);
  301. tr.innerHTML = "";
  302. return;
  303. }
  304. });
  305.  
  306. // Surlignage
  307. favProfiles.forEach(function(surligne) {
  308. if (hasProfilLink(tr, surligne.name)) {
  309. console.log("Surlignage : " + surligne.name);
  310. tr.style.background = colorListProfil[surligne.color];
  311. return;
  312. }
  313. });
  314.  
  315. }
  316.  
  317. //-----------------------------------------------------
  318. // Profil
  319. //-----------------------------------------------------
  320.  
  321. function traiterProfil() {
  322. var elem = document.getElementsByClassName("profile-wrapper-right");
  323. currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
  324.  
  325. elem[0].innerHTML += "Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div>";
  326. elem[0].innerHTML += "Favoris couleur <select id=\"idFavColor\"></select>";
  327.  
  328. // favoris ----------------------------------------------------------
  329. var isFav = false;
  330. var color = 0;
  331. favProfiles.forEach(function(fav) {
  332. if (fav.name === currentProfile) {
  333. isFav = true;
  334. color = fav.color;
  335. return;
  336. }
  337. });
  338.  
  339. var colorList = [];
  340. for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
  341. colorList.push(iColor);
  342. }
  343.  
  344. createComboBox("idFavColor", colorList);
  345. var comboFavColor = document.getElementById("idFavColor");
  346.  
  347. for (var j = 0; j < comboFavColor.length; j++) {
  348. comboFavColor[j].innerHTML = "";
  349. comboFavColor[j].style.backgroundColor = colorListProfil[j];
  350. }
  351.  
  352. if (isFav) {
  353. comboFavColor.selectedIndex = parseInt(color);
  354. comboFavColor.style.backgroundColor = colorListProfil[color];
  355. }
  356. detailRankProfile(rank);
  357. comboFavColor.onchange = function(event) {
  358. favProfile(event.target.selectedOptions[0].value);
  359. };
  360.  
  361. // bans ----------------------------------------------------------
  362. var isBan = false;
  363. var rank = 0;
  364. banProfiles.forEach(function(connard) {
  365. if (connard.name === currentProfile) {
  366. isBan = true;
  367. rank = connard.rank;
  368. return;
  369. }
  370. });
  371.  
  372. createComboBox("idBanRank", ["non","0","1","2"]);
  373. var comboBanRank = document.getElementById("idBanRank");
  374. if (isBan) {
  375. comboBanRank.selectedIndex = parseInt(rank) + 1;
  376. }
  377. detailRankProfile(rank);
  378. comboBanRank.onchange = function(event) {
  379. banProfile(event.target.selectedOptions[0].value);
  380. };
  381.  
  382. }
  383.  
  384. function favProfile(color) {
  385. console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
  386.  
  387. var index = -1;
  388. for(var i = 0; i < favProfiles.length; ++i) {
  389. if (stringContents(favProfiles[i].name, currentProfile)) {
  390. index = i;
  391. break;
  392. }
  393. }
  394.  
  395. if (index !== -1) {
  396. favProfiles.splice(index, 1);
  397. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  398. }
  399.  
  400. if (color !== "0") {
  401. favProfiles.push({name:currentProfile, color:color});
  402. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  403. }
  404.  
  405. document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
  406. }
  407.  
  408. function banProfile(rank) {
  409. console.log("banProfile : " + currentProfile + ", rang : " + rank);
  410.  
  411. var index = -1;
  412. for(var i = 0; i < banProfiles.length; ++i) {
  413. if (stringContents(banProfiles[i].name, currentProfile)) {
  414. index = i;
  415. break;
  416. }
  417. }
  418.  
  419. if (index !== -1) {
  420. banProfiles.splice(index, 1);
  421. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  422. }
  423.  
  424. if (rank !== "non") {
  425. banProfiles.push({name:currentProfile, rank:rank});
  426. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  427. }
  428.  
  429. detailRankProfile(rank);
  430. }
  431.  
  432. function detailRankProfile(rank) {
  433. var innerHTML;
  434. if (rank === "0") {
  435. innerHTML = "Ses sujets sont supprimés.";
  436. } else if (rank === "1") {
  437. innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
  438. } else if (rank === "2") {
  439. innerHTML = "Ses sujets et messages sont supprimés.";
  440. } else {
  441. innerHTML = "Non banni.";
  442. }
  443.  
  444. document.getElementById("idBanRankDetail").innerHTML = innerHTML;
  445. }
  446.  
  447. //-----------------------------------------------------
  448. // Utils
  449. //-----------------------------------------------------
  450.  
  451. function createImageButton(idButton, buttonHtml) {
  452. var button = document.getElementById(idButton);
  453. button.innerHTML = buttonHtml;
  454. return button;
  455. }
  456.  
  457. function createComboBox(idParent, list) {
  458. var sel = document.getElementById(idParent);
  459. var optionoption = null;
  460.  
  461. for(i = 0; i < list.length; i++) {
  462.  
  463. optionoption = document.createElement('option');
  464. optionoption.value = list[i];
  465. optionoption.innerHTML = list[i];
  466. sel.appendChild(optionoption);
  467. }
  468. return sel;
  469. }
  470.  
  471. function httpGetAsync(theUrl, callback)
  472. {
  473. var xmlHttp = new XMLHttpRequest();
  474. xmlHttp.onreadystatechange = function() {
  475. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  476. callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
  477. };
  478. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  479. xmlHttp.send(null);
  480. }
  481.  
  482. function contentsString(list, match) {
  483. for(var i = 0; i < list.length; ++i) {
  484. if (stringContents(list[i], match)) {
  485. return i;
  486. }
  487. }
  488. return -1;
  489. }
  490.  
  491. function getPath() {
  492. return url + window.location.pathname;
  493. }
  494.  
  495. function designTopButton(button) {
  496. button.style.color = "white";
  497. button.style.backgroundColor = "transparent";
  498. button.style.border = "none";
  499. }
  500.  
  501. function hasProfilLink(elem, name) {
  502. return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
  503. }
  504.  
  505. function hasProfilAvatar(elem, name) {
  506. return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
  507. }
  508.  
  509. function hasUrl(elem, url) {
  510. return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
  511. }
  512.  
  513. function stringContents(string, match) {
  514. return string.indexOf(match) !== -1;
  515. }
  516.  
  517. function addButtonToNavBar(names) {
  518.  
  519. var buttons = [];
  520.  
  521. if (document.getElementById(names[0]) === null) {
  522. var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
  523. var innerHTML = "";
  524. names.forEach(function(name) {
  525. innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
  526. });
  527. navbar[0].innerHTML += innerHTML;
  528. names.forEach(function(name) {
  529. designTopButton(document.getElementById(name));
  530. });
  531. }
  532.  
  533. names.forEach(function(name) {
  534. buttons.push(document.getElementById(name));
  535. });
  536.  
  537. return buttons;
  538. }
  539.  
  540. function getId() {
  541. return "id" + id++;
  542. }
  543.  
  544. //-----------------------------------------------------
  545. // Patch
  546. //-----------------------------------------------------
  547. //
  548. // 2.0.3 : Pastebin => Etape 3
  549. // + correction du bug d'affichage des courriers
  550. // 2.0.2 : Pastebin => https://pastebin.com/haqi3XRa
  551. // + Modification du bouton pour afficher/masquer
  552. // 2.0.1 : Pastebin => https://pastebin.com/vNmgUrCs
  553. // + Le clique sur le favoris emmene à la dernière page
  554. // 2.0.0 : Pastebin => https://pastebin.com/eHCt5h8E
  555. // + Prise en compte de la liste de favoris (affichage reste à droite)
  556. // L'icone du fichier n'est pas encore mise
  557. // + Changement du bouton afficher/masquer un commentaire.
  558. // 1.1.0 : Pastebin => https://pastebin.com/85F6ydsC
  559. // + gestion de la lovelist sur les profils
  560. // + plus besoin d'aller dans le code pour gérer ses listes
  561. // 1.0.3 : Pastebin => https://pastebin.com/RNWPdyyF
  562. // + suppression de 'Courriers' quand la liste est vide
  563. // + gestion de la banlist sur les profils
  564. // 1.0.2 : https://pastebin.com/TJzUnw69
  565. // + ajout de la liste des messages non lus au niveau de la barre des favs
  566. // 1.0.1 : https://pastebin.com/mFv7z7wb
  567. // + correction du bug des bans de topics
  568. // + detection du favoris/ban à chaque page du topic
  569. // 1.0.0 : https://pastebin.com/bjVmYYgM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement