RisiOnche

Risibank sur onche.org (Fix)

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==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
        }
    });

}