Jump to content

User:Launchballer/monobook.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.
/*
if(typeof Object.keys == "undefined")
{
Object.keys = (function () {
    var hasOwnProperty = Object.prototype.hasOwnProperty,
        hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
        DontEnums = [ 
            'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty',
            'isPrototypeOf', 'propertyIsEnumerable', 'constructor'
        ],
        DontEnumsLength = DontEnums.length;
 
    return function (o) {
        if (typeof o != "object" && typeof o != "function" || o === null)
            throw new TypeError("Object.keys called on a non-object");
 
        var result = [];
        for (var name in o) {
            if (hasOwnProperty.call(o, name))
                result.push(name);
        }
 
        if (hasDontEnumBug) {
            for (var i = 0; i < DontEnumsLength; i++) {
                if (hasOwnProperty.call(o, DontEnums[i]))
                    result.push(DontEnums[i]);
            }   
        }
 
        return result;
    };
})();
}
 
$(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((mw.config.get('wgCanonicalNamespace') + ":" + mw.config.get('wgTitle')) == ("User_talk:" + mw.config.get('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:' + mw.config.get('wgUserName').replace(/ /g, '_') + '" title="User talk:'+mw.config.get('wgUserName')+'">new messages</a> (<a href="/w/index.php?title=User_talk:'+mw.config.get('wgUserName').replace(/ /g, '_')+'&diff=cur&old=prev">last change</a> by '+lastUser+').';
						orangeBarDiv.className = "usermessage";
						$("#contentSub").after(orangeBarDiv);
						return;
					}
				}
			}
		});
	}
});
*/
importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool