User:Eladkse/ChatHacks.js

//Too bad this doesn't write over the functions properly. Going to have to figure out why. $(function {	$('body').prepend('.chat-mod, .mod, .mod:after {color:#da0;} .chat-mod.away {color:#eda;} .ChatHeader .username, .me {color:#00c;} .UserStatsMenu {color:#000;} ');	window.mods = [];	window.list = document.getElementById('Users').getElementsByTagName('ul')[0].getElementsByTagName('li');	for(i = 0; i < list.length; i++) {		if(list[i].className.split(' ')[1] == 'chat-mod') {			mods.push(list[i].id.substring(5, list[i].id.length));		}	}	//Add/remove mods when people join/leave	NodeChatController.view.addUser = function(user) {		if(user.attributes.isModerator == true) {			var add = true;			for(i in mods) {if(mods[i] == user.attributes.name) {add = false;}}			if(add == true) {mods.push(user.attributes.name)}		}		var view = new UserView({model: user});		$('#Users > ul').append(view.render.el);	}	NodeChatController.view.removeUser = function(user) {		NodeChatHelper.log("Trying to remove " + user.get('name') + " from the list."); NodeChatHelper.log("Matches found: " + $('#' + NodeChatHelper.liIdByUsername( user.get('name') )).length); for(i in mods) {if(mods[i] == user.attributes.name) {mods[i] = undefined;}} $('#' + NodeChatHelper.liIdByUsername( user.get('name') )).remove; }	//Color mod posts when they're added NodeChatController.view.addChat = function (chat) { // Determine if chat view is presently scrolled to the bottom var isAtBottom = false; if (($("#Chat").scrollTop + 1) >= ($("#Chat ul").outerHeight - $("#Chat").height)) { isAtBottom = true; }		// Add message to chat var view = new ChatView({model: chat}); for(i in mods) {if(mods[i] == view.model.attributes.name) {view.model.attributes.name = ' ' + view.model.attributes.name + ' '}} if(wgUserName == view.model.attributes.name) {view.model.attributes.name = ' ' + view.model.attributes.name + ' '} $('#Chat ul').append(view.render.el); // Scroll chat to bottom if (chat.attributes.name == wgUserName || isAtBottom) { NodeChatHelper.scrollToBottom; }	}	//Add timestamp to messages NodeChatController.view.sendMessage = function{ var inputField = $('input[name=message]'); var nameField = $('input[name=user_name]'); if (inputField.val) { var date = new Date; if(date.getUTCHours > 10) {var hours = date.getUTCHours;} else {var hours = '0' + date.getUTCHours;} if(date.getUTCMinutes > 10) {var minutes = date.getUTCMinutes;} else {var minutes = '0' + date.getUTCMinutes;} var chatEntry = new models.ChatEntry({name: nameField.val, text: '[' + hours + ':' + minutes + '] ' + inputField.val}); this.socket.send(chatEntry.xport); inputField.val(''); }		NodeChatHelper.focusTextInput; } });