RisiOnche

Risibank sur onche.org (Fix)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

Advertisement:

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.

(I already have a user style manager, let me install it!)

Advertisement:

// ==UserScript==
// @name         RisiOnche
// @namespace    RisiOnche
// @version      0.73.1
// @description  Risibank sur onche.org (Fix)
// @author       RisiOnche, Catalyst
// @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        none
// ==/UserScript==



(async () => {

    //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;

    //  AWAIT DOM TEXT PROMISE // POLL DOM IF IN JS (Retry 6 times)
    const textAreaSel = '.Form__input, #post textarea';
    let tentatives = 0;
    await new Promise(resolve => {
        (function check() {
            if (document.querySelector(textAreaSel)) return resolve();
            else if (++tentatives < 6) setTimeout(check, 300);
        })();
    });

    //GLOBAL_NODE
    let placeChangeModAfter;
    let placeBtnAfter;
    let placeRisiAfter;
    let textArea = document.querySelector(textAreaSel);
    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');
    } 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');
    }

    // LAPI a été mal compilée en (MAJ 2025) : })(this.window = this.window || {});
    // INJECTION OBLIGATOIRE DE L'API DANS LE <HEAD> GLOBAL pour palier au soucis.
    // Sinon incompatibilité avec IOS / GREASYMONKEY ET VIOLENT MONKEY.
    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();

    // CALL API IN HEAD FOR GREASYMONKEY
    const risiOnche = document.createElement('script');
    risiOnche.id = "risi-onche-bridge-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);

    // Appel direct de la fonction ou via unsafeWindow.fonction (TamperMonkey VS GreasyMonkey)
    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
    }

    /* RisiMobile Options */
    @media (max-width: 880px) {
        #right .bloc.border.red {
            order: -1;
        }
    }

    /*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'}`;

        });
    }

    // AJOUT ALT sur imgShack POUR COPIER COLLER
    document.querySelectorAll('img[src^="https://image.noelshack.com/"]:not([data-processed-risionche])').forEach(imgShack => {
        imgShack.alt = imgShack.src;
        imgShack.dataset.processedRisionche = '';
    });

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

    //Global Listener
    document.body.addEventListener('click', async (e) => {
       //Open Api or ByPass 403
        const linkShack = e.target.closest('a.link[href^="https://image.noelshack.com/"]');
        if (linkShack) {
            if (risiApi) {
                e.preventDefault();
                window.open('https://risibank.fr/api/v1/medias/by-source?type=jvc&url=' + linkShack.href, '_blank');
            } else if (!linkShack.matches('[rel~="noreferrer"]')) {
                e.preventDefault();
                window.open(linkShack.href, '_blank', 'noopener,noreferrer'); //FallBack NoReferrer If no balise REL
            }
        }
        //Pannel open IMG HD
        const linkOnche = e.target.closest('.logged .sticker > img[src^="https://cloud.onche.org/"]');
        if (linkOnche) {

            await new Promise(r => setTimeout(r, 100));

            const contextMenu = document.getElementById('context');
            const btnFullHDHere = document.getElementById('show-onche-hd');
            if (!contextMenu || btnFullHDHere) return;

            contextMenu.insertAdjacentHTML('beforeend', `
                <div class="item has-icon" id="show-onche-hd">
                    <span class="context-label">Voir en HD</span><span class="mdi mdi-printer-pos"></span>
                </div>`);
            document.getElementById('show-onche-hd').addEventListener('click', () => {
                window.open(linkOnche.src.replace('/128', ''), '_blank'); //Hd
            });
        }
    }, true);

})();