User:Lupin/watchlistDumper.js
//
// Dump your watchlist into an edit page
// Installation: add
//
// {{subst:js|User:Lupin/watchlistDumper.js}}
//
// to your user javascript file.
// Usage: type
//
// javascript:watchlistDumper.dump()
//
// into the address bar of your browser when editing the relevant page.
//
// Alternatively, bookmark this as a url for easy access,
// or add a link to your toolbox.
watchlistDumper = {
download : function(bundle) {
var x = window.XMLHttpRequest ? new XMLHttpRequest()
: window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
: false;
if (x) {
x.onreadystatechange=function() {x.readyState==4 && watchlistDumper.downloadComplete(x,bundle);};
x.open("GET",bundle.url,true);
x.send(null);
}
},
downloadComplete : function(x,bundle) {
x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
|| ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
},
processWatchlist : function(req, bundle) {
try { var editbox=document.editform.wpTextbox1; } catch (err) {
alert('Please edit the page where you want to dump your watchlist'); return;
}
var watchlist=[];
var lines=req.responseText.split('\n');
for (var i=0; i
if (lines[i].indexOf('
if (/^(Category|Image)/.test(article)) { article = ':' + article; }
watchlist.push(article);
}
}
if (watchlist.length > 0) {
editbox.value += '*' + watchlist.join('\n*') + '\n';
}
alert( 'Dumped ' + watchlist.length + ' watched pages' );
},
dump : function() {
watchlistDumper.download({
url: 'http://en.wikipedia.org/wiki/Special:Watchlist/edit',
onSuccess: watchlistDumper.processWatchlist,
onFailure: function(){alert('Watchlist download failed for some reason; please try again.');}
});
}
}
//