RainbowDDB

Ajoute un contour autour des messages signalés. La couleur change selon qui a effectué l'alerte ou si l'alerte a été traitée.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         RainbowDDB
// @namespace    CrazyJeux/Daring-Do
// @author       CrazyJeux/Daring-Do / H264
// @match        https://www.jeuxvideo.com/recherche/forums/0-*
// @match        https://www.jeuxvideo.com/forums/0-*
// @match        https://www.jeuxvideo.com/forums/42-*
// @match        https://www.jeuxvideo.com/forums/1-*
// @description  Ajoute un contour autour des messages signalés. La couleur change selon qui a effectué l'alerte ou si l'alerte a été traitée.
// @version      47.0.0
// @grant        none
// ==/UserScript==

const DISABLE_ALERT = false; //Switch on 'true' to disable all alerts on request.

(async function () {
    'use strict';

    function getPayload(doc) {
        const payloadRaw = [...doc.scripts].map(s => s.textContent.match(/jvc\.\w*Payload\s*=\s*["']([^"']+)["']/)).find(Boolean)?.[1];
        if (!payloadRaw) return null;
        try {
            return JSON.parse(atob(payloadRaw)); 
        } catch {
            return JSON.parse(payloadRaw); 
        }
    }

    function decodeSignaler(reponseJson) {
        if (reponseJson?.boost?.info?.includes("a déjà été signalé")) {
            return { couleur: "orange", reason : reponseJson?.boost?.value || null }; //byother
        }
        if (reponseJson?.message?.includes("Vous avez déjà signalé ce contenu")) {
            return { couleur: "red" }; //byme
        }
        if (reponseJson?.errors?.[0]?.includes("Cet utilisateur ne peut pas être signalé")) {
            return { couleur: "#9393f5" }; //isadmin
        }
        if (reponseJson?.message?.includes("Ce contenu a déjà été modéré. En cas de problème")) {
            return { couleur: "lightgreen" }; //ishandledbymod
        }
        if (reponseJson?.message?.includes("Ce contenu a déjà été modéré par un administrateur")) {
            return { couleur: "turquoise" }; //ishandledbyadmin
        }
        return null;
    }

    async function traiterListeSujets() {
        const listeSujets = document.querySelectorAll('.tablesForum__cellSubject');
        let i = 0, total = listeSujets.length;
        for (const sujet of listeSujets) {
            i++;
            document.getElementById('rainbow-ddb-btn').textContent = `Rainbow DDB (${i}/${total})`;
             /*await*/ (async () => {

                const topicId = sujet.href.split('/').pop().split('-')[2];

                //Open, Fetch, Parse sujet
                const resOpenSujet = await fetch(sujet.href);
                if (!resOpenSujet.ok) return;
                const textOpenSujet = await resOpenSujet.text();
                const docOpenSujet = new DOMParser().parseFromString(textOpenSujet, 'text/html');

                const data = getPayload(docOpenSujet);

                const firstMessage = data.listMessage[0];
                const urlSignaler = firstMessage.actions?.report?.url;
                if (!urlSignaler) return;

                const reponseDDB = await fetch(new URL(urlSignaler, location.origin));
                const reponseDDBJson = await reponseDDB.json();
                const result = decodeSignaler(reponseDDBJson);
                if (!result) return;

                sujet.style.cssText += `;color:${result.couleur} !important;`;

                /* FOR FUTUR IN SPA (CSS style)
                const blocHtml = document.querySelector(`.tablesForum__cellSubject[href*="-${topicId}-"]`);
                blocHtml.style.cssText += `;color:${result.couleur} !important;`;
                */
            })();
        }
    }

    async function traiterListeMessages() {
        const data = getPayload(document);
        let i = 0, total = data.listMessage.length;
        for (const message of data.listMessage) {
            i++;
            document.getElementById('rainbow-ddb-btn').textContent = `Rainbow DDB (${i}/${total})`;
            await (async () => {

                const messageId = message.id;

                const urlSignaler = message.actions?.report?.url;
                if (!urlSignaler) return;

                const reponseDDB = await fetch(new URL(urlSignaler, location.origin));
                const reponseDDBJson = await reponseDDB.json();
                const result = decodeSignaler(reponseDDBJson);
                if (!result) return;

                const blocHtml = document.querySelector(`#message-${messageId} .messageUser__card`);
                blocHtml.style.cssText += `;box-shadow:0 0 5px 5px ${result.couleur} !important;`;

                //`Signalé pour ${result.reason}`;
            })();
        }
    }

    function initBtn() {

        let placeForBtn = (window.innerWidth >= 1000) ? '.layout__contentAside > *:first-child' : '.titleMessagesUsers__title'

        document.querySelector(placeForBtn).insertAdjacentHTML('beforebegin', `
            <button id="rainbow-ddb-btn" class="btn btn-outline-dark jvchat-hide" style="border-radius: 0.45rem; width:95%; display: block; margin: 0 auto 20px;">
               RainbowDDB
            </button>
        `);
        document.getElementById('rainbow-ddb-btn').addEventListener('click', function () {

            if (!sessionStorage.getItem('rainbow-ddb-confirme') && !DISABLE_ALERT) {
                alert("Ce script fait énormement de requêtes (concept de 2016).\nA utiliser avec modération (Cloudflared).");
                sessionStorage.setItem('rainbow-ddb-confirme', '1');
            }
            if (location.href.includes('/forums/42-') || location.href.includes('/forums/1-')) {
                traiterListeMessages();
            }
            if (location.href.includes('/forums/0-') || location.href.includes('/recherche/forums/0-')) {
                traiterListeSujets();
            }

        }, { once: true });
    }
    initBtn();

})();