User:MACH-59330/chat.js

// give chat a wiki-specific class document.body.classList.add('wiki-' + wgDBname); // mobile chatskin meta tag $('head').append(mw.html.element('meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' })); // 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 = window.pings || new RegExp('(' + ['Speed', 'help', 'mod', 'CSS', 'template', 'infobox', 'Vanguard'].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 ('vibrate' in navigator) { context.navigator.vibrate(200); }		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) {			var data = cwmsg.attributes,				user = data.name;			if ( user === wgUserName || document.getElementById('Chat_' + privateRoomId).style.display !== 'none' && document.hasFocus ) return;			var avatar = cwmsg.attributes.avatarSrc.replace(/28(?!.*28)/, '150'),				pmtitle = "PM from " + user,				pmconfig = { body: data.text, icon: avatar },				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); }); window.QuickModTools = {	quickreasons: [		'spam',		'sockpuppet',		'impersonation',		'inappropriate language',		'inappropriate username',		'Inappropriate language - please see the Chat Guidelines',		'Inappropriate discussion',		'Off-topic discussion - please see the Chat Guidelines',		'Impolite behaviour - please see the Chat Guidelines',		'Not complying with mod direction - please see the Chat Guidelines',		'Intimidating behaviour/harassment'	],	defbanreason: 'Misbehaving in chat - please see the Chat Guidelines',	defbanlength: '86400' }; // chat imports importArticles({ type: 'script', articles: [ 'u:dev:QuickModTools/code.js', 'u:kocka:Emoticons/code.js', // 'u:dev:Colors/code.js' ] });