// ==UserScript==
// @name BlacklistED
// @namespace http://tampermonkey.net/
// @version 0.51
// @description Pour se débarrasser des spammeurs envoyés par Webechiasse
// @author GolemPuant
// @match http://onche.org/*
// @match https://onche.org/*
// @match http://www.onche.org/*
// @match https://www.onche.org/*
// @license MIT
// @icon https://image.noelshack.com/fichiers/2023/12/5/1679674847-8373460.png
// @grant none
// ==/UserScript==
(function() {
const cssIcone = `
.blacklistbutton {
outline: none;
border: none;
cursor: pointer;
background: none;
color: #999faf;
font-size: 60%;
}`;
const cssIcone1 = `
.blacklistdiv {
display: flex;
}`;
const cssIconeHover = `
.blacklistbutton:hover {
color: #4285F4;
}
`;
const bloqued = `
.blocked {
text-decoration: line-through;
}
`;
const bloquedImg = `
.blockedImg {
filter: grayscale(100%);
}
`;
const cssBlocked = `
body.forum.grey .blacklistbutton {
color: #788093;
}`
const cssBlocked1 = `
body.forum.blue .blacklistbutton {
color: #839ab2;
}`
const cssAvenoel = `
.avenoelBL {
background: #422100 !important;
}`
const csstypebl = `
.typeblbutton {
appearance: none;
border: 2px solid #1A1A1A;
border-radius: 15px;
box-sizing: border-box;
cursor: pointer;
display: inline-block;
font-family: Roobert,-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
font-size: 16px;
font-weight: 600;
line-height: normal;
margin: 0 auto;
min-width: 0;
outline: none;
padding: 6px 2px;
text-align: center;
text-decoration: none;
transition: all 300ms cubic-bezier(.23, 1, 0.32, 1);
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
width: 50%;
will-change: transform;
}`
const csstypebl1 = `
.typeblbutton:disabled {
pointer-events: none;
cursor: not-allowed
}`
const csstypebl2 = `
.typeblbutton:hover {
background-color: #71c2fb;
box-shadow: rgba(0, 0, 0, 0.25) 0 8px 15px;
transform: translateY(-2px);
}
`
const csstypebl3 = `
.typeblbutton:active {
box-shadow: none;
transform: translateY(0);
} `
//Intégration de la blackliste du script de Programafion
let list = JSON.parse(localStorage?.getItem('blacklist'));
let otherScriptList = localStorage?.getItem('blacklist_userscript.blacklist')?.split(',')
if(otherScriptList){
let set = new Set(list.map(item => item.toLowerCase()));
for (let item of otherScriptList) {
if (!set.has(item.toLowerCase())) {
set.add(item);
}
}
let result = Array.from(set);
setList(result)
setPrograList(result)
}
const typeBL = localStorage?.getItem('blacklisttype');
if(!typeBL) localStorage?.setItem('blacklisttype', 'onche'); // Types : onche, avenoel, masquer
// Stocke une liste de chaînes de caractères dans le stockage local
function setList(list) {
localStorage.setItem('blacklist', JSON.stringify(list));
}
function setPrograList(list) {
localStorage.setItem('blacklist_userscript.blacklist', (JSON.stringify(list))?.replace(/[\[\]"]/g, ''));
}
// Récupère une liste de chaînes de caractères depuis le stockage local
function getList() {
let list = localStorage.getItem('blacklist');
if (!list) {
list = [];
localStorage.setItem('blacklist', JSON.stringify(list));
} else {
list = JSON.parse(list);
}
return list;
}
function getPrograList() {
let otherScriptList = localStorage?.getItem('blacklist_userscript.blacklist')
console.log(localStorage?.getItem('blacklist_userscript.blacklist'))
if (!otherScriptList) {
otherScriptList = [];
localStorage.setItem('blacklist_userscript.blacklist', otherScriptList);
} else {
otherScriptList = otherScriptList;
}
return otherScriptList;
}
// Ajoute un élément à la liste stockée dans le stockage local
function addToBL(item) {
const list = getList();
const otherlist = getPrograList();
if(otherlist){
if(!(otherlist?.includes(item) || otherlist?.includes(item?.toLowerCase()))){
let jslist = null;
if(otherlist?.length > 0){
jslist = otherlist?.split(',')
jslist.push(item);
console.log(jslist)
let newotherlist = (JSON.stringify(jslist))?.replace(/[\[\]"]/g, '');
localStorage.setItem('blacklist_userscript.blacklist', newotherlist);
}else{
jslist = item;
localStorage.setItem('blacklist_userscript.blacklist', jslist);
}
}
}
if (!list?.includes(item)) {
list.push(item);
setList(list);
console.log(`Utilisateur ${item} bloqué`);
} else {
console.log(`${item} est déjà bloqué`);
}
initialiser();
}
// Supprime un élément de la liste stockée dans le stockage local
function removeFromBL(item) {
let list = getList();
const otherlist = getPrograList();
if((otherlist?.includes(item) || otherlist?.includes(item?.toLowerCase()))){
let jslist = otherlist?.split(',')
jslist = jslist.filter(function(it) {
return it?.toLowerCase() !== item?.toLowerCase();
});
let newotherlist = (JSON.stringify(jslist))?.replace(/[\[\]"]/g, '');
localStorage.setItem('blacklist_userscript.blacklist', newotherlist);
}
if (list.includes(item) || list.includes(item?.toLowerCase())) {
list = list.filter((listItem) => listItem !== item);
list = list.filter((listItem) => listItem !== item?.toLowerCase());
setList(list);
console.log(`Utilisateur ${item} débloqué`);
} else {
console.log(`${item} n'est pas bloqué`);
}
if(document.querySelectorAll('.topics > .topic')) initialisertopic();
if(document.querySelectorAll('.messages > .message')) initialiser();
}
function isBL(item) {
const list = (getList())?.map(function(el) {
return el.toLowerCase();
});
return list.includes(item) || list.includes(item?.toLowerCase());
}
function initialiserListe(){
const elements = document.querySelector('#divBL')?.remove();
const typeBL = localStorage?.getItem('blacklisttype');
const right = document.querySelector('#right');
let divBL = document.createElement('div');
divBL.id = "divBL";
let divtitle = document.createElement('div');
let divliste = document.createElement('div');
let divcog = document.createElement('div');
let divoptions = document.createElement('div');
let divoptionsfils = document.createElement('div');
divcog.classList.add('mdi');
divcog.classList.add('mdi-cog');
divcog.classList.add('right');
divcog.style = 'cursor: pointer;transition:0.5s';
divoptions.classList.add('content');
divoptions.classList.add('rows');
divoptions.setAttribute('hidden', 'true');
divoptions.style='display:none;';
let textoptions = document.createElement('small');
textoptions.textContent = 'Changer de thème';
divoptions.appendChild(textoptions);
let onchebutton = document.createElement('button');
let avebutton = document.createElement('button');
onchebutton.classList.add('typeblbutton');
avebutton.classList.add('typeblbutton');
if(typeBL == "onche"){
onchebutton.disabled = true;
avebutton.disabled = false;
}
if(typeBL == "avenoel"){
onchebutton.disabled = false;
avebutton.disabled = true;
}
//avebutton.style = 'background: #71c2fb;outline: none;border: none;border-radius: 5px;width: fit-content;margin-left: auto;margin-right: auto;cursor: pointer;';
//avebutton.classList.add('blacklistbutton');
onchebutton.textContent = "Basique";
avebutton.textContent = "Avenoel";
onchebutton?.addEventListener('click', function(event) {
localStorage?.setItem('blacklisttype', 'onche');
window.location.reload();
});
avebutton?.addEventListener('click', function(event) {
localStorage?.setItem('blacklisttype', 'avenoel');
window.location.reload();
});
divoptionsfils.appendChild(onchebutton);
divoptionsfils.appendChild(avebutton);
divoptions.appendChild(divoptionsfils);
divcog?.addEventListener('click', function(event) {
if(divoptions.getAttribute('hidden') == 'true')
{
divcog.style = 'cursor: pointer;transition:0.5s;transform: rotate(90deg);';
divoptions.setAttribute('hidden', 'false');
divoptions.style = 'display:flex;'
}else{
divcog.style = 'cursor: pointer;transition:0.5s';
divoptions.setAttribute('hidden', 'true');
divoptions.style='display:none;'
};
});
divtitle.classList.add('title');
divtitle.innerHTML = "Blacklist";
divtitle.appendChild(divcog);
divBL.appendChild(divtitle);
divBL.appendChild(divoptions);
divliste.classList.add('content');
divliste.classList.add('rows');
divliste.style = 'margin-top:0px; max-height: 130px; overflow-y: auto;'
divBL.appendChild(divliste);
let liste = getList();
let text = document.createElement('small');
(liste.length > 0) ? text.textContent = 'Cliquer sur un pseudo pour le débloquer' : text.textContent = 'Votre blacklist est vide' ;
divliste.appendChild(text);
liste?.forEach((elem) => {
let userbutton = document.createElement('button');
userbutton.classList.add('blacklistbutton');
userbutton.textContent = elem;
userbutton.title = "débloquer "+ elem;
userbutton.addEventListener('click', function() {
removeFromBL(elem);
});
userbutton.style = "width: max-content; margin:auto; font-size: 100%"
divliste.appendChild(userbutton);
})
divBL.classList.add('bloc');
divBL.classList.add('border');
divBL.classList.add('red');
right.appendChild(divBL);
}
function initialisertopic(){
const topics = document.querySelectorAll('.topics > .topic'); // sélectionne tous les div .message qui sont les fils de la div .message elle-même fille de la div #left
initialiserListe();
topics.forEach((topic) => { // boucle sur chaque élément
const avatar = topic.querySelector('.topic-left > img');
const pseudo = topic.querySelector('.topic-subject > .topic-username') || topic.querySelector('.topic-subject > .topic-nb > .topic-username');
const typeBL = localStorage?.getItem('blacklisttype');
switch(typeBL) {
case 'avenoel':
// Version colorée d'Avenoel
if(isBL(pseudo.innerHTML)){
console.log(topic.style)
topic.classList.add('avenoelBL')
}else{
topic.classList.remove('avenoelBL')
}
break;
case 'masquer':
// Version qui masque les topics
break;
default:
// Version basique d'Onche
if(isBL(pseudo.innerHTML)){
const sujetspan = topic.querySelector('.topic-subject > span:not(.topic-nb)');
if(sujetspan){
pseudo?.classList.add('blocked');
avatar?.classList.add('blockedImg');
let sujetdiv = document.createElement("div");
let sujetdivparent = document.createElement("div");
sujetdivparent.classList.add('_format');
sujetdivparent.classList.add('_spoiler');
sujetdivparent.classList.add('sujetdiv');
sujetdivparent?.addEventListener('click', function(event) {
if(!sujetdivparent?.classList.contains('active')){
event.preventDefault();
}
});
const sujeta = topic.querySelector('a.link');
sujeta?.addEventListener('click', function(event) {
if(!sujetdivparent?.classList.contains('active')){
event.preventDefault();
if(event.target !== sujetdivparent){
alert("Par mesure de sécurité vous devez cliquer sur l'intitulé du topic pour l'afficher avant de pouvoir aller dessus")
}
}
});
sujetdivparent?.appendChild(sujetdiv)
sujetdiv.innerHTML = sujetspan?.innerHTML;
sujetspan?.parentNode.replaceChild(sujetdivparent, sujetspan);
}
}
else{
const sujetdiv = topic?.querySelector('.sujetdiv')?.querySelector('div');
if(sujetdiv){
pseudo?.classList.remove('blocked');
avatar?.classList.remove('blockedImg');
let sujetspan = document.createElement("span");
sujetspan.innerHTML = sujetdiv?.innerHTML;
sujetdiv?.parentNode.replaceChild(sujetspan, sujetdiv);
}
}
}
});
}
function initialiser(){
const elements = document.querySelectorAll('.blacklistdiv');
elements.forEach(element => element.remove());
const messages = document.querySelectorAll('.message'); // sélectionne tous les div .message qui sont les fils de la div .message elle-même fille de la div #left
const typeBL = localStorage?.getItem('blacklisttype');
initialiserListe();
messages.forEach((message) => { // boucle sur chaque élément
const fils = message.querySelector('.message-top > .right');
const pseudo = message.getAttribute('data-username');
const icone = document.createElement('div');
icone.classList.add('mdi');
icone.classList.add('blacklistdiv');
const bouton = document.createElement('div');
bouton.classList.add('blacklistbutton');
const username = message.querySelector('.message-top > .message-infos > .message-username');
const avatar = message.querySelector('.avatar');
if(isBL(pseudo)){
//Blacklisté
bouton.textContent = "débloquer";
bouton.addEventListener('click', function() {
removeFromBL(pseudo);
});
let elementstohide = message.querySelectorAll('.message-content, .answer, .message-bottom');
switch(typeBL) {
case 'avenoel':
// Type avenoel
message.classList.add('avenoelBL');
break;
default:
username.classList.add('blocked');
avatar.classList.add('blockedImg');
elementstohide.forEach(element => {element.style.display = 'none';});
if(message?.classList.contains('answer')){
let collapser = message.querySelector('.answer .see-more');
(collapser)? collapser.style.display = 'none' : collapser = null;
}
}
}else{
//Pas blacklisté
username.classList.remove('blocked');
avatar.classList.remove('blockedImg');
bouton.textContent = "bloquer";
bouton.addEventListener('click', function() {
addToBL(pseudo);
});
let elementstoshow = message.querySelectorAll('.message-content, .answer, .answer .see-more');
let bottomtoshow = message.querySelectorAll('.message-bottom');
switch(typeBL) {
case 'avenoel':
// Type Avenoel
message.classList.remove('avenoelBL');
break;
default:
elementstoshow.forEach(element => {element.style.display = 'block';});
bottomtoshow.forEach(element => {element.style.display = 'flex';});
}
}
// Ajouter condition pour savoir si l'utilisateur est bloqué ou pas
icone.appendChild(bouton);
fils.prepend(icone);
});
}
function GM_addStyle(css) {
const style = document.getElementById("GM_addStyleBy8626") || (function() {
const style = document.createElement('style');
style.type = 'text/css';
style.id = "GM_addStyleBy8626";
document.head.appendChild(style);
return style;
})();
const sheet = style.sheet;
sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
}
GM_addStyle(cssIcone);
GM_addStyle(cssIcone1);
GM_addStyle(cssIconeHover);
GM_addStyle(bloqued);
GM_addStyle(bloquedImg);
GM_addStyle(cssBlocked);
GM_addStyle(cssBlocked1);
GM_addStyle(cssAvenoel);
GM_addStyle(csstypebl);
GM_addStyle(csstypebl1);
GM_addStyle(csstypebl2);
GM_addStyle(csstypebl3);
//Messages dans un topic
try{
const messagesElement = document.querySelector('.messages');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
initialiser();
observer.disconnect();
}
});
});
observer.observe(messagesElement);
}catch(err){
}
//Topics sur le forum
try{
const topicsElement = document.querySelector('.topics');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
initialisertopic();
observer.disconnect();
}
});
});
observer.observe(topicsElement);
}catch(err){
}
//Barre des blacklistés
try{
const rightElement = document.querySelector('#right');
const observer1 = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
initialiserListe();
observer1.disconnect();
}
});
});
observer1.observe(rightElement);
}catch(err){
console.log(err)
}
'use strict';
// Your code here...
})();