User:Messenger of Heaven/chat.js

// HTML5 desktop notifications +ping class & PM notifications, forked from TK-999 and Noreplyz require(['wikia.window', 'mw'], function (context, mw) {	if (!context.Notification) {		return;	}	// main room ping variables	var pings = new RegExp('(' + ['MoH', 'Messey', 'Messenger', 'Heaven'].join('|') + ')', 'gi'),		notification = document.createElement('audio');		notification.src = 'http://images.wikia.nocookie.net/speedit/images/0/01/Notification.ogg';		notification.id = 'ChatNotification';		notification.style.display = 'none';	document.body.appendChild(notification);	// main room notification ping function	function main(message) {		var data = JSON.parse(message.data).attrs;		if (data.isInlineAlert || !pings.test(data.text) || data.name == wgUserName ) {			return;		}		var mainconfig = {			body: data.text,			icon: data.avatarSrc.replace(/28(?!.*28)/, '150')		};		document.querySelector('#Chat_' + window.mainRoom.roomId + ' li:last-of-type').classList.add('ping');		notification.play; if ( !document.hasFocus || document.querySelector('#Chat_' + window.mainRoom.roomId).style.display == 'none' ) { var ping = new context.Notification(data.name, mainconfig); setTimeout(function { ping.close; }, 5000); }	}	// pm notification function function priv(cwpm) { var privateRoomId = cwpm.attributes.roomId; var privateRoom = window.mainRoom.chats.privates[privateRoomId]; privateRoom.model.chats.bind('afteradd', function(cwmsg) {			user = cwmsg.attributes.name;			if ( user === wgUserName || document.getElementById('Chat_' + privateRoomId).style.display !== 'none' && document.hasFocus ) return;			msg = cwmsg.attributes.text;			var obj = mainRoom.model.users.findByName(name);			avatar = cwmsg.attributes.avatarSrc.replace(/28(?!.*28)/, '150');			pmtitle = "PM from " + user;			var pmconfig = {				body: msg,				icon: avatar			};			var pmping = new context.Notification(pmtitle, pmconfig),				pmnotif = document.getElementById('ChatNotification');			pmnotif.play;			setTimeout(function { pmping.close; }, 5000);		}); }	// unbind listener if the user didn't allow notifications Notification.requestPermission(function (response) {		if (response !== "granted") {			context.mainRoom.socket.unbind('chat:add', main);			context.mainRoom.model.privateUsers.unbind('add', priv);		}	}); context.mainRoom.socket.bind('chat:add', main); context.mainRoom.model.privateUsers.bind('add', priv); }); importArticles({ type: 'script', articles: [ 'u:dev:ChatOptions/code.js', 'u:dev:NewMessageCount.js', 'u:dev:MediaWiki:PrivateMessageAlert/code.js', 'u:dev:MediaWiki:MessageBlocker/code.js' ] });