YouTube Video Random Seek

Seek randomly in a YouTube video

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

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

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                YouTube Video Random Seek
// @version             0.2.9
// @author              workingProgress8
// @description         Seek randomly in a YouTube video
// @namespace           youtubeRandomSeeker
// @match             https://*.youtube.com/watch*
// @match             http://*.youtube.com/watch*
// @exclude             https://*.youtube.com/results?search_query*
// @exclude             http://*.youtube.com/results?search_query*
// @run-at              document-end
// @license             MIT
// ==/UserScript==
 
function addRListener()
{
    if (document.querySelector('video').src=='')
    {
        return;
    }
    document.addEventListener('keypress', function rForRandom(event)
                              {
                                  if (event.key == 'r' && event.target != document.querySelector('input#search.ytd-searchbox'))
                                  {
                                      let max = document.querySelector('video').duration;
                                      if (isNaN(max))
                                      {
                                          return;
                                      }
                                      document.querySelector('video').currentTime = Math.random() * (max -1);
                                  }
                              });
}

addRListener();