Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name AveNoel
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://avenoel.org/*
- // @grant none
- // ==/UserScript==
- //Profils
- var favProfiles;
- var banProfiles;
- var currentProfile;
- var colorListProfil = [
- "White",
- "LightBlue",
- "LightCoral",
- "LightCyan",
- "LightGoldenRodYellow",
- "LightGrey",
- "LightGreen",
- "LightPink",
- "LightSalmon",
- "LightSeaGreen",
- "LightSkyBlue",
- "LightSlateGrey",
- "LightSteelBlue"
- ];
- //Topic
- var bans;
- // Global
- var id = 0;
- const space = " ";
- const url = "https://avenoel.org";
- const imgQuote = "<img src=\"/images/topic/quote.png\" alt=\"Icône citation\">";
- const imgEdit = "<img src=\"/images/topic/edit.png\" alt=\"Icône éditer\" title=\"Éditer le message\">";
- const imgDelete = "<img src=\"/images/topic/delete.png\" alt=\"Icône suppression\">";
- (function() {
- 'use strict';
- //debugger;
- //localStorage.removeItem("favs");
- //localStorage.removeItem("bans");
- //localStorage.removeItem("favProfiles");
- //localStorage.removeItem("banProfiles");
- initCache();
- var path = window.location.pathname;
- if (path.startsWith('/profil')) {
- traiterProfil();
- } else {
- ajouterBarFav();
- if (path.startsWith('/forum')) {
- traiterForum();
- } else if (path.startsWith('/topic')) {
- traiterTopic();
- } else {
- console.log('Cas ' + path + " non traité.");
- }
- }
- })();
- function initCache() {
- bans = localStorage.bans === undefined ? [] : JSON.parse(localStorage.bans);
- favProfiles = localStorage.favProfiles === undefined ? [] : JSON.parse(localStorage.favProfiles);
- banProfiles = localStorage.banProfiles === undefined ? [] : JSON.parse(localStorage.banProfiles);
- }
- function ajouterBarFav() {
- var idCourrier = getId();
- var idFavoris = getId();
- var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
- var innerHTML =
- "<section>"+
- " <div id=\""+idCourrier+"\"><div>"+
- " <div id=\""+idFavoris+"\">Favoris</div>"+
- "</section>";
- barFav[0].children[1].innerHTML = innerHTML;
- httpGetAsync("https://avenoel.org/favoris", function (html) {
- var list = html.getElementsByTagName("tBody")[0].children;
- var buttonBar = document.getElementById(idFavoris);
- var innerHTML = "";
- //debugger;
- for(var i = 0; i < list.length; i++) {
- var fav = list[i];
- fav.children[1].children[0].href = fav.children[0].children[0].getAttribute("href");
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[0]);
- innerHTML += "<li>" + fav.innerHTML + "</li>";
- }
- buttonBar.innerHTML += innerHTML;
- });
- httpGetAsync("https://avenoel.org/messagerie", function (html) {
- var mails = html.getElementsByClassName("active");
- if (mails.length > 2) {
- var innerHTMLCourrier = "<div>Courriers";
- for(var i = 1; i < mails.length -1; ++i) {
- innerHTMLCourrier += "<li>";
- innerHTMLCourrier += mails[i].getElementsByClassName("author")[0].innerHTML + " : ";
- innerHTMLCourrier += mails[i].getElementsByClassName("title")[0].innerHTML;
- innerHTMLCourrier += "</li>";
- }
- innerHTMLCourrier += "</div>";
- document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
- }
- });
- }
- //-----------------------------------------------------
- // Topic
- //-----------------------------------------------------
- function traiterTopic() {
- var lstTopic = document.getElementsByClassName("topic-messages");
- var trsTopic = lstTopic[0].children;
- for(var iTopic = 0; iTopic < trsTopic.length; ++iTopic) {
- traiterTrTopic(trsTopic[iTopic]);
- }
- traiterNavBarTopic();
- }
- function traiterNavBarTopic() {
- var relativePath = "";
- getPath().split("-").splice(2).forEach(function(split) {
- relativePath += split + "-";
- });
- relativePath = relativePath.slice(0, -1);
- var buttons = addButtonToNavBar(["buttonBan"]);
- var buttonBan = buttons[0];
- // Bouton des bans
- var isInBan = contentsString(bans, relativePath) != -1;
- if (isInBan) {
- buttonBan.innerHTML = "DEBAN";
- buttonBan.onclick = function() {
- deleteFromCache(bans, "bans");
- };
- } else {
- buttonBan.innerHTML = "BAN";
- buttonBan.onclick = function() {
- addInCache(bans, "bans");
- };
- }
- }
- function addInCache(cacheList, cacheName) {
- console.log("addInCache : " + cacheName);
- cacheList.push(getPath());
- localStorage.setItem(cacheName, JSON.stringify(cacheList));
- ajouterBarFav();
- traiterNavBarTopic();
- }
- function deleteFromCache(cacheList, cacheName) {
- console.log("deleteFromCache : " + cacheName);
- var relativePath = "";
- getPath().split("-").splice(2).forEach(function(split) {
- relativePath += split + "-";
- });
- relativePath = relativePath.slice(0, -1);
- var i = contentsString(cacheList, relativePath);
- if (i !== -1) {
- cacheList.splice(i, 1);
- localStorage.setItem(cacheName, JSON.stringify(cacheList));
- }
- ajouterBarFav();
- traiterNavBarTopic();
- }
- function traiterTrTopic(tr) {
- var message = null;
- var rank = -1;
- // Suppression des FDP
- banProfiles.forEach(function(connard) {
- var id = getId();
- message = null;
- if (hasProfilLink(tr, connard.name)) {
- message = "<div id=\"" + id + "\"><span>Réponse sur" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
- }
- if (hasProfilAvatar(tr, connard.name)) {
- message = "<div id=\"" + id + "\"><span>Message de" + space + "</span><a href=\"https://avenoel.org/profil/" + connard.name + "\">" + connard.name + "</a></div>";
- }
- if (message !== null) {
- rank = connard.rank;
- return;
- }
- });
- if (rank == 2) {
- tr.innerHTML = message;
- } else {
- addButtonHiddenTopicMessage(tr, rank == 1);
- }
- }
- function addButtonHiddenTopicMessage(tr, isHidden) {
- var aside = tr.getElementsByClassName("message-aside hidden-xs")[0];
- var content = tr.getElementsByClassName("message-content")[0];
- var header = tr.getElementsByClassName("message-header")[0];
- var footer = tr.getElementsByClassName("message-footer")[0];
- var idButton = getId();
- var idHeaderHidden = getId();
- header.innerHTML += "<div id=\"" + idHeaderHidden + "\">Message masqué.</div>";
- var headerHidden = document.getElementById(idHeaderHidden);
- headerHidden.isHidden = !isHidden;
- headerHidden.style.display = headerHidden.isHidden ? "none" : "";
- content.isHidden = isHidden;
- content.style.display = content.isHidden ? "none" : "";
- var innerButton = content.isHidden ? "Afficher" : "Masquer";
- aside.innerHTML += "<button id=\"" + idButton + "\" >" + innerButton + "</button>";
- var button = document.getElementById(idButton);
- button.onclick = function() {
- content.isHidden = !content.isHidden;
- button.innerHTML = content.isHidden ? "Afficher" : "Masquer";
- content.style.display = content.isHidden ? "none" : "";
- footer.style.display = content.isHidden ? "none" : "";
- headerHidden.isHidden = !headerHidden.isHidden;
- headerHidden.style.display = headerHidden.isHidden ? "none" : "";
- };
- }
- //-----------------------------------------------------
- // Forum
- //-----------------------------------------------------
- function traiterForum() {
- var lst = document.getElementsByClassName("table table-striped topics");
- var trs = lst[0].children[1].children;
- for(var i = 0; i < trs.length; ++i) {
- traiterTrForum(trs[i]);
- }
- }
- function traiterTrForum(tr) {
- // Suppression des caracteres ching chong
- if (tr.innerText.match(/[\u3400-\u9FBF]/)) {
- console.log("Suppression des caracteres ching chong");
- tr.innerHTML = "";
- return;
- }
- // Suppression des FDP
- banProfiles.forEach(function(connard) {
- if (hasProfilLink(tr, connard.name)) {
- console.log("Suppression du FDP : " + connard.name);
- tr.innerHTML = "";
- return;
- }
- });
- bans.forEach(function(url) {
- if (hasUrl(tr, url)) {
- console.log("Suppression du sujet : " + url);
- tr.innerHTML = "";
- return;
- }
- });
- // Surlignage
- favProfiles.forEach(function(surligne) {
- if (hasProfilLink(tr, surligne.name)) {
- console.log("Surlignage : " + surligne.name);
- tr.style.background = colorListProfil[surligne.color];
- return;
- }
- });
- }
- //-----------------------------------------------------
- // Profil
- //-----------------------------------------------------
- function traiterProfil() {
- var elem = document.getElementsByClassName("profile-wrapper-right");
- currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
- elem[0].innerHTML += "Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div>";
- elem[0].innerHTML += "Favoris couleur <select id=\"idFavColor\"></select>";
- // favoris ----------------------------------------------------------
- var isFav = false;
- var color = 0;
- favProfiles.forEach(function(fav) {
- if (fav.name === currentProfile) {
- isFav = true;
- color = fav.color;
- return;
- }
- });
- var colorList = [];
- for (var iColor = 0; iColor < colorListProfil.length; iColor++) {
- colorList.push(iColor);
- }
- createComboBox("idFavColor", colorList);
- var comboFavColor = document.getElementById("idFavColor");
- for (var j = 0; j < comboFavColor.length; j++) {
- comboFavColor[j].innerHTML = "";
- comboFavColor[j].style.backgroundColor = colorListProfil[j];
- }
- if (isFav) {
- comboFavColor.selectedIndex = parseInt(color);
- comboFavColor.style.backgroundColor = colorListProfil[color];
- }
- detailRankProfile(rank);
- comboFavColor.onchange = function(event) {
- favProfile(event.target.selectedOptions[0].value);
- };
- // bans ----------------------------------------------------------
- var isBan = false;
- var rank = 0;
- banProfiles.forEach(function(connard) {
- if (connard.name === currentProfile) {
- isBan = true;
- rank = connard.rank;
- return;
- }
- });
- createComboBox("idBanRank", ["non","0","1","2"]);
- var comboBanRank = document.getElementById("idBanRank");
- if (isBan) {
- comboBanRank.selectedIndex = parseInt(rank) + 1;
- }
- detailRankProfile(rank);
- comboBanRank.onchange = function(event) {
- banProfile(event.target.selectedOptions[0].value);
- };
- }
- function favProfile(color) {
- console.log("favProfile : " + currentProfile + ", color : " + colorListProfil[color]);
- var index = -1;
- for(var i = 0; i < favProfiles.length; ++i) {
- if (stringContents(favProfiles[i].name, currentProfile)) {
- index = i;
- break;
- }
- }
- if (index !== -1) {
- favProfiles.splice(index, 1);
- localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
- }
- if (color !== "0") {
- favProfiles.push({name:currentProfile, color:color});
- localStorage.setItem("favProfiles", JSON.stringify(favProfiles));
- }
- document.getElementById("idFavColor").style.backgroundColor = colorListProfil[color];
- }
- function banProfile(rank) {
- console.log("banProfile : " + currentProfile + ", rang : " + rank);
- var index = -1;
- for(var i = 0; i < banProfiles.length; ++i) {
- if (stringContents(banProfiles[i].name, currentProfile)) {
- index = i;
- break;
- }
- }
- if (index !== -1) {
- banProfiles.splice(index, 1);
- localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
- }
- if (rank !== "non") {
- banProfiles.push({name:currentProfile, rank:rank});
- localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
- }
- detailRankProfile(rank);
- }
- function detailRankProfile(rank) {
- var innerHTML;
- if (rank === "0") {
- innerHTML = "Ses sujets sont supprimés.";
- } else if (rank === "1") {
- innerHTML = "Ses sujets sont supprimés et ses messages sont masqués.";
- } else if (rank === "2") {
- innerHTML = "Ses sujets et messages sont supprimés.";
- } else {
- innerHTML = "Non banni.";
- }
- document.getElementById("idBanRankDetail").innerHTML = innerHTML;
- }
- //-----------------------------------------------------
- // Utils
- //-----------------------------------------------------
- function createImageButton(idButton, buttonHtml) {
- var button = document.getElementById(idButton);
- button.innerHTML = buttonHtml;
- return button;
- }
- function createComboBox(idParent, list) {
- var sel = document.getElementById(idParent);
- var optionoption = null;
- for(i = 0; i < list.length; i++) {
- optionoption = document.createElement('option');
- optionoption.value = list[i];
- optionoption.innerHTML = list[i];
- sel.appendChild(optionoption);
- }
- return sel;
- }
- function httpGetAsync(theUrl, callback)
- {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
- callback(new DOMParser().parseFromString(xmlHttp.responseText, "text/html"));
- };
- xmlHttp.open("GET", theUrl, true); // true for asynchronous
- xmlHttp.send(null);
- }
- function contentsString(list, match) {
- for(var i = 0; i < list.length; ++i) {
- if (stringContents(list[i], match)) {
- return i;
- }
- }
- return -1;
- }
- function getPath() {
- return url + window.location.pathname;
- }
- function designTopButton(button) {
- button.style.color = "white";
- button.style.backgroundColor = "transparent";
- button.style.border = "none";
- }
- function hasProfilLink(elem, name) {
- return stringContents(elem.innerHTML, "https://avenoel.org/profil/" + name + "\"");
- }
- function hasProfilAvatar(elem, name) {
- return stringContents(elem.innerHTML, "alt=\"Avatar de "+ name + "\"");
- }
- function hasUrl(elem, url) {
- return stringContents(elem.innerHTML, "<a href=\"" + url + "\">");
- }
- function stringContents(string, match) {
- return string.indexOf(match) !== -1;
- }
- function addButtonToNavBar(names) {
- var buttons = [];
- if (document.getElementById(names[0]) === null) {
- var navbar = document.getElementsByClassName("nav navbar-nav navbar-links");
- var innerHTML = "";
- names.forEach(function(name) {
- innerHTML += "<li class=\"\"><a><button id=\"" + name + "\" ></button></a></li>";
- });
- navbar[0].innerHTML += innerHTML;
- names.forEach(function(name) {
- designTopButton(document.getElementById(name));
- });
- }
- names.forEach(function(name) {
- buttons.push(document.getElementById(name));
- });
- return buttons;
- }
- function getId() {
- return "id" + id++;
- }
- //-----------------------------------------------------
- // TODO list
- //-----------------------------------------------------
- //Passer les commentaires avec les fleches du clavier
- //Ouvirir et fermer un commentaire
- //acces au profil des personnes bannis en cliquant sur le nom
- //-----------------------------------------------------
- // Patch
- //-----------------------------------------------------
- //
- // 2.0.1 : Pastebin => Etape 3
- // + Le clique sur le favoris emmene à la dernière page
- // 2.0.0 : Pastebin => https://pastebin.com/eHCt5h8E
- // + Prise en compte de la liste de favoris (affichage reste à droite)
- // L'icone du fichier n'est pas encore mise
- // + Changement du bouton afficher/masquer un commentaire.
- // 1.1.0 : Pastebin => https://pastebin.com/85F6ydsC
- // + gestion de la lovelist sur les profils
- // + plus besoin d'aller dans le code pour gérer ses listes
- // 1.0.3 : Pastebin => https://pastebin.com/RNWPdyyF
- // + suppression de 'Courriers' quand la liste est vide
- // + gestion de la banlist sur les profils
- // 1.0.2 : https://pastebin.com/TJzUnw69
- // + ajout de la liste des messages non lus au niveau de la barre des favs
- // 1.0.1 : https://pastebin.com/mFv7z7wb
- // + correction du bug des bans de topics
- // + detection du favoris/ban à chaque page du topic
- // 1.0.0 : https://pastebin.com/bjVmYYgM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement