Random Episode Selector

Select random episode from Wikipedia list article.

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     Random Episode Selector
// @grant    none
// @namespace   com.cool.pax
// @include     https://en.wikipedia.org/wiki/List_of_*
// @version     1
// @description:en  Select random episode from Wikipedia list article.
// @description Select random episode from Wikipedia list article.
// ==/UserScript==

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

var x = Array.from( document.querySelectorAll( ".vevent" ) );

var i = getRandomInt( x.length );

var h = x[i].querySelector( "th" );
var s = x[i].querySelector( ".summary" );

var ex = x[i].nextElementSibling;

if ( ex.className == "vevent" )
  ex = "";
else
  ex = ex.textContent;

alert( h.id + "\n" + s.textContent + "\n\n" + ex );