User:Fred Gandt/globalWatchlist.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Fred Gandt/globalWatchlist. This user script seems to have an accompanying .css page at User:Fred Gandt/globalWatchlist.css. |
( 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( "<tbody>" );
str = str.substr( pos );
pos = str.indexOf( "</tbody>" );
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( "<tr>" ) ) != -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 += "<li><a href=\"" + link + "/Special:Watchlist\" title=\"" + link + "/Special:Watchlist\">" + project + "</a></li>";
}
}
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 = "<h5>Watchlists</h5><div class=\"body\" style=\"display:block;\"><ul id=\"fg-global-watchlists\"></ul></div>";
FetchProjects();
}
}
jQuery( document ).ready( Init );
} () );