Full_Black_List

Supprime totalement les sujets des pseudo blacklistés depuis la blacklist JVC.

目前為 2025-01-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Full_Black_List
// @namespace    Full_Black_List
// @version      0.13.2
// @description  Supprime totalement les sujets des pseudo blacklistés depuis la blacklist JVC.
// @author       Atlantis
// @match        *://www.jeuxvideo.com/recherche/forums/0-*
// @match        *://www.jeuxvideo.com/forums/0-*
// @match        *://www.jeuxvideo.com/forums/42-*
// @match        *://www.jeuxvideo.com/forums/1-*
// @match        *://www.jeuxvideo.com/forums/message*
// @match        *://www.jeuxvideo.com/messages-prives/message.php*
// @match        *://www.jeuxvideo.com/messages-prives/indesirables.php
// @match        *://www.jeuxvideo.com/sso/blacklist.php
// @match        *://www.jeuxvideo.com/login*
// @icon         https://images.emojiterra.com/google/noto-emoji/unicode-16.0/color/128px/274c.png
// @license      MIT
// @grant        none
// ==/UserScript==

//___FETCH___SYNCH__BL___(ALL)___
async function synchfetchpseudos() {
    const response = await fetch('/sso/blacklist.php');
    const htmlText = await response.text();

    const parser = new DOMParser();
    const doc = parser.parseFromString(htmlText, 'text/html');

    let pseudos = doc.querySelectorAll('#blacklist span');

    let pseudoList = [];
    pseudos.forEach(span => {
        pseudoList.push(span.textContent.trim());
    });

    localStorage.setItem('fullblacklistJVC', JSON.stringify(pseudoList));

}

//_______PAGE_DE______CONNEXION___(Login)___
if (window.location.href.indexOf('jeuxvideo.com/login') > -1) {
    localStorage.removeItem('fullblacklistJVC');
}

//______MASQUAGE_____BLOC____MESSAGE____FORUM__(Topic_1_42)____
if (window.location.href.indexOf('jeuxvideo.com/forums/1-') > -1 || window.location.href.indexOf('jeuxvideo.com/forums/42-') > -1 || window.location.href.indexOf('jeuxvideo.com/forums/message/') > -1) {

    //masquage_message
    const blacklistBlocks = document.querySelectorAll('.msg-pseudo-blacklist');
    blacklistBlocks.forEach(block => {
        block.remove();
    });

    //ajout dun event au bouton blacklist
    const blacklisterBtns = document.querySelectorAll('.picto-msg-tronche');
    blacklisterBtns.forEach(function(btn) {
        btn.addEventListener('click', function() {
            sessionStorage.setItem('fullblacklistJVCAwait', 'true');
        });
    });

    // Mise à jour de la Blacklist du script apres actualisation
    let bljvcawait = sessionStorage.getItem('fullblacklistJVCAwait');
    if (bljvcawait === 'true') {
        synchfetchpseudos(); // fullblacklistJVCAwait est 'true'
        sessionStorage.removeItem('fullblacklistJVCAwait'); // Supprime la clé 'fullblacklistJVCAwait'
    }

}

//______BLACKLIST____LISTE_SUJETS___(Liste_Sujet)(Recherche)___
if (window.location.href.indexOf('jeuxvideo.com/forums/0-') > -1 || window.location.href.indexOf('jeuxvideo.com/recherche/forums/0-') > -1) {
    // Fonction pour récupérer la liste des pseudos blacklistés depuis JVC ou le local storage
    function getListeBlacklist() {
        let liste = localStorage.getItem('fullblacklistJVC');
        if (liste) {
            return JSON.parse(liste);
        } else {
            synchfetchpseudos(); // Fonction à exécuter si la liste est pseudo connecté
            setTimeout(() => {
                location.reload();
            }, 2000);
        }
    }

    // Fonction pour supprimer des éléments insensible à la casse
    function supprimerParListeDePseudos(pseudos) {
        const pseudosLower = pseudos.map(pseudo => pseudo.toLowerCase()); // liste tout les pseudo en miniusucle
        document.querySelectorAll('li').forEach(item => {
            const auteur = item.querySelector('.topic-author');
            if (auteur && pseudosLower.includes(auteur.textContent.trim().toLowerCase())) {
                // Supprimer le sujet si ateur
                item.remove();
            }
        });
    }



    let pseudosBlacklist = getListeBlacklist();
    supprimerParListeDePseudos(pseudosBlacklist);
}

