Jump to content

User:Writ Keeper/Scripts/cookielessOrangeBar.js

From Wikipedia, the free encyclopedia
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.
/* OBSOLETE, DO NOT USE: [[User:Writ Keeper/Scripts/orangeBar.js]] is the correct location for this script.


$(document).ready(function()
{
	var numNotes = /\d+/.exec($("#pt-notifications").text())[0];
	
	if(numNotes == null)
	{
		var data = {action:"query", meta:"notifications", format:"json", notprop:"count"};
		$.post("/w/api.php", data, function(result)
		{
			numNotes = result.query.notifications.count;
		});
	}
	if(numNotes > 0)
	{
		var firstData = {action:"query", meta:"notifications", format:"json", notprop:"list",notlimit:numNotes}
		$.post("/w/api.php", firstData, function(firstResponse)
		{
			var keyArray = Object.keys(firstResponse.query.notifications.list)
		
			if((wgCanonicalNamespace + ":" + wgTitle) == ("User_talk:" + wgUserName))
			{
				var idString = "";
				for(i = 0; i < keyArray.length; i++)
				{
					if(firstResponse.query.notifications.list[keyArray[i]].category == "edit-user-talk" && typeof firstResponse.query.notifications.list[keyArray[i]].read == "undefined")
					{
						idString = idString + keyArray[i] + "|";
					}
				}
				if(idString.length > 0)
				{
					var secondData = {action:"query", meta:"notifications", format:"json", notlimit:"1", notmarkread:idString};
					$.post("/w/api.php", secondData);
				}
			}
			else
			{
				for(i = 0; i < keyArray.length; i++)
				{
					if(firstResponse.query.notifications.list[keyArray[i]].category == "edit-user-talk" && typeof firstResponse.query.notifications.list[keyArray[i]].read == "undefined")
					{
						var lastUser = firstResponse.query.notifications.list[keyArray[i]].agent.name;
						var orangeBarDiv = document.createElement("div");
						orangeBarDiv.innerHTML = 'You have <a href="/wiki/User_talk:' + wgUserName.replace(/ /g, '_') + '" title="User talk:'+wgUserName+'">new messages.</a> Last edit by '+lastUser+'.';
						orangeBarDiv.className = "usermessage";
						$("#contentSub").after(orangeBarDiv);
						return;
					}
				}
			}
		});
	}
});
*/