Random Episode Selector

Select random episode from Wikipedia list article.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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