User:Svick/reverseWatchlist.js

importScript('User:Luasóg bot/framework.js');

if (typeof jQuery == 'undefined') mw.loader.load('//bits.wikimedia.org/skins-1.5/common/jquery.min.js');

addOnloadHook(function { if (mw.config.get('wgPageName') == 'Wikipedia:Reverse_Watchlist')  {    if (typeof reverseWatchlistLimit == 'undefined')      reverseWatchlistLimit = 365;

var startDate = new Date - reverseWatchlistLimit * 24 * 60 * 60 * 1000;

var hideMe = document.getElementById('hide-me'); hideMe.parentNode.removeChild(hideMe);

document.getElementById('bodyContent').innerHTML += ' Loading ';

var luasog = new Luasog("http://en.wikipedia.org/w/api.php");

var requestParams = {action:"query", generator: "watchlistraw", prop: "info|revisions", rvprop: "timestamp", gwrlimit: "max", gwrnamespace: "0"}; var pages = new Array;

var callback = function(data) { document.getElementById('loading').innerHTML += '.';

for (var pageId in data.query.pages) { var page = data.query.pages[pageId]; if (page.missing == undefined && page.redirect == undefined) { var date = new Date(page.revisions[0].timestamp); if (date < startDate) pages.push({title: page.title, timestamp: date}); }     }

if (data['query-continue'] != undefined) { requestParams.gwrcontinue = data['query-continue'].watchlistraw.gwrcontinue; luasog.request(requestParams, callback); } else { pages.sort(function(a, b) { return a.timestamp - b.timestamp; });

var hideMe = document.getElementById('loading'); hideMe.parentNode.removeChild(hideMe); var result = document.createElement("ol"); result.id = "reverse-watchlist";

for (var i = 0; i < pages.length; i++) { var page = pages[i]; var date = page.timestamp.toDateString; result.innerHTML += '' + date.substring(date.indexOf(' ') + 1) + ' ' + page.title + ''; }       document.getElementById('bodyContent').appendChild(result); }   }

luasog.request(requestParams, callback); } });