MediaWiki:FullInterwikiMap.js

(function {

console.log("Checking page name."); if (location.pathname == "/wiki/MediaWiki:Interwiki_map/full") { console.log("We are viewing MediaWiki:Interwiki_map/full"); var request = { action: "query", meta: "siteinfo", siprop: "interwikimap" };   var params = location.search.substr(1).split(/[&=]/); var param_idx = params.indexOf("sifilteriw"); if ((param_idx != -1) && (param_idx < (params.length-1)) && ((params[param_idx+1] == "local") || (params[param_idx+1] == "!local"))) { request.sifilteriw = params[param_idx+1]; }   mw.loader.using("mediawiki.api").then(function  {        return new mw.Api.get(request);    }).then(extractIWData).then(replacePageContent); }

function extractIWData(reply) { console.log("A reply from the API has been recieved. Attempting to extract data."); var data = { prefix: [], url: [], count: 0 };   var iwmap = reply.query.interwikimap; for (i = 0; i < iwmap.length; i++) { data.prefix.push(iwmap[i].prefix); data.url.push(iwmap[i].url); }   data.count = iwmap.length; return data; }

function replacePageContent(data) { console.log("Data has been extracted from the API reply. Attempting to add to page."); var main_content = document.getElementById("mw-content-text"); var article_placeholder = $("#mw-content-text > .noarticletext")[0]; if (article_placeholder) { console.log("Aritcle placeholder found. Attempting to remove."); main_content.removeChild(article_placeholder); }   console.log("Attempting to generate new content."); var new_content = document.createElement("table"); new_content.className = "wikitable sortable"; new_content.innerHTML = " Prefix  Host Name  URL  "; var new_entry = null; for (i = 0; i < data.count; i++) { console.log("Attempting to generate new entry."); new_entry = document.createElement("tr"); new_entry.innerHTML = " "+data.prefix[i]+" "+getHostName(data.url[i])+"  "+data.url[i]+" "; new_content.appendChild(new_entry); }   console.log("Attempting to insert new content."); main_content.insertBefore(new_content, main_content.firstChild); }

function getHostName(url) { var start = url.indexOf("://")+3; var stop = url.indexOf("/", start); return url.substring(start, stop); }

});