MediaWiki:ScrollingList.js

/* ======== Scrolling list ================================ author:    Petr Kajzar User:Slepi date:      05/2009 license:   only for Wikilectures lf1.cuni.cz   desc.:      This script connects server and gets some response. One of its functions is to display list of wanted articles and scroll it              on the page (element id "wanted-articles"). ======================================================== */

// connect server var xmlhttp;

// FUNCTION READING SERVER RESPONSE // source: www.w3schools.com, editted // url = url of page to read // todo = function to be done after connecting function loadXMLDoc(url, todo) { xmlhttp=null;

if (window.XMLHttpRequest) { // code for new browsers xmlhttp=new XMLHttpRequest; } else if (window.ActiveXObject) { // code for IE5 and IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

if (xmlhttp!=null) { eval("xmlhttp.onreadystatechange=" + todo +";"); xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { window.alert("Error: Your browser does not support XMLHTTP. Some parts of this page may not be displayed properly."); } }

function wantedArticles { if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = OK

// process the response var beginParse = ""; var endParse = ""; var htmlRes = xmlhttp.responseText; var start = htmlRes.indexOf(beginParse); var end = htmlRes.indexOf(endParse);

var output = htmlRes.substring(start+30, end-6); output = output.replace(/<\/li>\n/g, " • "); output = output.replace(//g, ""); output = output.replace(/<\/li>/g, ""); output = output.replace(/\(\)/g, ""); if (navigator.appName == "Opera") output = output.replace(/\/a>\)/g, ""); // Opera fix     output = '' + output + ' ';      document.getElementById("wanted-articles").innerHTML = output;    } else {      // window.alert("Error: An error occured when connecting the server. Some pages may not be displayed properly.");    }  } }

// start it! addOnloadHook(function{if (document.getElementById("wanted-articles") == undefined) return; loadXMLDoc(wgServer + wgScript + "/Special:Wantedpages?limit=20&offset=0", "wantedArticles");});