Sleazy Fork is available in English.

Reddit Embed Redgifs Video

embed iframe redgifs in posts for reddit

// ==UserScript==
// @name            Reddit Embed Redgifs Video
// @version         0.3.2
// @description     embed iframe redgifs in posts for reddit
// @namespace       https://greasyfork.org/users/821661
// @match           https://www.reddit.com/*
// @match           https://new.reddit.com/*
// @match           https://www.redgifs.com/ifr/*
// @grant           GM_addStyle
// @license         MIT
// @require         https://code.jquery.com/jquery-3.7.1.min.js
// @author          hdyzen
// ==/UserScript==
(function () {
    'use strict';

    // Domain
    const domain = location.hostname;

    // Create video
    function createIframe(href) {
        const iframe = document.createElement('iframe');
        iframe.src = href.replace('watch', 'ifr');
        return iframe;
    }

    // Detect links
    function detectLinks() {
        const links = document.querySelectorAll(':is(._3Qkp11fjcAw9I9wtLo8frE, ._2dkUkgRYbhbpU_2O2Wc5am) :is(._13svhQIUZqD9PVzFcLwOKT, .a6Bzb7gqvN3mqBOAEyFIv)[href*="redgifs.com/"]:not([video], [href$=".jpg"], [href$=".png"])');
        links.forEach((link) => {
            const parent = link.parentElement;
            link.setAttribute('video', '');
            parent.insertAdjacentElement('afterend', createIframe(link.href));
        });
    }
    if (domain === 'www.reddit.com' || domain === 'new.reddit.com') {
        // Interval detect links
        let interval = setInterval(detectLinks, 500);

        // GM Style reddit
        GM_addStyle(`
            iframe[src*="redgifs.com/ifr"] {
                min-height: 512px;
                width: 100%;
                max-height: 70vh;
                max-width: 100%;
            }
            ._17nmfaMf1Rq20sVfEmle0O:has(._2MkcR85HDnYngvlVW2gMMa > a[href*="redgifs.com/"]) {
                display: none !important;
            }
            ._32pB7ODBwG3OSx1u_17g58 iframe[src*="redgifs.com/ifr"] {
                min-height: 512px;
                max-height: 70vh;
            }
            ._19FzInkloQSdrf0rh3Omen iframe[src*="redgifs.com/ifr"] {
                margin-top: 10px;
                min-height: 512px;
                max-height: 70vh;
            }
            ._19FzInkloQSdrf0rh3Omen:has(iframe[src*="redgifs.com/ifr"]) {
                flex-direction: column !important;
            }
            ._19FzInkloQSdrf0rh3Omen:has(iframe[src*="redgifs.com/ifr"]) .Gk-MlLujgqsaX1n-sGa_O {
                display: none !important;
            }

        `);
    }
    if (domain === 'www.redgifs.com') {
        // GM Style redgifs
        GM_addStyle(`
            .logo, .userInfo {
                display: none !important;
            }
            body, .App, .embeddedPlayer{
                background-color: #000 !important;
            }
        `);
    }
})();