Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.48 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. var innerHTML =
  90. "<section>"+
  91. " <div id=\""+idCourrier+"\"><div>"+
  92. " <div id=\""+idFavoris+"\">Favoris</div>"+
  93. "</section>";
  94. barFav[0].children[1].innerHTML = innerHTML;
  95.  
  96. httpGetAsync("https://avenoel.org/favoris", function (html) {
  97. var list = html.getElementsByTagName("tBody")[0].children;
  98. var buttonBar = document.getElementById(idFavoris);
  99. var innerHTML = "";
  100.  
  101. //debugger;
  102. for(var i = 0; i < list.length; i++) {
  103. var fav = list[i];
  104.  
  105. fav.children[1].children[0].href = fav.children[0].children[0].getAttribute("href");
  106.  
  107. fav.removeChild(fav.children[2]);
  108. fav.removeChild(fav.children[2]);
  109. fav.removeChild(fav.children[2]);
  110. fav.removeChild(fav.children[0]);
  111. innerHTML += "<li>" + fav.innerHTML + "</li>";
  112. }
  113. buttonBar.innerHTML += innerHTML;
  114. });
  115.  
  116. httpGetAsync("https://avenoel.org/messagerie", function (html) {
  117. var mails = html.getElementsByClassName("active");
  118.  
  119. if (mails.length > 2) {
  120. var innerHTMLCourrier = "<div>Courriers";
  121.  
  122. for(var i = 1; i < mails.length -1; ++i) {
  123. innerHTMLCourrier += "<li>";
  124. innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
  125. innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
  126. innerHTMLCourrier += "</li>";
  127. }
  128.  
  129. innerHTMLCourrier += "</div>";
  130. document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
  131. }
  132. });
  133.  
  134. }
  135.  
  136. //-----------------------------------------------------
  137. // Topic
  138. //-----------------------------------------------------
  139.  
  140. function traiterTopic() {
  141. var lstTopic = document.getElementsByClassName("topic-messages");
  142. var trsTopic = lstTopic[0].children;
  143. for(var iTopic = 0; iTopic < trsTopic.length; ++iTopic) {
  144. traiterTrTopic(trsTopic[iTopic]);
  145. }
  146.  
  147. traiterNavBarTopic();
  148. }
  149.  
  150.  
  151. function traiterNavBarTopic() {
  152.  
  153. var relativePath = "";
  154. getPath().split("-").splice(2).forEach(function(split) {
  155. relativePath += split + "-";
  156. });
  157. relativePath = relativePath.slice(0, -1);
  158.  
  159. var buttons = addButtonToNavBar(["buttonBan"]);
  160. var buttonBan = buttons[0];
  161.  
  162. // Bouton des bans
  163. var isInBan = contentsString(bans, relativePath) != -1;
  164. if (isInBan) {
  165. buttonBan.innerHTML = "DEBAN";
  166. buttonBan.onclick = function() {
  167. deleteFromCache(bans, "bans");
  168. };
  169. } else {
  170. buttonBan.innerHTML = "BAN";
  171. buttonBan.onclick = function() {
  172. addInCache(bans, "bans");
  173. };
  174. }
  175.  
  176. }
  177.  
  178. function addInCache(cacheList, cacheName) {
  179. console.log("addInCache : " + cacheName);
  180. cacheList.push(getPath());
  181. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  182. ajouterBarFav();
  183. traiterNavBarTopic();
  184. }
  185.  
  186. function deleteFromCache(cacheList, cacheName) {
  187. console.log("deleteFromCache : " + cacheName);
  188.  
  189. var relativePath = "";
  190. getPath().split("-").splice(2).forEach(function(split) {
  191. relativePath += split + "-";
  192. });
  193. relativePath = relativePath.slice(0, -1);
  194.  
  195. var i = contentsString(cacheList, relativePath);
  196. if (i !== -1) {
  197. cacheList.splice(i, 1);
  198. localStorage.setItem(cacheName, JSON.stringify(cacheList));
  199. }
  200.  
  201. ajouterBarFav();
  202. traiterNavBarTopic();
  203. }
  204.  
  205. function traiterTrTopic(tr) {
  206.  
  207. var message = null;
  208. var rank = -1;
  209.  
  210. // Suppression des FDP
  211. banProfiles.forEach(function(connard) {
  212.  
  213. var id = getId();
  214. message = null;
  215. if (hasProfilLink(tr, connard.name)) {
  216. message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  217. }
  218. if (hasProfilAvatar(tr, connard.name)) {
  219. message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
  220. }
  221.  
  222. if (message !== null) {
  223. rank = connard.rank;
  224. return;
  225. }
  226. });
  227.  
  228. if (rank == 2) {
  229. tr.innerHTML = message;
  230. } else {
  231. addButtonHiddenTopicMessage(tr, rank == 1);
  232. }
  233.  
  234. }
  235.  
  236. function addButtonHiddenTopicMessage(tr, isHidden) {
  237.  
  238. var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
  239. var content = tr.getElementsByClassName("message-content")[0];
  240. var header = tr.getElementsByClassName("message-header")[0];
  241. var ulHeader = header.getElementsByClassName("message-actions")[0];
  242. var footer = tr.getElementsByClassName("message-footer")[0];
  243.  
  244. var idButton = getId();
  245.  
  246. content.isHidden = isHidden;
  247. var innerButton = content.isHidden ? "Afficher" : "Masquer";
  248. ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
  249.  
  250. var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
  251. var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
  252.  
  253. var button = document.getElementById(idButton);
  254.  
  255. button.style.backgroundColor = "Transparent";
  256. button.style.border = "none";
  257.  
  258. button.onclick = function() {
  259. content.isHidden = !content.isHidden;
  260. button.innerHTML = content.isHidden ? imageUp : imageDown;
  261. content.style.display = content.isHidden ? "none" : "";
  262. footer.style.display = content.isHidden ? "none" : "";
  263. aside.style.display = content.isHidden ? "none" : "";
  264. };
  265. content.isHidden = !content.isHidden;
  266. button.onclick.apply();
  267. }
  268.  
  269. //-----------------------------------------------------
  270. // Forum
  271. //-----------------------------------------------------
  272.  
  273.  
  274. function traiterForum() {
  275. var lst = document.getElementsByClassName("table table-striped topics");
  276. var trs = lst[0].children[1].children;
  277. for(var i = 0; i < trs.length; ++i) {
  278. traiterTrForum(trs[i]);
  279. }
  280. }
  281.  
  282. function traiterTrForum(tr) {
  283.  
  284. // Suppression des caracteres ching chong
  285. if (tr.innerText.match(/[\u3400-\u9FBF]/)) {
  286. console.log("Suppression des caracteres ching chong");
  287. tr.innerHTML = "";
  288. return;
  289. }
  290.  
  291. // Suppression des FDP
  292. banProfiles.forEach(function(connard) {
  293. if (hasProfilLink(tr, connard.name)) {
  294. console.log("Suppression du FDP : " + connard.name);
  295. tr.innerHTML = "";
  296. return;
  297. }
  298. });
  299.  
  300. bans.forEach(function(url) {
  301. if (hasUrl(tr, url)) {
  302. console.log("Suppression du sujet : " + url);
  303. tr.innerHTML = "";
  304. return;
  305. }
  306. });
  307.  
  308. // Surlignage
  309. favProfiles.forEach(function(surligne) {
  310. if (hasProfilLink(tr, surligne.name)) {
  311. console.log("Surlignage : " + surligne.name);
  312. tr.style.background = colorListProfil[surligne.color];
  313. return;
  314. }
  315. });
  316.  
  317. }
  318.  
  319. //-----------------------------------------------------
  320. // Profil
  321. //-----------------------------------------------------
  322.  
  323. function traiterProfil() {
  324. var elem = document.getElementsByClassName("profile-wrapper-right");
  325. currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
  326.  
  327. elem[0].innerHTML += "Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div>";
  328. elem[0].innerHTML += "Favoris couleur <select id=\"idFavColor\"></select>";
  329.  
  330. // favoris ----------------------------------------------------------
  331. var isFav = false;
  332. var color = 0;
  333. favProfiles.forEach(function(fav) {
  334. if (fav.name === currentProfile) {
  335. isFav = true;
  336. color = fav.color;
  337. return;
  338. }
  339. });
  340.  
  341. var colorList = [];
  342. for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
  343. colorList.push(iColor);
  344. }
  345.  
  346. createComboBox("idFavColor", colorList);
  347. var comboFavColor = document.getElementById("idFavColor");
  348.  
  349. for (var j = 0; j < comboFavColor.length; j++) {
  350. comboFavColor[j].innerHTML = "";
  351. comboFavColor[j].style.backgroundColor = colorListProfil[j];
  352. }
  353.  
  354. if (isFav) {
  355. comboFavColor.selectedIndex = parseInt(color);
  356. comboFavColor.style.backgroundColor = colorListProfil[color];
  357. }
  358. detailRankProfile(rank);
  359. comboFavColor.onchange = function(event) {
  360. favProfile(event.target.selectedOptions[0].value);
  361. };
  362.  
  363. // bans ----------------------------------------------------------
  364. var isBan = false;
  365. var rank = 0;
  366. banProfiles.forEach(function(connard) {
  367. if (connard.name === currentProfile) {
  368. isBan = true;
  369. rank = connard.rank;
  370. return;
  371. }
  372. });
  373.  
  374. createComboBox("idBanRank", ["non","0","1","2"]);
  375. var comboBanRank = document.getElementById("idBanRank");
  376. if (isBan) {
  377. comboBanRank.selectedIndex = parseInt(rank) + 1;
  378. }
  379. detailRankProfile(rank);
  380. comboBanRank.onchange = function(event) {
  381. banProfile(event.target.selectedOptions[0].value);
  382. };
  383.  
  384. }
  385.  
  386. function favProfile(color) {
  387. console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
  388.  
  389. var index = -1;
  390. for(var i = 0; i < favProfiles.length; ++i) {
  391. if (stringContents(favProfiles[i].name, currentProfile)) {
  392. index = i;
  393. break;
  394. }
  395. }
  396.  
  397. if (index !== -1) {
  398. favProfiles.splice(index, 1);
  399. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  400. }
  401.  
  402. if (color !== "0") {
  403. favProfiles.push({name:currentProfile, color:color});
  404. localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
  405. }
  406.  
  407. document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
  408. }
  409.  
  410. function banProfile(rank) {
  411. console.log("banProfile : " + currentProfile + ", rang : " + rank);
  412.  
  413. var index = -1;
  414. for(var i = 0; i < banProfiles.length; ++i) {
  415. if (stringContents(banProfiles[i].name, currentProfile)) {
  416. index = i;
  417. break;
  418. }
  419. }
  420.  
  421. if (index !== -1) {
  422. banProfiles.splice(index, 1);
  423. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  424. }
  425.  
  426. if (rank !== "non") {
  427. banProfiles.push({name:currentProfile, rank:rank});
  428. localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
  429. }
  430.  
  431. detailRankProfile(rank);
  432. }
  433.  
  434. function detailRankProfile(rank) {
  435. var innerHTML;
  436. if (rank === "0") {
  437. innerHTML = "Ses sujets sont supprimés.";
  438. } else if (rank === "1") {
  439. innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
  440. } else if (rank === "2") {
  441. innerHTML = "Ses sujets et messages sont supprimés.";
  442. } else {
  443. innerHTML = "Non banni.";
  444. }
  445.  
  446. document.getElementById("idBanRankDetail").innerHTML = innerHTML;
  447. }
  448.  
  449. //-----------------------------------------------------
  450. // Utils
  451. //-----------------------------------------------------
  452.  
  453. function createImageButton(idButton, buttonHtml) {
  454. var button = document.getElementById(idButton);
  455. button.innerHTML = buttonHtml;
  456. return button;
  457. }
  458.  
  459. function createComboBox(idParent, list) {
  460. var sel = document.getElementById(idParent);
  461. var optionoption = null;
  462.  
  463. for(i = 0; i < list.length; i++) {
  464.  
  465. optionoption = document.createElement('option');
  466. optionoption.value = list[i];
  467. optionoption.innerHTML = list[i];
  468. sel.appendChild(optionoption);
  469. }
  470. return sel;
  471. }
  472.  
  473. function httpGetAsync(theUrl, callback)
  474. {
  475. var xmlHttp = new XMLHttpRequest();
  476. xmlHttp.onreadystatechange = function() {
  477. if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  478. callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
  479. };
  480. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  481. xmlHttp.send(null);
  482. }
  483.  
  484. function contentsString(list, match) {
  485. for(var i = 0; i < list.length; ++i) {
  486. if (stringContents(list[i], match)) {
  487. return i;
  488. }
  489. }
  490. return -1;
  491. }
  492.  
  493. function getPath() {
  494. return url + window.location.pathname;
  495. }
  496.  
  497. function designTopButton(button) {
  498. button.style.color = "white";
  499. button.style.backgroundColor = "transparent";
  500. button.style.border = "none";
  501. }
  502.  
  503. function hasProfilLink(elem, name) {
  504. return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
  505. }
  506.  
  507. function hasProfilAvatar(elem, name) {
  508. return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
  509. }
  510.  
  511. function hasUrl(elem, url) {
  512. return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
  513. }
  514.  
  515. function stringContents(string, match) {
  516. return string.indexOf(match) !== -1;
  517. }
  518.  
  519. function addButtonToNavBar(names) {
  520.  
  521. var buttons = [];
  522.  
  523. if (document.getElementById(names[0]) === null) {
  524. var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
  525. var innerHTML = "";
  526. names.forEach(function(name) {
  527. innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
  528. });
  529. navbar[0].innerHTML += innerHTML;
  530. names.forEach(function(name) {
  531. designTopButton(document.getElementById(name));
  532. });
  533. }
  534.  
  535. names.forEach(function(name) {
  536. buttons.push(document.getElementById(name));
  537. });
  538.  
  539. return buttons;
  540. }
  541.  
  542. function getId() {
  543. return "id" + id++;
  544. }
  545.  
  546. //-----------------------------------------------------
  547. // Patch
  548. //-----------------------------------------------------
  549. //
  550. // 2.0.2 : Pastebin => Etape 3
  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