Advertisement
Guest User

Untitled

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