Utilisateur:Stef48/randomPage.js
Apparence
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.function randomPage(){
setTimeout('window.location.replace("http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Page_au_hasard")',20000);
document.cookie = 'autoRandom=true;expires=' + new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365).toGMTString();
}
function stopRandomPage(){
document.cookie = 'autoRandom=true;expires=' + new Date().toGMTString() + ";" + ";";
}
function RandomNavig()
{
var a = document.getElementById("p-navigation");
if (a)
{
b = a.getElementsByTagName("ul");
if(b.length > 0)
{
b[0].innerHTML = b[0].innerHTML
+ '<br>'
+ '<li><span id="random_navigation" title="Activer le random">'
+ '<a href="javascript:randomPage()">Activer</a> / <a href="javascript:stopRandomPage()">Désactiver</a>'
+ '</span></li>'
}
}
try
{
var autoRandom = document.cookie.split('autoRandom=')[1].split('.')[0];
} catch (error) {
var autoRandom = false;
}
if (autoRandom)
{
randomPage();
}
}
$(RandomNavig);