Advertisement
Guest User

Untitled

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