//_______BOUTON_____BLACKLIST___LISTE_SUJET_(Liste_Sujet)_____
if (window.location.href.indexOf('jeuxvideo.com/forums/0-') > -1) {

    var divContainer = document.createElement('div');
    divContainer.classList.add('custom-btn-container');

    // Créer les spans à l'intérieur de la div
    var span1 = document.createElement('span');
    //span1.classList.add('btn');
    span1.classList.add('btn', 'btn-actu-new-list-forum', 'btn-actualiser-forum', 'icon-refresh');
    span1.textContent = 'Actu BL';
    span1.title = 'Actualiser la blacklist des Sujets';
    span1.style.borderRadius = '6px';
    span1.style.minWidth = '5rem';
    //span1.style.textDecoration = 'underline';
    span1.addEventListener('click', synchfetchpseudos);
    span1.addEventListener('click', function () { alert('Filtrage des topics actualisés avec la blacklist JVC ✅'); });
    span1.addEventListener('click', function () { location.reload(); });

    // Vous pouvez ajouter d'autres spans si nécessaire
    var span2 = document.createElement('span');
    //span2.classList.add('btn');
    span2.classList.add('btn', 'btn-actu-new-list-forum', 'btn-actualiser-forum');
    span2.textContent = 'Voir BL';
    span2.title = 'Voir/Editer/Eporter la BlackList';
    span2.style.borderRadius = '6px';
    span2.style.minWidth = '4rem';
    //span2.style.textDecoration = 'underline';
    span2.addEventListener('click', function() { window.open('/sso/blacklist.php', '_blank'); });

    // Ajouter les spans à la div
    divContainer.appendChild(span1);
    divContainer.appendChild(document.createTextNode('\u00A0\u00A0'));
    divContainer.appendChild(span2);

    // Trouver l'élément avec la classe 'bloc-pagi-default px-3 px-lg-0'
    var blocPagiDefault = document.querySelector('.bloc-pagi-default.px-3.px-lg-0');
    var pagiBeforeListTopic = document.querySelector('.pagi-before-list-topic');

    // Ajouter la div juste après cette div spécifique
    pagiBeforeListTopic.parentNode.insertBefore(divContainer, pagiBeforeListTopic.nextSibling);

}


//______________MASQUAGE____BLOC__MESSAGE_MP__(Message_MP)____
if (window.location.href.indexOf('jeuxvideo.com/messages-prives/message.php') > -1) {

    //masquage_message_bl
    const blacklistBlocks = document.querySelectorAll('.msg-pseudo-blacklist');
    blacklistBlocks.forEach(block => {
        block.remove();
    });


    //liste_local_storage_blacklist_les_MP
    function supprimerParListeDePseudos(pseudos) {
        const pseudosLower = pseudos.map(pseudo => pseudo.toLowerCase()); // Liste tous les pseudos en minuscules
        const blacklistBlocks = document.querySelectorAll('.bloc-message-forum');
        blacklistBlocks.forEach(block => {
            const auteur = block.querySelector('.bloc-pseudo-msg'); // Cibler l'élément avec le pseudo
            const boutonBlacklist = block.querySelector('.picto-msg-tronche');
            if (auteur && pseudosLower.includes(auteur.textContent.trim().toLowerCase())) {
                boutonBlacklist.click(); // BL_MP
            }
        });
    }

    //recup_local_storage
    function getListeBlacklist() {
        let liste = localStorage.getItem('fullblacklistJVC');
        if (liste) {
            return JSON.parse(liste);
        } else {
            synchfetchpseudos(); // Fonction à exécuter si la liste est pseudo connecté
            setTimeout(() => {
                location.reload();
            }, 1000);
        }
    }

    let pseudosBlacklist = getListeBlacklist();
    supprimerParListeDePseudos(pseudosBlacklist);

}


//________________Suuppression_combiné_BL___(Page_BlackList_MP)____
if (window.location.href.indexOf('jeuxvideo.com/messages-prives/indesirables.php') > -1) {
    document.querySelectorAll('.mp_delete_blacklist').forEach(function(button) {
        button.addEventListener('click', function() {
            const userId = this.getAttribute('data-id'); // Récupère l'ID depuis l'attribut data-id
            fetch(`/sso/ajax_delete_blacklist.php?id_alias_unblacklist=${userId}`)
                .then(() => {
                    localStorage.removeItem('fullblacklistJVC'); //vide black list local storage
                });
        });
    });
}

//________________MISE_A_JOUR_PAGE_BLACK_LISTE__(Page_BlackList_Forums)____
if (window.location.href.indexOf('jeuxvideo.com/sso/blacklist.php') > -1) {

    updatepseudos();

    // Parcourt chaque élément et ajoute un gestionnaire d'événement
    const crosses = document.querySelectorAll('.icon-cross-entypo');
    crosses.forEach(cross => {
        cross.addEventListener('click', updatepseudos);
    });

    function updatepseudos() {
        setTimeout(() => {
            let pseudos = document.querySelectorAll('#blacklist span');

            let pseudoList = [];
            pseudos.forEach(span => {
                pseudoList.push(span.textContent.trim());
            });

            localStorage.setItem('fullblacklistJVC', JSON.stringify(pseudoList));
        }, 1000); //delais pour capturer la page à jour
    }
}

