Add Delight-VR Video and Script

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

Versione datata 13/09/2025. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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