vrbdl

UserScript version of this extension https://github.com/dvick/vrbdownres

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        vrbdl
// @namespace   Violentmonkey Scripts
// @match       *://vrbangers.com/video/*
// @grant       none
// @version     1.0
// @author      -
// @run-at       document-end
// @description UserScript version of this extension https://github.com/dvick/vrbdownres
// ==/UserScript==
(function() {
    'use strict';

    function doInjectButton() {
        if (document.querySelector('.video-download-button__activator')) {
            return;
        }
        const button = document.createElement('button');
        button.className = 'video-download-button__activator app-link app-link__button app-link__button--block --single-video';
        button.setAttribute('data-v-d6d564ee', '');
        button.innerText = 'Download';
        const appMenuActivator = document.querySelector('.single-video-info__download-button > .app-menu__activator');
        if (appMenuActivator) {
            appMenuActivator.appendChild(button);
        }
    }

    function injectButton() {
        const preview = document.querySelector('.single-video-poster__preview');

        if (preview && preview.classList.contains('--loading')) {
            const observer = new MutationObserver((mutations, observer) => {
                if (!preview.classList.contains('--loading')) {
                    observer.disconnect();
                    doInjectButton();
                }
            });
            observer.observe(preview, {
                attributes: true,
                attributeFilter: ['class']
            });
        } else {
            doInjectButton();
        }
    }

    function observePage() {
        const target = document.querySelector('main.app-content') || document.getElementById('__nuxt');
        if (target) {
            const observer = new MutationObserver((mutations, observer) => {
                for (const mutation of mutations) {
                    for (const node of mutation.addedNodes) {
                        if (node.id === '__layout' || node.classList.contains('single-video-info__download-button')) {
                            observer.disconnect();
                            injectButton();
                            return;
                        }
                    }
                }
            });
            observer.observe(target, { childList: true });
        }
    }

    // Initial button injection on page load
    if (window.location.pathname.startsWith('/video/')) {
        injectButton();
        observePage();
    }

    // Observe history changes and re-inject button if necessary
    const historyPushState = history.pushState;
    history.pushState = function() {
        historyPushState.apply(this, arguments);
        if (window.location.pathname.startsWith('/video/')) {
            injectButton();
            observePage();
        }
    };
})();