RisiOnche

Risibank sur onche.org (Fix)

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         RisiOnche
// @namespace    RisiOnche
// @version      0.60.0
// @description  Risibank sur onche.org (Fix)
// @author       RisiOnche, Catalyst
// @match        https://risibank.fr/compte*
// @match        https://onche.org/topic/*
// @match        https://onche.org/forum/*
// @match        https://onche.org/chat/*
// @match        https://onche.org/profil*
// @exclude      https://onche.org/forum/**/search
// @exclude      https://onche.org/forum/**/search?*
// @icon         https://www.risishack.com/lfoubw.png
// @grant        GM.xmlHttpRequest
// @grant        GM.setValue
// @grant        GM.getValue
// @connect      cloud.onche.org
// @connect      noelshack.com
// ==/UserScript==


if (location.hostname === 'onche.org') {

    //GLOBAL_VALUE
    let overlay = JSON.parse(localStorage.getItem('risi-overlay')) ?? false; //UnString
    let risiApi = JSON.parse(localStorage.getItem('risi-api')) ?? false; //UnString
    let risiOpen = JSON.parse(localStorage.getItem('risi-toggle-open')) ?? true; //UnString


    let showNSFW = false;
    if (location.href.includes('onche.org/forum/3')) showNSFW = true;
    if (document.querySelector('.title a[href*="onche.org/forum/3"]')) showNSFW = true;


    //GLOBAL_SELECTOR
    let placeChangeModAfter;
    let placeBtnAfter;
    let placeRisiAfter;
    let textArea;
    if (location.href.includes('onche.org/chat/')) { //MP CHAT
        placeChangeModAfter = document.querySelector('#right .bloc.border.green, #right .bloc.border:last-of-type');
        placeBtnAfter = document.querySelector('.Messages');
        placeRisiAfter = document.querySelector('.Form.insert-image');
        textArea = document.querySelector('.Form__input');
    } else {
        placeChangeModAfter = document.querySelector('#right .bloc.border.green, #right .bloc.border:last-of-type');
        placeBtnAfter = document.querySelector('#post .composer__toolbar-items .onche-add, #post .composer__toolbar-items .item:last-child');
        placeRisiAfter = document.querySelector('#post .composer__stickers-host');
        textArea = document.querySelector('#post textarea');
    }

    // Injection obligatoire de l'api dans le <head> global (ViolentMonkey GreasyMonkey/ Mise à jour API risibank 2025)
    const script = document.createElement('script');
    script.src = 'https://risibank.fr/downloads/web-api/risibank.js?v=1.3.2';
    document.head.appendChild(script);
    script.onload = () => risibankReady();

    //API IN HEAD FOR GREASYMONKEY
    const risiOnche = document.createElement('script');
    risiOnche.id = "risi-onche-api";
    risiOnche.textContent = `
    function activateRisibank(container, textArea, overlay, showNSFW) {
        const themeRisi = document.body.matches('.blue, .grey') ? 'dark' : 'light';
        RisiBank.activate({
            type: overlay ? 'overlay' : 'iframe',
            container,
            theme: themeRisi,
            mediaSize: 'sm',
            navbarSize: 'sm',
            defaultTab: 'fav',
            showNSFW: showNSFW,
            allowUsernameSelection: true,
            onSelectMedia: (e) => {
                RisiBank.Actions.addSourceImageLink(textArea)(e);
                textArea?.dispatchEvent(new Event('change', { bubbles: true }));
            }
        });
    }
    window.activateRisibank = activateRisibank;`;
    document.head.appendChild(risiOnche);


    const activateRisibankSafe = typeof activateRisibank !== "undefined" ? activateRisibank : unsafeWindow.activateRisibank;

    //CSS
    const CSS = document.createElement('style');
    CSS.id = "risi-onche-css";
    CSS.textContent = `
    #risi-onche iframe {
        height: 10rem !important
    }

    /*BTN RISI CSS MP*/
    .chat #risibank-toggle {
        cursor: pointer;
        padding: 10px 20px 7px;
    }

    /*MOBILE BTN ENVOYER CSS*/
    @media (max-width: 415px) {
        .forum .composer__send {
            padding: 0.4rem 0.5rem !important;
            font-size: 0.85em !important;
            margin: auto;
            border-radius : 6px !important;
            transition : none;
        }
        .forum .composer__send .mdi {
            font-size: 1rem;
        }
        .composer__toolbar .composer__send .mdi {
            display : none !important; /*icone ➣ masquée sur mobile car trop petit*/
        }
    }`;
    document.head.appendChild(CSS);


    function risibankReady() {
        //Create Node RisiOnche
        function remountRisiOnche() {
            document.getElementById('risi-onche')?.remove();
            if (overlay || !risiOpen) return;

            if (!placeRisiAfter) return;
            placeRisiAfter?.insertAdjacentHTML('afterend', '<div id="risi-onche" style="max-height: 30rem"></div>');

            activateRisibankSafe(document.getElementById('risi-onche'), textArea, overlay, showNSFW);
        }
        remountRisiOnche();

        // HTML Btn Risibank
        placeBtnAfter?.insertAdjacentHTML('afterend', `
            <div id="risibank-toggle" class="item" title="Ouvrir / Fermer RisiBank">
               <img src="https://risibank.fr/logo.png" width="22" style="filter: hue-rotate(250deg)">
            </div>
        `);
        // Listeners JS Bloc
        document.getElementById('risibank-toggle')?.addEventListener('click', () => {
            //Bouton RisiOnche
            if (overlay) {
                activateRisibankSafe(document.body, textArea, overlay, showNSFW);
            } else {
                risiOpen = !risiOpen; // Revert
                localStorage.setItem('risi-toggle-open', risiOpen);

                remountRisiOnche();
            }
        });


        // Bloc Options dans la sidebar
        placeChangeModAfter?.insertAdjacentHTML('afterend', `
            <div class="bloc border red">
                <div class="title">🔧 Risibank</div>
                <div class="content centered">
                    <button id="swtich-mode" class="button bordered secondary" type="button">Mode intégré : ${!overlay ? 'On' : 'Off'}</button>
                    <button id="open-risibank-url" class="button bordered secondary" type="button" title="Lors d'un clic sur un sticker noelshack, rediriger vers RisiBank si le sticker existe plutôt que noelshack">Rediriger vers RisiBank : ${risiApi ? 'On' : 'Off'}</button>
                </div>
            </div>
        `);
        // Listeners Bloc Options
        document.getElementById('swtich-mode')?.addEventListener('click', function() {
            overlay = !overlay; // Revert
            localStorage.setItem('risi-overlay', overlay);
            this.textContent = `Mode intégré : ${!overlay ? 'On' : 'Off'}`;

            remountRisiOnche();
        });
        document.getElementById('open-risibank-url')?.addEventListener('click', function() {
            risiApi = !risiApi; // Revert
            localStorage.setItem('risi-api', risiApi);
            this.textContent = `Rediriger vers RisiBank : ${risiApi ? 'On' : 'Off'}`;

        });
    }

    // Remplace les liens risibank par des images inline
    document.querySelectorAll('a.link[href^="https://risibank.fr/cache/medias/"]:not([data-processed])').forEach(link => {
        link.outerHTML = `
            <a href="${link.href}" class="link" data-processed target="_blank" rel="nofollow">
                <div class="smiley"><img src="${link.href}"></div>
            </a>
        `;
    });

    //ByPass 403 or open api
    document.body.addEventListener('click', (e) => {
        const linkShack = e.target.closest('a.link[href^="https://image.noelshack.com/"]');
        if (linkShack) {
            e.preventDefault();
            if (risiApi) window.open('https://risibank.fr/api/v1/medias/by-source?type=jvc&url=' + linkShack.href, '_blank'); //Site
            else window.open(linkShack.href, '_blank', 'noopener,noreferrer'); //NoReferrer
        }
    });

}