Switch JavaDoc version

Switch between JavaDoc versions since Java 7

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

You will need to install an extension such as Tampermonkey to install this 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 Switch JavaDoc version
// @namespace https://franklinyu.github.io
// @version 0.1
// @description Switch between JavaDoc versions since Java 7
// @match https://docs.oracle.com/javase/*/docs/api/*
// ==/UserScript==

const match = location.pathname.match('/javase/(\\d+)/docs/api/(.*)')

const select = document.createElement('select')
select.style.float = 'right'
select.addEventListener('change', e => {
	location = `/javase/${e.target.value}/docs/api/${match[2]}`
})

for (const version of ['7', '8', '9', '10']) {
	const option = document.createElement('option')
	option.innerText = version
	if (version === match[1])
		option.selected = true
	select.append(option)
}

const navbar = document.getElementsByClassName('topNav')[0]
navbar && navbar.append(select)