Random Video For Youtube

Play Random Video in Youtube

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Random Video For Youtube
// @name:fr      Video Aléatoire Pour Youtube
// @name:en      Random Video For Youtube Video
// @namespace    http://tampermonkey.net/
// @author        TrouveMe
// @version      0.3.1
// @contributionURL https://www.paypal.com/donate/?cmd=_donations&[email protected]&item_name=Greasy+Fork+donation
// @description     Play Random Video in Youtube
// @description:fr  Lance Video Aléatoire sur Youtube
// @description:en  Play Random Video in Youtube Video
// @match        https://www.youtube.com/*
// @match        https://www.youtu.be/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function clickRandomNthItem(selector) {
        let items = document.querySelectorAll(selector);
        let randomIndex = getRandomInt(0, items.length - 1);
        if (items[randomIndex]) {
            items[randomIndex].click();
        }
    }

    function createButton() {
        const button = document.createElement('button');
        //button.innerText = "Lancer musique aléatoire";
        const imgbtn = new Image(32, 32)
        imgbtn.src = "https://www.svgrepo.com/show/458362/sort-random.svg"
        imgbtn.alt = "Picture For Random Button / Image Pour le Bouton Aléatoire"
        button.appendChild(imgbtn)
        button.style.position = 'fixed';
        button.style.top = '90%';
        button.style.right = '1.5%';
        button.style.zIndex = 1000;
        button.style.padding = '10px';
        button.style.backgroundColor = '#1DB954';
        button.style.color = '#FFFFFF';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.addEventListener('mouseover', () => { button.style.backgroundColor = '#1a8a41'})
        button.addEventListener('mouseout', () => { button.style.backgroundColor = '#1DB954'})
        button.addEventListener('mousedown', () => { button.style.backgroundColor = '#166e35'})
        button.addEventListener('mouseup', () => { button.style.backgroundColor = '#1DB954'})



        button.addEventListener('click', function() {
            clickRandomNthItem('a#thumbnail.yt-simple-endpoint.inline-block.style-scope.ytd-thumbnail');
            button.style.top = '85%';

        });
        document.body.appendChild(button);
    }

    // Attendre que la page soit entièrement chargée avant de créer le bouton
    window.addEventListener('load', createButton);

})();