User:Gerbrant/WikiCheck/ui html.css

    var urlAPI = "http://en.wikipedia.org/w/api.php?format=jsonfm&action="; var urlWL  = "http://en.wikipedia.org/wiki/Special:Watchlist/raw"; var urlPrev = "http://en.wikipedia.org/w/index.php?diff=prev&title="; var urlDiff = "http://en.wikipedia.org/w/index.php?title="; var maxRequestLength = 1024; //Safely below limit of webbrowser. var nsTalk = "Talk:"; var nspTalk = " talk";

var AppWindow; var LastChecked; //The date at which the watchlist was last loaded. var CurChecking; //Pages have to have changed more recently than this. This was the previous LastChecked. var Pages;      //Array of pages to be checked against CurChecking. var Ready;      //Array of pages ready to be displayed. var UserName;

var DisplayBatchCount = 16;

function ResponseText(x){ return x.document.getElementsByTagName("PRE")[0].innerText; } function ResponseObject(x){ return eval("(" + ResponseText(x) + ")"); } function Request(u, f) { function DoRequest {		AppWindow.OpenWebPage(u, function(x)		{			try			{				x = ResponseObject(x);			}			catch(e)			{				//Most likely indicates Wikipedia is having maintenance or other transient issues. Wait half a minute and retry.				window.setTimeout(DoRequest, 30000);				return;			}			f(x);		}); }	DoRequest; }

function toURL(p){ return encodeURI(p).replace(/&/g, "%26").replace(/\+/g, "%2B"); }

function ExpandRevs(i) {	var r = document.getElementById("Revs" + i); var e = document.getElementById("Expand" + i); if(r.className == "RevsC"){ r.className = "RevsE"; e.className = "Collapse"; } //e.innerHTML = " - " else                     { r.className = "RevsC"; e.className = "Expand"; } //e.innerHTML = " + " }

function fromISODate(s) {	m = s.match(/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/); if(m) return new Date(Date.UTC(m[1], m[2], [3], m[4], m[5], m[6])); }

var drIndex, drPage, drCount, drCurrentRev; function DisplayRevisionsNext(id) {	var a = document.getElementById("Title" + drIndex) a.href = urlDiff + drPage + "&oldid=" + id + "&diff=" + drCurrentRev; a.className = "Title"; if(++drIndex >= DisplayBatchCount) return; window.setTimeout("DisplayRevisions(" + drIndex + ")", 2000); }

function ParseRevisions(x) {	var r, l, a, u, c, id; var p = x.query.pages; for(var i in p)	{ l = p[i].revisions; if(drCurrentRev == 0) drCurrentRev = l[0].revid; for(var j in l)		{ r = l[j]; u = document.createElement("SPAN"); u.innerText = r.user; u.className = "User"; c = document.createElement("SPAN"); if(r.comment) {				c.innerText = r.comment; c.className = "Comment"; }			else {				c.innerText = LS.NoComment; c.className = "RedComment"; }			a = document.createElement("A"); id = r.revid a.href = urlPrev + drPage + "&oldid=" + id; a.target = "_blank"; a.className = "Rev"; a.appendChild(u); a.appendChild(document.createTextNode(": ")); a.appendChild(c); document.getElementById("Revs" + drIndex).appendChild(a); if(r.user == UserName) return DisplayRevisionsNext(id); if(r.timestamp && fromISODate(r.timestamp) < CurChecking) return DisplayRevisionsNext(id); }	}	p = x["query-continue"]; if(p) {		drCount *= 2; if(drCount > 500) drCount = 500; Request(urlAPI + "query&prop=revisions&rvprop=ids|user|timestamp|comment&titles=" + drPage + "&rvstartid=" + p.revisions.rvstartid + "&rvlimit=" + drCount, ParseRevisions); }	else DisplayRevisionsNext(id); }

function DisplayRevisions(page) {	drIndex = page; drPage = toURL(Ready[page]); drCount = 1; drCurrentRev = 0; Request(urlAPI + "query&prop=revisions&rvprop=ids|user|comment&rvlimit=1&titles=" + drPage, ParseRevisions); }

function DisplayBatchFinal {	var s = []; var m = Ready.length; if(m > DisplayBatchCount) m = DisplayBatchCount; for(var i = 0; i < m; i++) {		s.push(" "); s.push(Ready[i]); s.push(" ");; }	document.getElementById("List").innerHTML = s.join(""); DisplayRevisions(0, 0); }

function DisplayBatchEmpty {	document.getElementById("List").innerText = LS.EmptyBatch; }

var maxCheckPages = 2; var cntCheckPages = 0;

function CheckBatch {	var p, t, l, ep; var urlQuery = "query&prop=info&titles="; var urlLength = urlAPI.length + urlQuery.length - 1; var ub = [urlAPI, urlQuery]; var first = true; while(Pages.length) {			p = Pages.shift; ep = toURL(p); urlLength += ep.length + 1; if(first) first = false; else if(urlLength > maxRequestLength) {			Pages.unshift(p); break; }		else ub.push("|"); ub.push(ep); }	Request(ub.join(""), function(x)	{		var p, ci, t;		var l = x.query.pages;		var r = "";		for(var i in l)		{			p = l[i];			if(!(p.ns & 1))			{				if(p.ns)				{					t = p.title;					ci = t.indexOf(":");					Pages.unshift(t.substr(0, ci) + nspTalk + t.substr(ci));				}				else Pages.unshift(nsTalk + p.title);			}			if(i >= 0)				if(fromISODate(p.touched) >= CurChecking)					Ready.push(p.title);		};		if(Pages.length == 0) DisplayBatchFinal;		else if(Ready.length < DisplayBatchCount)			if(++cntCheckPages < maxCheckPages) CheckBatch;			else DisplayBatchFinal;		else DisplayBatchFinal;	}); }

function DisplayBatch {	if(Ready.length < DisplayBatchCount) if(Pages.length == 0) AppWindow.OpenWebPage(urlWL, function(x)		{			CurChecking = LastChecked;			LastChecked = new Date;			Pages = x.document.getElementById("titles").value.split(/[\n\r]+/);			if(Pages.length == 1 && Pages[0] == "")			{				Pages = [];				DisplayBatchEmpty;			}			else CheckBatch;		}); else CheckBatch; else DisplayBatchFinal; }

function fromRegDate(s) {	m = s.match(/^(\d{1,2})-(\d{1,2})-(.*)$/); if(m) return new Date(m[2] + "-" + m[1] + "-" + m[3]); return new Date(s); }

function fromRegArray(s) {	if(s == "") return []; return decodeURI(s).split("|"); }

function GetUserNameAndDisplayBatch {	Request(urlAPI + "query&meta=userinfo", function(x)	{		UserName = x.query.userinfo.name;		DisplayBatch;	}); }

document.Init = function(w) {	document.getElementById("NextButton").innerText = LS.Next; document.getElementById("FinishButton").innerText = LS.Finish; AppWindow = w;	LastChecked = fromRegDate(w.GetSetting("Status", "LastChecked")); CurChecking = fromRegDate(w.GetSetting("Status", "CurChecking")); Pages = fromRegArray(w.GetSetting("Status", "Pages")); Ready = fromRegArray(w.GetSetting("Status", "Ready")); UserName = decodeURI(w.GetSetting("Config", "UserName")); try{ document.getElementById("Dbg").innerText = LastChecked + "\n" + CurChecking + "\n" + UserName + "\n" + Pages + "\n\n" + Ready; }catch(x){} if(UserName) DisplayBatch; else GetUserNameAndDisplayBatch; }

function toRegDate(d) {	return d.getDate + "-" + (d.getMonth + 1) + "-" + d.getFullYear + " " + d.getHours + ":" + d.getMinutes + ":" + d.getSeconds; }

function toRegArray(a) {	if(a.lenth == 0) return ""; return encodeURI(a.join("|")); }

function Exit {	AppWindow.SaveSetting("Status", "LastChecked", toRegDate(LastChecked)); AppWindow.SaveSetting("Status", "CurChecking", toRegDate(CurChecking)); AppWindow.SaveSetting("Status", "Pages", toRegArray(Pages)); AppWindow.SaveSetting("Status", "Ready", toRegArray(Ready)); AppWindow.SaveSetting("Config", "UserName", encodeURI(UserName)); AppWindow.Quit; }

function Next {	Ready = Ready.slice(DisplayBatchCount); DisplayBatch; }

function Finish {	Ready = Ready.slice(DisplayBatchCount); Exit; }   