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==
- //-----------------------------------------------------
- // TODO list
- //-----------------------------------------------------
- //Et si tu pouvais add une messagerie facebook like avec les mp qui s'affiche en bas, ça serait pas mal.
- //Et un je sais pas si c'est possible, mais recevoir une notif quand on nous cite serait parfait, des fois on rate des échanges intéressant juste parce qu'on oublie de check tout les mp
- //-----------------------------------------------------
- //Profils
- var regexList;
- var bansRegex;
- var favProfiles;
- var banProfiles;
- var currentProfile;
- var colorListProfil = [
- "White",
- "LightBlue",
- "LightCoral",
- "LightCyan",
- "LightGoldenRodYellow",
- "LightGrey",
- "LightGreen",
- "LightPink",
- "LightSalmon",
- "LightSeaGreen",
- "LightSkyBlue",
- "LightSlateGrey",
- "LightSteelBlue"
- ];
- //Topic
- var favs;
- var bans;
- // Global
- var id = 0;
- var profil = {name:"rien"};
- const space = " ";
- const url = "https://avenoel.org";
- const imgQuote = "<img src=\"/images/topic/quote.png\" alt=\"Icône citation\" width=\"20\">";
- const imgEdit = "<img src=\"/images/topic/edit.png\" alt=\"Icône éditer\" title=\"Éditer le message\" width=\"20\">";
- const imgDelete = "<img src=\"/images/topic/delete.png\" alt=\"Icône suppression\" width=\"20\">";
- (function() {
- 'use strict';
- var t0 = performance.now();
- //debugger;
- //localStorage.removeItem("favs");
- //localStorage.removeItem("bans");
- //localStorage.removeItem("favProfiles");
- //localStorage.removeItem("banProfiles");
- initProfil();
- initFunctions();
- setInterval(initCache, 1500);
- 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 if (path.startsWith('/messagerie')) {
- traiterMessagerie();
- } else {
- console.log('Cas ' + path + " non traité.");
- }
- }
- enhanceTextArea();
- controlVersion();
- var t1 = performance.now();
- console.log("Call to AveNoel took " + (t1 - t0) + " milliseconds.");
- })();
- function initProfil() {
- var split = document.getElementsByClassName('navbar-user-avatar')[0].parentElement.href.split("/");
- profil.name = split[split.length-1];
- }
- function initFunctions() {
- if (!String.prototype.splice) {
- /**
- * {JSDoc}
- *
- * The splice() method changes the content of a string by removing a range of
- * characters and/or adding new characters.
- *
- * @this {String}
- * @param {number} start Index at which to start changing the string.
- * @param {number} delCount An integer indicating the number of old chars to remove.
- * @param {string} newSubStr The String that is spliced in.
- * @return {string} A new string with the spliced substring.
- */
- String.prototype.splice = function(start, delCount, newSubStr) {
- return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
- };
- }
- }
- function initCache() {
- regexList = localStorage.regexList === undefined ? [] : JSON.parse(localStorage.regexList);
- bansRegex = localStorage.bansRegex === undefined ? [] : JSON.parse(localStorage.bansRegex);
- favs = localStorage.favs === undefined ? {} : JSON.parse(localStorage.favs);
- 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 controlVersion() {
- httpGetApiAsync("messages/1611709", function(res) {
- var match = res.content.match(/[0-9]+\.[0-9]+\.[0-9]+/g);
- if (match && version !== match[0]) {
- var patchNotes = res.content.split(match)[1].match(/[^\r\n]+/g);
- var div = document.getElementById('alertversion');
- var innerHTML =
- "La version " + match[0] + " est disponible => " +
- "<a href=\"https://avenoel.org/topic/101099-1-aide-voici-un-script-pour-vous-faciliter-la-vie-sur-avn\">ici</a>.";
- for(var i = 1; i < patchNotes.length -1; ++i) {
- innerHTML += "<li>" + patchNotes[i] + "</li>";
- }
- innerHTML +=
- "<br>N'oubliez pas de laisser un commentaire." +
- "<br><img class=\"board-noelshack\" src=\"https://image.noelshack.com/fichiers/2017/02/1484089609-coeur.png\">";
- div.innerHTML = innerHTML;
- div.style.color = "red";
- }
- });
- }
- //-----------------------------------------------------
- // Editeur de texte
- //-----------------------------------------------------
- function enhanceTextArea() {
- var textArea = document.getElementsByTagName("textarea")[document.getElementsByTagName("textarea").length - 1];
- if (!textArea) {
- return;
- }
- if (textArea.value.length > 0) {
- textArea.selectionStart = textArea.value.length;
- textArea.focus();
- }
- var edit = function(tagIn, tagOut) {
- var start = textArea.selectionStart;
- var end = textArea.selectionEnd;
- textArea.value = textArea.value.splice(textArea.selectionEnd, 0, tagOut).splice(textArea.selectionStart, 0, tagIn);
- textArea.selectionStart = start + tagIn.length;
- textArea.selectionEnd = end + tagIn.length;
- textArea.focus();
- };
- var textAreaButtons = document.getElementsByClassName("form-group bbcodes")[document.getElementsByClassName("form-group bbcodes").length - 1];
- var list = [
- {name:"R", tagIn:"<color=red>", tagOut:"</color>", color:"red"},
- {name:"G", tagIn:"<color=green>", tagOut:"</color>", color:"green"},
- {name:"B", tagIn:"<color=blue>", tagOut:"</color>", color:"blue"}
- ];
- var div = document.createElement('div');
- list.forEach(function(each) {
- div.innerHTML = "<button type=\"button\" class=\"btn\" tabindex=\"-1\" data-type=\"tag\"><span>" + each.name + "</span></button>";
- var btn = div.firstChild;
- textAreaButtons.appendChild(btn);
- btn.style.color = each.color;
- btn.onclick = function() {edit(each.tagIn, each.tagOut);};
- });
- div.remove();
- textArea.onfocusout = function () {
- var value = textArea.value;
- regexList.forEach(function(each) {
- value = value.replace(new RegExp(each.reg, "gm"), each.res);
- });
- // Mort aux cucks
- textArea.value = value
- .replace(new RegExp("cuck", "gm"), "candaule")
- .replace(new RegExp("Cuck", "gm"), "Candaule")
- .replace(new RegExp("CUCK", "gm"), "CANDAULE");
- };
- }
- //-----------------------------------------------------
- // Fav/Courriers
- //-----------------------------------------------------
- function ajouterBarFav() {
- var barFav = document.getElementsByClassName("col-md-3 col-sm-12 col-xs-12 pull-right hidden-sm hidden-xs");
- if (barFav.length === 0) {
- return;
- }
- var idCourrier = getId();
- var idFavoris = getId();
- barFav[0].replaceChild(barFav[0].children[0].cloneNode(true), barFav[0].children[0]);
- var listDiv = barFav[0].children[1];
- listDiv.classList = [];
- listDiv.innerHTML =
- "<section>"+
- " <div id=\"alertversion\"></div>"+
- " <div id=\""+idCourrier+"\"></div>"+
- " <div id=\""+idFavoris+"\"></div>"+
- "</section>";
- var rect = listDiv.getBoundingClientRect(),
- scrollTop = window.pageYOffset || document.documentElement.scrollTop;
- var top = rect.top + scrollTop;
- var event = function(e) {
- if (window.scrollY > top) {
- listDiv.style.position = "absolute";
- listDiv.style.top = window.scrollY + 'px';
- } else {
- listDiv.style.position = null;
- listDiv.style.top = top + 'px';
- }
- };
- window.addEventListener('scroll', event);
- event.apply();
- var documentTitle = document.title;
- var setMails = function(){
- httpGetAsync("https://avenoel.org/messagerie", function (html) {
- var mails = html.getElementsByClassName("active");
- if (mails.length > 2) {
- document.title = "(" + (mails.length-2) + ") " + documentTitle;
- var innerHTMLCourrier = "Courrier" + ((mails.length-2) > 1 ? "s" : "") + " (" + (mails.length-2) + ")";
- 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>";
- }
- document.getElementById(idCourrier).innerHTML = innerHTMLCourrier;
- } else {
- document.title = documentTitle;
- document.getElementById(idCourrier).innerHTML = "";
- }
- });
- };
- setInterval(setMails, 30000);
- setMails.apply();
- var setFavs = function(){
- httpGetAsync("https://avenoel.org/favoris", function (html) {
- var list = html.getElementsByTagName("tBody")[0].children;
- var buttonBar = document.getElementById(idFavoris);
- var innerHTMLFav = "Favoris";
- for(var i = 0; i < list.length; i++) {
- var fav = list[i];
- var nbDiff = "";
- var href = fav.children[1].children[0].href;
- var nb = fav.children[3].innerHTML.trim();
- if (fav.children[0].children[0].href === window.location.href) {
- favs[href] = nb;
- localStorage.setItem("favs", JSON.stringify(favs));
- }
- if (favs[href]) {
- if( favs[href] !== nb) {
- nbDiff = "(" + (nb - favs[href]) + ") ";
- }
- } else {
- favs[href] = nb;
- localStorage.setItem("favs", JSON.stringify(favs));
- }
- fav.children[1].children[0].href = fav.children[0].children[0].href;
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[2]);
- fav.removeChild(fav.children[0]);
- innerHTMLFav += "<li>" + nbDiff + fav.innerHTML + "</li>";
- }
- document.getElementById(idFavoris).innerHTML = innerHTMLFav;
- });
- };
- setInterval(setFavs, 30000);
- setFavs.apply();
- }
- //-----------------------------------------------------
- // Topic
- //-----------------------------------------------------
- function traiterTopic() {
- overloadButtonDeleteTopic();
- var lstTopic = document.getElementsByClassName("topic-messages");
- var trsTopic = lstTopic[0].children;
- var listTop = [];
- document.onkeydown = function(event) {
- if (true) {
- return;
- }
- var newTop;
- if (event.key === "ArrowUp") {
- newTop = findNewTop(true, listTop);
- }
- if (event.key === "ArrowDown") {
- newTop = findNewTop(false, listTop);
- }
- if (Number.isInteger(newTop)) {
- window.scrollTo(0, newTop);
- }
- };
- listTop.push(0);
- for(var iTopic = 0; iTopic < trsTopic.length; ++iTopic) {
- listTop.push(traiterTrTopic(trsTopic[iTopic]));
- collapseQuote(trsTopic[iTopic]);
- overloadButtons(trsTopic[iTopic]);
- }
- traiterNavBarTopic();
- }
- function findNewTop(isUp, listTop) {
- for(var i = 0; i < listTop.length - 1; ++i) {
- if (listTop[i] <= window.scrollY && window.scrollY <= listTop[i + 1]) {
- return isUp ? listTop[i] : listTop[i + 1];
- }
- }
- }
- 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.some(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 true;
- }
- return false;
- });
- if (rank == 2) {
- tr.innerHTML = message;
- tr.focus();
- } else {
- addButtonHiddenTopicMessage(tr, rank == 1);
- }
- return tr.offsetTop;//getBoundingClientRect().top + window.pageYOffset;
- }
- function collapseQuote(tr) {
- var content = tr.getElementsByClassName("message-content")[0];
- if (!content) {
- return;
- }
- var lines = content.innerHTML.match(/[^\r\n]+/g);
- var ids = [];
- var currentLine;
- var lastRank = -1;
- var currentRank = -1;
- for(var i = lines.length - 1; i > -1; --i) {
- currentRank = calculRank(lines[i]);
- if (lastRank > 0 && currentRank > lastRank) {
- lines.splice(i + 1, 0, "</div>");
- } else if (currentRank > 0 && currentRank < lastRank) {
- var idButton = getId();
- var idDiv = getId();
- var beforeButton = "";
- for(var iGt = 0; iGt < currentRank; ++iGt) {
- beforeButton += "> ";
- }
- var buttonAll = "";
- if (currentRank === 1) {
- var idButtonAll = "buttonAll" + getId();
- buttonAll = "<button id=\"" + idButtonAll + "\" ></button>";
- ids.push({idButton:idButtonAll, idDiv:idDiv});
- }
- var maskInnerHTML = "<span class=\"message-content-quote\">" + beforeButton + "<i><button id=\"" + idButton + "\" ></button>" + buttonAll + "</i></span><div id=\"" + idDiv + "\" >";
- ids.push({idButton:idButton, idDiv:idDiv});
- lines.splice(i + 1, 0, maskInnerHTML);
- }
- lastRank = currentRank;
- }
- content.innerHTML = lines.join('');
- addCollapseEvent(tr, ids);
- }
- function addCollapseEvent(tr, ids) {
- ids.forEach(function(id) {
- var button = document.getElementById(id.idButton);
- button.style.border = "none";
- button.innerHTML = ">";
- button.style.textAlign = "center";
- var div = document.getElementById(id.idDiv);
- div.style.display = "none";
- if (id.idButton.startsWith("buttonAll")) {
- button.innerHTML = "=>";
- button.onclick = function() {
- button.innerHTML = button.innerHTML === "<=" ? "=>" : "<=";
- var innerHTML = button.innerHTML === "<=" ? "<" : ">";
- var buttonList = div.getElementsByTagName("button");
- for (var i = 0; i < buttonList.length; i++) {
- buttonList[i].innerHTML = innerHTML;
- }
- var divList = div.getElementsByTagName("div");
- var display = button.innerHTML === "<=" ? "" : "none";
- div.style.display = display;
- for (var j = 0; j < divList.length; j++) {
- divList[j].style.display = display;
- }
- button.previousSibling.innerHTML = button.innerHTML === "<=" ? "<" : ">";
- };
- } else {
- button.onclick = function() {
- button.innerHTML = button.innerHTML === "<" ? ">" : "<";
- div.style.display = div.style.display === "none" ? "" : "none";
- if (button.nextSibling !== null) {
- button.nextSibling.innerHTML = button.innerHTML === "<" ? "<=" : "=>";
- }
- };
- }
- });
- }
- function calculRank(line) {
- var rank = -1;
- var index;
- var matcher = "quote\">> ";
- while (index != -1) {
- rank++;
- index = line.indexOf(matcher);
- matcher += "> ";
- }
- return rank;
- }
- 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 ulHeader = header.getElementsByClassName("message-actions")[0];
- var footer = tr.getElementsByClassName("message-footer")[0];
- var idButton = getId();
- content.isHidden = isHidden;
- var innerButton = content.isHidden ? "Afficher" : "Masquer";
- ulHeader.innerHTML = "<button id=\"" + idButton + "\" >" + innerButton + "</button>" + ulHeader.innerHTML;
- var imageUp = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53604.svg\"></li>";
- var imageDown = "<li><img src=\"https://img-fi-n2.akamaized.net/icons/svg/53/53598.svg\" alt=\"Icône citation\"></li>";
- var button = document.getElementById(idButton);
- button.style.backgroundColor = "Transparent";
- button.style.border = "none";
- button.onclick = function() {
- content.isHidden = !content.isHidden;
- button.innerHTML = content.isHidden ? imageUp : imageDown;
- content.style.display = content.isHidden ? "none" : "";
- footer.style.display = content.isHidden ? "none" : "";
- aside.style.display = content.isHidden ? "none" : "";
- };
- content.isHidden = !content.isHidden;
- button.onclick.apply();
- }
- function overloadButtons(tr) {
- var header = tr.getElementsByClassName("message-header")[0];
- if (!header) {
- return;
- }
- var imgs = header.getElementsByTagName("img");
- var img;
- for(var i = 0; i < imgs.length; ++i) {
- if (imgs[i].src === "https://avenoel.org/images/topic/delete.png") {
- img = imgs[i];
- }
- }
- if (!img) {
- return;
- }
- var button = img.parentElement;
- var href = button.href;
- button.href = "#";
- button.onclick = function() {
- if (window.confirm("Voulez vous supprimer le message ?")) {
- window.location.href = href;
- }
- };
- }
- function overloadButtonDeleteTopic() {
- var buttons = document.getElementsByClassName("btn btn-danger");
- if (!buttons) {
- return;
- }
- for(var i = 0; i < buttons.length; ++i) {
- var button = buttons[i];
- var href = button.href;
- button.href = "#";
- button.onclick = function() {
- if (window.confirm("Voulez vous " + this.innerHTML.toLowerCase() + " le topic ?")) {
- window.location.href = href;
- }
- };
- }
- }
- //-----------------------------------------------------
- // 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
- if (banProfiles.some(function(connard) {
- if (hasProfilLink(tr, connard.name)) {
- console.log("Suppression du FDP : " + connard.name);
- tr.innerHTML = "";
- return true;
- }
- return false;
- })) {
- return;
- }
- if (bans.some(function(url) {
- if (hasUrl(tr, url)) {
- console.log("Suppression du sujet : " + url);
- tr.innerHTML = "";
- return true;
- }
- return false;
- })) {
- return;
- }
- if (bansRegex.some(function(regex) {
- if (tr.innerHTML.match(new RegExp(regex, "gm"))) {
- console.log("Suppression du sujet regex : " + regex);
- tr.innerHTML = "";
- return true;
- }
- return false;
- })) {
- return;
- }
- // Surlignage
- if (favProfiles.some(function(surligne) {
- if (hasProfilLink(tr, surligne.name)) {
- console.log("Surlignage : " + surligne.name);
- tr.style.background = colorListProfil[surligne.color];
- return true;
- }
- return false;
- })) {
- return;
- }
- }
- //-----------------------------------------------------
- // Profil
- //-----------------------------------------------------
- function traiterProfil() {
- var isMine = profil.name === document.getElementsByTagName("h2")[0].innerHTML;
- var elem = document.getElementsByClassName("profile-wrapper-right");
- currentProfile = window.location.href.substring("https://avenoel.org/profil/".length);
- elem[0].innerHTML += "<div " + (isMine ? "hidden" : "") + ">Banni de rang <select id=\"idBanRank\"></select><div id=\"idBanRankDetail\"></div></div>";
- elem[0].innerHTML += "Favoris couleur <select id=\"idFavColor\"></select>";
- // favoris ----------------------------------------------------------
- var isFav = false;
- var color = 0;
- favProfiles.some(function(fav) {
- if (fav.name === currentProfile) {
- isFav = true;
- color = fav.color;
- return true;
- }
- return false;
- });
- 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];
- }
- comboFavColor.onchange = function(event) {
- favProfile(event.target.selectedOptions[0].value);
- };
- // bans ----------------------------------------------------------
- detailRankProfile();
- 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);
- };
- if (isMine) {
- afficherConfig();
- }
- }
- function afficherConfig() {
- var container = document.getElementsByClassName("col-md-7 col-centered profile")[0];
- var editorContainer = container.appendChild(container.children[0].cloneNode(true));
- editorContainer.style.textAlign = "left";
- editorContainer.style.marginTop = "15px";
- editorContainer.innerHTML = "";
- var config = container.appendChild(container.children[0].cloneNode(true));
- config.style.textAlign = "left";
- config.style.marginTop = "15px";
- var idEditor = getId();
- var idTopic = getId();
- var idBannis = getId();
- config.innerHTML =
- "<div>Liste mots clés de l'éditeur de texte :</div>"+
- "<div id=\"" + idEditor + "\"></div>"+
- "<br>"+
- "<div>Liste mots clés du masques des sujets :</div>"+
- "<div id=\"" + idTopic + "\"></div>"+
- "<br>"+
- "<div>Liste des bannis :</div>"+
- "<div id=\"" + idBannis + "\"></div>";
- addEditorToProfil(editorContainer);
- createConfigEditor(document.getElementById(idEditor));
- createConfigTopic(document.getElementById(idTopic));
- createConfigBannis(document.getElementById(idBannis));
- }
- function addEditorToProfil(container) {
- if (true) {
- container.style.display = "none";
- }
- httpGetAsync("https://avenoel.org/forum", function (html) {
- var form = html.getElementsByTagName("form")[1];
- //var risi = html.getElementsByClassName("btn risi-wlogo")[0];
- // risi.formAction = "https://avenoel.org/forum/#risibank";
- // console.log(risi.formAction);
- container.appendChild(form.children[2]);
- container.appendChild(form.children[2]);
- container.appendChild(form.children[2]);
- enhanceTextArea();
- });
- }
- function createConfigEditor(container) {
- var lines = [];
- var innerHTML = "<li>";
- regexList.forEach(function (each) {
- var res;
- if (each.res.startsWith("https://")) {
- res = "<img class=\"board-noelshack\" src=\"" + each.res + "\">";
- } else {
- res = each.res;
- }
- var idButton = getId();
- innerHTML +=
- each.reg + " => " + res + space +
- "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
- "</li>" +
- "<li>";
- lines.push({id:idButton, each:each});
- });
- var idButtonPlus = getId();
- var idInputKey = getId();
- var idInputValue = getId();
- innerHTML +=
- "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
- " => " +
- "<input class=\"profile-biography\" id=\"" + idInputValue + "\" type=\"text\" style=\"height: 30px;\"/>" +
- "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
- "</li>";
- container.innerHTML = innerHTML;
- lines.forEach(function (line, i) {
- var button = document.getElementById(line.id);
- button.style.backgroundColor = "Transparent";
- button.style.border = "none";
- button.onclick = function() {
- regexList.splice(i, 1);
- localStorage.setItem("regexList", JSON.stringify(regexList));
- createConfigEditor(container);
- };
- });
- var buttonPlus = document.getElementById(idButtonPlus);
- buttonPlus.style.backgroundColor = "Transparent";
- buttonPlus.style.border = "none";
- buttonPlus.onclick = function() {
- regexList.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
- localStorage.setItem("regexList", JSON.stringify(regexList));
- createConfigEditor(container);
- };
- }
- function createConfigTopic(container) {
- var lines = [];
- var innerHTML = "<li>";
- bansRegex.forEach(function (each) {
- var idButton = getId();
- innerHTML +=
- each + space +
- "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
- "</li>" +
- "<li>";
- lines.push({id:idButton, each:each});
- });
- var idButtonPlus = getId();
- var idInputKey = getId();
- innerHTML +=
- "<input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
- "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
- "</li>";
- container.innerHTML = innerHTML;
- lines.forEach(function (line, i) {
- var button = document.getElementById(line.id);
- button.style.backgroundColor = "Transparent";
- button.style.border = "none";
- button.onclick = function() {
- bansRegex.splice(i, 1);
- localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
- createConfigTopic(container);
- };
- });
- var buttonPlus = document.getElementById(idButtonPlus);
- buttonPlus.style.backgroundColor = "Transparent";
- buttonPlus.style.border = "none";
- buttonPlus.onclick = function() {
- bansRegex.push(document.getElementById(idInputKey).value);
- localStorage.setItem("bansRegex", JSON.stringify(bansRegex));
- createConfigTopic(container);
- };
- }
- function createConfigBannis(container) {
- var lines = [];
- var idButtonPlus = getId();
- var idInputKey = getId();
- var innerHTML =
- // "<li><input class=\"profile-biography\" id=\"" + idInputKey + "\" type=\"text\" style=\"height: 30px;\"/>" +
- // "<button id=\"" + idButtonPlus + "\">" + imgEdit + "</button>" +
- // "</li>"+
- "<ul style=\" columns: 3; -webkit-columns: 3; -moz-columns: 3;\">";
- banProfiles.forEach(function (each) {
- var idButton = getId();
- innerHTML +=
- "<li>"+
- each.name + " / " + each.rank + space +
- "<button id=\"" + idButton + "\">" + imgDelete + "</button>" +
- "</li>";
- lines.push({id:idButton, each:each});
- });
- innerHTML += "</ul>";
- container.innerHTML = innerHTML;
- lines.forEach(function (line, i) {
- var button = document.getElementById(line.id);
- button.style.backgroundColor = "Transparent";
- button.style.border = "none";
- button.onclick = function() {
- banProfiles.splice(i, 1);
- localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
- createConfigBannis(container);
- };
- });
- // var buttonPlus = document.getElementById(idButtonPlus);
- // buttonPlus.style.backgroundColor = "Transparent";
- // buttonPlus.style.border = "none";
- // buttonPlus.onclick = function() {
- // banProfiles.push({reg:document.getElementById(idInputKey).value, res:document.getElementById(idInputValue).value});
- // localStorage.setItem("banProfiles", JSON.stringify(banProfiles));
- // createConfigBannis(container);
- // };
- }
- 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;
- }
- //-----------------------------------------------------
- // Messagerie
- //-----------------------------------------------------
- function traiterMessagerie() {
- var button = document.getElementsByClassName("btn btn-danger")[0];
- if (!button) {
- return;
- }
- button.parentElement.onsubmit = function() {
- return window.confirm("Voulez vous quittez le MP ?");
- };
- }
- //-----------------------------------------------------
- // 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 httpGetApiAsync(path, callback) {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
- callback(JSON.parse(xmlHttp.responseText).data);
- };
- xmlHttp.open("GET", "https://avenoel.org/api/v1/" + path, 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++;
- }
- //-----------------------------------------------------
- // Patch
- //-----------------------------------------------------
- //
- var version = "3.1.0";
- // 3.1.0 : Pastebin => Etape 3
- // + fin de la gestion des configs des données en cache
- // 3.0.0 : Pastebin => https://pastebin.com/SeqMW35E
- // + début de la page de config dans le profil
- // + Ajout de la gestion des mots clés éditeur dans le profil
- // 2.6.0 : Pastebin => https://pastebin.com/17GWSM7A
- // + initialisation de la page de configuration de l'appli
- // + ajout du ban de topic par mots clés
- // + optimisation de l'affichage des sujets
- // 2.5.0 : Pastebin => https://pastebin.com/JKKB1RJi
- // + ajout d'une liste de mots clés qui seront transformés dans l'éditeur.
- // 2.4.0 : Pastebin => https://pastebin.com/JCfGHLZ4
- // + ajout des dialogs de confirmation pour la suppression des topics/messages et ignorer.
- // + ajout des modifs dans la notifs des patchs.
- // 2.3.0 : Pastebin => https://pastebin.com/QXe2AJ6v
- // + Ajout d'une popup de confirmation pour quitter les MP
- // 2.2.0 : Pastebin => https://pastebin.com/0gPthPD4
- // + ajout d'un bouton pour afficher/masquer toutes les citations.
- // + amélioration de l'affichage de la nouvelle version
- // 2.1.0 : https://pastebin.com/T2dP5ryX
- // + controle de la version
- // + affichage du nombre de postes dans les favoris depuis la dernière visite
- // + controle de la version
- // + affichage du nombre de postes dans les favoris depuis la dernière visite
- // 2.0.8 : Pastebin => https://pastebin.com/21a6u01a
- // + correction du bug sur les citations (redirection bas de page)
- // 2.0.7 : Pastebin => https://pastebin.com/cD6VqLUY
- // + correction d'un bug sur la barre des favoris
- // + ajout de nouvelles actions dans l'éditeur de texte
- // + la barre des courriers est rafraichie toutes les 30s
- // 2.0.6 : Pastebin => https://pastebin.com/GvTLjLaF
- // + l'élément favoris/courrier se déplace avec le scroll
- // 2.0.5 : Pastebin => https://pastebin.com/pNqRphzh
- // + ajout du nombre de courriers non lus sur l'onglet
- // + possibilité d'afficher/masquer les citiations (masquées par défaut)
- // 2.0.4 : Pastebin => https://pastebin.com/4mCdppfi
- // + affichage de la liste des favoris dans les topics noirs
- // + correction bug sur les BL
- // + optimisation des listes
- // 2.0.3 : Pastebin =>https://pastebin.com/nPvLrBbV
- // + correction du bug d'affichage des courriers
- // 2.0.2 : Pastebin => https://pastebin.com/haqi3XRa
- // + Modification du bouton pour afficher/masquer
- // 2.0.1 : Pastebin => https://pastebin.com/vNmgUrCs
- // + 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