Jump to content

User:Writ Keeper/Scripts/orangeBar.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 14:54, 1 May 2013 (new script). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function orangeBarOfDoom()
{
var regexResult = /lastTalkpageVisit=(\d+);/.exec(document.cookie);
if(regexResult != null && regexResult.length > 1)
{
	var escapedUsername = wgUserName.replace(/ /g, "_");
	if(wgPageName = "User_talk:"+ escapedUsername)
	{
		var d = new Date();
		document.cookie = "lastTalkpageVisit=" + d.getTime();
	}
	else
	{
		var data = {action: "query", prop:"revisions", format:"json", rvprop:"timestamp|user", rvlimit:"1", rvdir:"older", rvexcludeuser: wgUserName, titles: "User talk:"+wgUserName};
		$.post("/w/api.php", data, function(results)
		{
			var index = Object.keys(extData.query.pages)[0];
			var lastUser = results.query.pages[index].revisions[0].user
			var lastTimestamp = Date.parse(results.query.pages[index].revisions[0].timestamp);
			if( regexResult[1] < lastTimestamp )
			{
				var orangeBarDiv = document.createElement("div");
				orangeBarDiv.innerHTML = 'You have <a href="/w/index.php?title=User_talk:'+escapedUsername+'&amp;redirect=no" title="User talk:'+wgUserName+'">new messages.</a> Last edit by '+lastUser+'.';
				orangeBarDiv.className = "usermessage";
				$("#contentSub").after(orangeBarDiv);
			}
		})
	}
}
else
{
	var d = new Date();
	document.cookie = "lastTalkpageVisit=" + d.getTime();
}
}
document.ready(orangeBarOfDoom);