Redgifs Embed Tweaks

tweaks redgifs embed/iframe video

Από την 18/11/2023. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        Redgifs Embed Tweaks
// @namespace   https://greasyfork.org/pt-BR/users/821661
// @match       https://www.redgifs.com/ifr/*
// @grant       GM_registerMenuCommand
// @grant       GM_setValue
// @grant       GM_getValue
// @version     0.1
// @author      hdyzen
// @description tweaks redgifs embed/iframe video
// @license     MIT
// ==/UserScript==

(function () {
    'use strict';
    // Autoplay state
    const autoplay = GM_getValue('autoplay', true);
    // Open state
    const openLink = GM_getValue('openlink', false);
    // Autoplay toggle
    function autoplayToggle() {
        GM_setValue('autoplay', !autoplay);
    }
    // Open link when click on video
    function openLinkToggle() {
        GM_setValue('openlink', !openLink);
    }
    // Prevent opening video link
    if (!openLink) {
        document.addEventListener('click', (e) => {
            if (!e.target.closest('.videoLink')) return;
            e.preventDefault();
        });
    }
    // Menu commands
    (function menuCommands() {
        // Autoplay
        const commandAutoplay = GM_registerMenuCommand('Autoplay: ON', autoplayToggle, {
            title: 'Click for toggle',
        });
        if (!autoplay) {
            GM_registerMenuCommand('Autoplay: OFF', autoplayToggle, {
                title: 'Click for toggle',
                id: commandAutoplay,
            });
        }
        // Open link
        const commandLink = GM_registerMenuCommand('Open link when click: OFF', openLinkToggle, {
            title: 'Click for toggle',
        });
        if (openLink) {
            GM_registerMenuCommand('Open link when click: ON', openLinkToggle, {
                title: 'Click for toggle',
                id: commandLink,
            });
        }
    })();
    // Mutation observer for pause video
    if (!autoplay) {
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList' && mutation.target.classList.contains('routeWrapper')) {
                    mutation.addedNodes.forEach((node) => {
                        const video = node.querySelector('.videoLink video');
                        if (video) {
                            video.removeAttribute('autoplay');
                            observer.disconnect();
                        }
                    });
                }
            });
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    }
})();