Add Delight-VR Video and Script

Adds dl8-video element and Delight-VR script to the page

Verze ze dne 13. 09. 2025. Zobrazit nejnovější verzi.

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         Add Delight-VR Video and Script
// @version      1.2
// @description  Adds dl8-video element and Delight-VR script to the page
// @author       Guzmazow
// @match        *://*/*
// @grant        none
// @license      MIT
// @namespace https://greasyfork.org/users/1514505
// ==/UserScript==


(function() {
    'use strict';

    // Inject button at the start of body
    function injectButton() {
        var btn = document.createElement('button');
        btn.textContent = 'Add Delight-VR Video';
        btn.style.margin = '16px';
        btn.id = 'delight-vr-btn';
        document.body.insertBefore(btn, document.body.firstChild);
        btn.addEventListener('click', runScriptAction);
    }

    // Script action to add video and script
    function runScriptAction() {
        // Prevent multiple insertions
        if (document.getElementById('dl8-video-injected')) return;

        // Find the currently playing <video> tag, or fallback to the first
        var videos = document.querySelectorAll('video');
        var videoTag = null;
        for (var i = 0; i < videos.length; i++) {
            if (!videos[i].paused && videos[i].currentTime > 0) {
                videoTag = videos[i];
                break;
            }
        }
        if (!videoTag && videos.length > 0) {
            videoTag = videos[0];
        }
        var videoSrc = '';
        if (videoTag) {
            if (videoTag.src) {
                videoSrc = videoTag.src;
            } else {
                var videoSource = videoTag.querySelector('source');
                if (videoSource && videoSource.src) {
                    videoSrc = videoSource.src;
                }
            }
        }
        if (!videoSrc) {
            alert('No <video> tag with a valid src found!');
            return;
        }

    // Create wrapper div with selected style
    var wrapper = document.createElement('div');
    wrapper.setAttribute('style', 'width: 500px; height: 300px; position: fixed; top: 100px; left: 0; z-index: 9999; background: #000;');
    wrapper.id = 'dl8-video-wrapper';

    var dl8Video = document.createElement('dl8-video');
    dl8Video.setAttribute('title', 'Example Video');
    dl8Video.setAttribute('format', 'STEREO_180_LR');
    dl8Video.setAttribute('display-mode', 'fullscreen');
    dl8Video.setAttribute('loop', '');
    dl8Video.id = 'dl8-video-injected';

    var source = document.createElement('source');
    source.src = videoSrc;
    source.type = "video/mp4";
    dl8Video.appendChild(source);

    wrapper.appendChild(dl8Video);
    document.body.appendChild(wrapper);

        if (!document.querySelector('script[src*="delight-vr.com"]')) {
            var script = document.createElement('script');
            script.src = "https://cdn.delight-vr.com/latest/dl8-dac884cdc04ea921934408999668b16b33b8334a.js";
            script.async = true;
            document.head.appendChild(script);
        }
    }

    // Wait for DOM ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', injectButton);
    } else {
        injectButton();
    }
})();