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 17:00, 1 May 2013 (for future reference). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
/*
FOR FUTURE REFERENCE, SHOULD THE WMF EVER DECIDE TO REMOVE THE ORANGE BAR FOR REAL:
.usermessage {
background-color: #ffce7b;
border: 1px solid #ffa500;
color: black;
font-weight: bold;
margin: 2em 0 1em;
padding: .5em 1em;
vertical-align: middle;
}

These are the CSS styles applied to the OBoD to make it look the way it is.

*/


function orangeBarOfDoom()
{
	var cookieResult = $.cookie("lastTalkpageView");
	if(cookieResult != null)
	{
		var escapedUsername = wgUserName.replace(/ /g, "_");
		if(wgPageName == "User_talk:"+ escapedUsername)
		{
			var d = new Date();
			$.cookie("lastTalkpageView", d.getTime(), {expires:365, path: '/'});
		}
		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(results.query.pages)[0];
				var lastUser = results.query.pages[index].revisions[0].user
				var lastTimestamp = Date.parse(results.query.pages[index].revisions[0].timestamp);
				if( cookieResult < 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();
		$.cookie("lastTalkpageView", d.getTime(), {expires:365, path: '/'});
	}
}
$(document).ready(orangeBarOfDoom);