User:Svick/transcludeWatchlist.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');

var timer = null; var nextReload = null; function loadWatchlist { var watchlistElem = document.getElementById('transclude-watchlist'); if (watchlistElem != null) {   if (typeof transcludeWatchlistLimit == 'undefined') transcludeWatchlistLimit = 100; watchlistElem.innerHTML = ' Loading … '; var luasog = new Luasog("http://en.wikipedia.org/w/api.php"); var requestParams = {action:"query", list: "watchlist", wlexcludeuser: mw.config.get('wgUserName'), wlprop: "ids|title|timestamp|user|parsedcomment|flags", wllimit: transcludeWatchlistLimit}; var callback = function(data) { var list = document.createElement('ul');

var target = (typeof transcludeWatchlistNewWindow != 'undefined' && transcludeWatchlistNewWindow) ? 'target="_blank"' : '';

for (var i = 0; i < data.query.watchlist.length; i++) { var edit = data.query.watchlist[i]; list.innerHTML += '' + '(diff) ' +  + (edit.minor == undefined ?  : 'm') + (edit.bot == undefined ? '' : 'b') + ' ' + '' + edit.title + ' ' + edit.timestamp + ' ' + '' + edit.user + ' ' + '(' + edit.parsedcomment + ')' + ''; }

var result = document.createElement('div'); result.innerHTML += ' '; result.appendChild(list);

var watchlistElem = document.getElementById('transclude-watchlist'); watchlistElem.replaceChild(result, watchlistElem.firstChild);

if (typeof transcludeWatchlistReloadTime != 'undefined' && timer == null) { refresh; timer = setInterval(refresh, 1000); // 1s }   }    luasog.request(requestParams, callback); } }

function refresh { if (nextReload == null) { nextReload = new Date; nextReload.setTime(nextReload.getTime + transcludeWatchlistReloadTime * 1000); }

var remaining = Math.floor((nextReload - new Date) / 1000);

if (remaining <= 0) { clearInterval(timer); timer = null; nextReload = null; loadWatchlist; } else { var timeToReloadElem = document.getElementById('time-to-reload'); timeToReloadElem.innerHTML = 'Time to reload: ' + remaining + ' s.'; } }

$(loadWatchlist);