Advertisement
Guest User

Untitled

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