//_______________EXPORT_PAGE__BLACKLIST___(Page_BlackList_Forums)____
if (window.location.href.indexOf('jeuxvideo.com/sso/blacklist.php') > -1) {
    'use strict';

    // Fonction d'exportation de la Blacklist
    function exportBlacklist() {

        let listItems = document.querySelectorAll('#blacklist li');
        let idList = [];
        listItems.forEach(li => {
            let idAlias = li.getAttribute('data-id-alias');
            idList.push(idAlias);
        });
        let jsonBlob = new Blob([JSON.stringify(idList, null, 2)], { type: 'application/json' });

        //creation_lien_telechargement
        let link = document.createElement('a');
        link.href = URL.createObjectURL(jsonBlob);
        link.download = 'Blacklist_JVC.json';
        link.click();
    }

    // Fonction d'importation de la Blacklist depuis un fichier JSON
    async function importBlacklist(event) {
        let file = event.target.files[0];
        if (!file) return;

        // Fetch recuperer hash preference forum
        const response = await fetch('/forums/0-51-0-1-0-1-0-0.htm');
        const htmlfofo = await response.text();
        const parser = new DOMParser();
        const doc = parser.parseFromString(htmlfofo, 'text/html');
        const ajaxHashpref = doc.querySelector('#ajax_hash_preference_user');
        // preference_user => necassaire pour ajouter à la blacklist JVC

        let reader = new FileReader();
        reader.onload = async e => {
            try {
                importBtn.textContent = 'Load...';
                // Lecture et parsing du fichier JSON
                let blacklist = JSON.parse(e.target.result);

                // Boucle ajax pour ajouter pseudo blacklist de la liste
                let fetchPromises = blacklist.map(idAlias => {
                    let url = `/forums/ajax_forum_blacklist.php?id_alias_msg=${idAlias}&action=add&ajax_hash=${ajaxHashpref.value}`;
                    return fetch(url);
                });
                //attendre resultat pour refresh
                let results = await Promise.all(fetchPromises);
                window.location.reload();
            } catch (error) {
                alert("Fichier JSON invalide");
                window.location.reload();
            }
        };
        reader.readAsText(file);
    }

    async function deleteBlacklist() {
        strikeBtn.textContent = 'Loading...';
        // Récupérer tous les éléments <li> dans #blacklist
        let listItems = document.querySelectorAll('#blacklist li');
        let idList = [];
        listItems.forEach(li => {
            let idAlias = li.getAttribute('data-id-alias');
            idList.push(idAlias);
        });
    
        // Créer un tableau de promesses pour les requêtes Ajax
        let fetchPromises = idList.map(idAlias => {
                let url = `/sso/ajax_delete_blacklist.php?id_alias_unblacklist=${idAlias}`;
                return fetch(url);
        });
        // Attendre que toutes les requêtes se terminent
        let results = await Promise.all(fetchPromises);
        window.location.reload();
    }


    // Ajouter les boutons Export et Import
    let container = document.querySelector('.layout__row.layout__content.layout__row--gutter.mb-5');
    if (!container) return; // Si le container n'existe pas, ne rien faire
    let ull1 = document.createElement('ul');
    let ull2 = document.createElement('ul');

    // Création du bouton d'export
    let exportBtn = document.createElement('button');
    exportBtn.textContent = 'Exporter';
    exportBtn.title = 'Exporter BlackList JVC en Fichier';
    exportBtn.className = 'simpleButton';
    exportBtn.style.borderRadius = '6px';
    exportBtn.addEventListener('click', exportBlacklist);

    // Création du bouton d'import
    let importBtn = document.createElement('button');
    importBtn.textContent = 'Importer';
    importBtn.title = 'Importer BlackList depuis un Fichier';
    importBtn.className = 'simpleButton';
    importBtn.style.borderRadius = '6px';
    importBtn.addEventListener('click', function() {
        let input = document.createElement('input');
        input.type = 'file';
        input.accept = '.json';
        input.addEventListener('change', importBlacklist);
        input.click();
    });

    let strikeBtn = document.createElement('button');
    strikeBtn.textContent = 'Vider la BlackList';
    strikeBtn.title = 'Vider toute la blacklist JVC + Script';
    strikeBtn.className = 'simpleButton';
    strikeBtn.style.borderRadius = '6px';
    strikeBtn.style.backgroundColor = 'red';
    strikeBtn.addEventListener('click', () => window.confirm('⚠️ Supprimer toute la blacklist (JVC + Script) ??⚠️') ? deleteBlacklist() : null);


    // Ajouter les boutons au container
    ull1.appendChild(importBtn);
    ull1.appendChild(document.createTextNode('\u00A0\u00A0')); // Espace entre les boutons
    ull1.appendChild(exportBtn);
    ull2.appendChild(strikeBtn);
    container.appendChild(ull1);
    container.appendChild(ull2);
}