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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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      42.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 "orange"; //byother
        }
        if (reponseJson?.message?.includes("Vous avez déjà signalé ce contenu")) {
            return "red"; //byme
        }
        if (reponseJson?.errors?.[0]?.includes("Cet utilisateur ne peut pas être signalé")) {
            return "#9393f5"; //isadmin
        }
        if (reponseJson?.message?.includes("Ce contenu a déjà été modéré. En cas de problème")) {
            return "lightgreen"; //ishandledbymod
        }
        if (reponseJson?.message?.includes("Ce contenu a déjà été modéré par un administrateur")) {
            return "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 couleur = decodeSignaler(reponseDDBJson);
                if (!couleur) return;

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

                /* FOR FUTUR IN SPA (CSS style)
                const blocHtml = document.querySelector(`.tablesForum__cellSubject[href*="-${topicId}-"]`);
                blocHtml.style.cssText += `;color:${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 couleur = decodeSignaler(reponseDDBJson);
                if (!couleur) return;

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

    function initBtn() {

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

        document.querySelector(placeForBtn).insertAdjacentHTML('beforebegin', `
            <button id="rainbow-ddb-btn" class="btn btn-outline-dark" 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();

})();