MediaWiki:UserTalkNotifications/code.js

/* User Talk Notifications * Code by Seaside98 */

//Variables var talkWikis = window.talkWikis || []; var pageName = window.talkName || 'Talk'; var talkNames = []; //Uppercase the first letter of each wiki's name for (var a in talkWikis) { talkNames[a] = talkWikis[a].replace(/\b./g, function(m){ return m.toUpperCase; }); checkWiki(a); } //Add WikiaNotification element if not present if (!$('#WikiaNotifications').length) { $('#WikiaBarWrapper').before(''); } //Function to check for new messages function checkWiki(z) { //If we are on the talkpage or the cookie isn't set, then update the timestamp if (wgServer+wgPageName == 'http://'+talkWikis[z]+'.wikia.comUser:'+wgUserName+'/'+pageName || !$.cookie('talk'+talkWikis[z])) { setStamp(z); } else { //Load the edits since the last timestamp, organize the data, and then display it to the user $.ajax({			contentType: "application/json; charset=utf-8",			url: "http://"+talkWikis[z]+".wikia.com/api.php?action=query&prop=revisions&titles=User:"+encodeURIComponent(wgUserName)+"/"+pageName+"&rvprop=user&rvend="+$.cookie('talk'+talkWikis[z])+"&format=json",			dataType: "jsonp",			cache: false		}).done(function(data) {			var userAry = [];			var userList;			var plural;			var p; for (p in data.query.pages) { break; }			if ("revisions" in data.query.pages[p]) {				for (var i=0; i You have '+plural+' from '+userList+'. ');				} else {						$('#WikiaNotifications').append(' You have '+plural+' on the '+talkNames[z]+' Wiki from '+userList+'. ');				}				$('.talkClose').click(function { $(this).parent.remove; });			}		});	} } //Function to update the timestamp cookie function setStamp(z) { //Load the last revision to get the timestamp instead of relying on the user's computer for the correct time $.ajax({		contentType: "application/json; charset=utf-8",		url: "http://"+talkWikis[z]+".wikia.com/api.php?action=query&prop=revisions&titles=User:"+encodeURIComponent(wgUserName)+"/"+pageName+"&rvprop=timestamp&rvlimit=1&format=json",		dataType: "jsonp",		cache: false	}).done(function(data) {		var p; for (p in data.query.pages) { break; }		//Add 1 second to the timestamp of the last edit and store it as a cookie		if ("revisions" in data.query.pages[p]) {			var curTime = (parseInt(data.query.pages[p].revisions[0].timestamp.replace(/[^0-9]/g, ""))+1).toString			$.cookie('talk'+talkWikis[z],curTime,{expires: 5, path: '/', domain: '.wikia.com'});			console.log(curTime);		//If the page doesn't exist, prompt the user to create it		} else if (wgServer+wgPageName != 'http://'+talkWikis[z]+'.wikia.comUser:'+wgUserName+'/'+pageName) {			$('#WikiaNotifications').append(' Please create the page User:'+wgUserName+'/'+pageName+'</a> on the '+talkNames[z]+' Wiki. </li>');		}	}); }