mic_none

User:Flaming/random link.js Source: en.wikipedia.org/wiki/User:Flaming/random_link.js

url = 'http://en.wikipedia.org/w/api.php?action=query&format=json&prop=links&callback=onCallback&titles='
url2 = 'http://en.wikipedia.orghttps://demo.azizisearch.com/lite/wikipedia/page/'
function randItem (array) {
    return array[Math.floor(Math.random() * array.length)]
    };
function load_links (title) {
    script = document.createElement("script");
    script.setAttribute('src',url + title);
    script.setAttribute('lang','javascript');
    document.body.appendChild(script);
    };
function onCallback (data) {
    k = data['query']['pages'];
    for (x in k) {
        links = k[x]['links'];
        };
    the_link = randItem(links);
    document.location = url2 + the_link['title'];
    };
$(function(){
    addPortletLink ('p-cactions','javascript:load_links(wgPageName)','RL','pt-rl','Random link','',false);
    });