User:Tappity/chat.js

var pings = ['Tappity', 'Tap', 'Slayze', 'Taptap'];

/* set a variable to determine Focus or not. */ window.hasFocus = true; $(window).bind('focus', function { window.hasFocus = true; }); $(window).bind('blur', function { window.hasFocus = false; });

var alertInit = function { Notification.requestPermission; mainRoom.model.chats.bind('afteradd', $.proxy(alertPing, mainRoom.viewDiscussion)); };

var alertPing = function(chat) { var user = chat.attributes.name; var msg = chat.attributes.text; if (!user || user === wgUserName || window.hasFocus) { return; }   var impt = ''; pings.forEach(function(ping) {       if (msg.indexOf(ping) !== -1) {            impt = '[MENTION]';            mainRoom.viewDiscussion.scrollToBottom;        }    }); var nMsg = (impt ? impt + ' ' : '') + user + ': ' + msg; var notification = new Notification(nMsg); };

$(document).ready(alertInit);