User:TUSF/chat.js

//The following code will alert you when under 3 conditions //(currently, all pings are the same.) //When there is an Alert (User Join/Leave/Ban/Ect) //When someone says your name //When someone posts. //The first Condition always happens, so it'll make a ping each time. //The second condition and the third condition only ping you when

$('body').append(' '); window.hasFocus = true;//set a variable to determine Focus or not. $(window).bind('focus', function {window.hasFocus = true;document.getElementById('sound').innerHTML = '';}); $(window).bind('blur', function {window.hasFocus = false;}); var AlertPing=function(type) //Will add new sounds for each. This is temporary. Just setting it up! {	var playSound = function(link) {document.getElementById('sound').innerHTML=' ';}; if(type=='user-join') {playSound('http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg');} if(type=='user-leave') {playSound('http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg');} if(type=='user-post') {playSound('http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg');} if(type=='name-alert') {playSound('http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg');} else {playSound('http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg');} } NodeChatDiscussion.prototype.chatPing = function (chat) {	var text = chat.attributes.text; if(chat.attributes.isInlineAlert && text != $.msg('chat-welcome-message',wgSiteName)) //Don't bother alerting when you first join! {AlertPing;return;} if(mainRoom.isInitialized && chat.attributes.name != wgUserName && !chat.attributes.isInlineAlert) {		var pings = [wgUserName]; //List of items to alert on. wgUserName is ones own Username. May add more items. if(!window.hasFocus) //Only annoy people if the window isn't focused {			for(var i = 0; i < pings.length; i++) {				if(text.toLowerCase.indexOf(pings[i].toLowerCase) != -1 || this != mainRoom.viewDiscussion) {AlertPing;this.scrollToBottom;break;return;} }			if(document.getElementById('sound').innerHTML == '') //Only allert once, until focus is returned. Unless name is called. {AlertPing;return;} }		}	} mainRoom.model.chats.bind('afteradd', $.proxy(mainRoom.viewDiscussion.chatPing, mainRoom.viewDiscussion));