User:Monochromatic Bunny/chat.js

importScriptPage('User:Monchoman45/ChatHacks.js', 'c'); mw.loader.load('https://raw.github.com/sactage/wikia-js-snippets/master/ChatOptions.js');

/** * Shows an HTML5 desktop notification if your name is mentioned in chat * @see https://developer.mozilla.org/en-US/docs/Web/API/notification * credit to TK-999 */ require(['wikia.window', 'mw'], function (context, mw) {	if (!context.Notification) {		return;	}	// cache user name	var user = mw.config.get('wgUserName');	function notify(message) {		var data = JSON.parse(message.data).attrs;		if (data.isInlineAlert || data.text.indexOf(user) === -1) {			return;		}		var options = {			body: data.text,			icon: data.avatarSrc		};		new context.Notification(data.name, options);	}	// unbind listener if the user didn't allow notifications	Notification.requestPermission(function (response) { if (response !== "granted") { context.mainRoom.socket.unbind('chat:add', notify); }	});	context.mainRoom.socket.bind('chat:add', notify); });