User:Fred Gandt/globalWatchlist.js

( function {	function FetchProjects {		var req;		if ( window.XMLHttpRequest ) {			req = new XMLHttpRequest;		} else {			req = new ActiveXObject( "Microsoft.XMLHTTP" );		}		req.onreadystatechange = function {			if ( ( req.readyState == 4 ) && ( req.status == 200 ) ) {				var str = req.responseText,					pos = str.indexOf( "wikitable sortable mw-centralauth-wikislist" ) + 43;				str = str.substr( pos );				pos = str.indexOf( " " );				str = str.substr( pos );				pos = str.indexOf( " " );				str = str.substr( 0, pos );				MakeList( str );			}		}		req.open( "GET", "/wiki/Special:CentralAuth/" + mw.config.get( "wgUserName" ), true );		req.send;	}	function MakeList( s ) {		var link,			pos = 0,			project,			ul = document.getElementById( "fg-global-watchlists" );		while ( ( pos = s.indexOf( " " ) ) != -1 ) {			s = s.substr( pos + 4 );			pos = s.indexOf( "href=" ) + 6;			s = s.substr( pos ); pos = s.indexOf( "\" " );			link = s.substr( 0, pos );			pos = link.lastIndexOf( "/" );			link = link.substr( 0, pos );			pos = link.lastIndexOf( "." );			project = link.substr( 2, ( pos -2 ) );			ul.innerHTML += "" + project + "";		}	}	function Init {		if ( mw.config.get( "wgPageName" ) == "Special:Watchlist" ) {			var left_nav_panel = document.getElementById( "mw-panel" ),				nav_list_wrap = document.createElement( "div" );			nav_list_wrap.setAttribute( "class", "portal expanded" );			left_nav_panel.appendChild( nav_list_wrap );			nav_list_wrap.innerHTML = " Watchlists  ";			FetchProjects;		}	}	jQuery( document ).ready( Init ); } );