User:TUSF/chat.js

$('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');} } var VisibleLastTime = function {//If the latest message has a different time from the previous one, show the time! $(".Chat li.continued:last-of-type").each(function		{		var prevtime = $(this).prev.find(".time").text;		var thistime = $(this).find(".time").text;		if(prevtime != thistime)			{$(this).find(".time").css("display","inline");}		}); }

//Basically the function above, but doing so when the chat starts, for previous messages. $(".Chat li.continued").each(function	{	var prevtime = $(this).prev.find(".time").text;	var thistime = $(this).find(".time").text;	if(prevtime != thistime)		{$(this).find(".time").css("display","inline");}	});

NodeChatDiscussion.prototype.chatPing = function (chat) {	VisibleLastTime; 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,"loli","pedo"]; //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;} }		}	} $('body').ready( function { mainRoom.model.chats.bind('afteradd', $.proxy(mainRoom.viewDiscussion.chatPing, mainRoom.viewDiscussion)); } );