User:Monchoman45/ChatHacks.js

//Too bad this doesn't write over the functions properly. Going to have to figure out why. $(function {	if(wgPageName == 'Special:Chat') {		$('body').prepend('.chat-mod, .mod, .mod:after {color:#da0;} .chat-mod.away {color:#eda;} .ChatHeader .username, .me {color:#00c;} .UserStatsMenu {color:#000;} ');

//Add a 'go afk' button $('#Write').append('AFK'); //Unbind all of the listeners that set your status to back $(window).unbind('mousemove').unbind('focus').unbind('keypress'); //Set status to back when you press enter $('input[name=message]').bind('keypress', function {if(event.keyCode == 13) {NodeChatHelper.resetActivityTimer;}}); //Add a 'clear chat' button $('#Write').append('Clear'); 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.model.users._callbacks.add[0] = 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.model.users._callbacks.remove[0] = 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.model.chats._callbacks.add[0] = 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 - doesn't work yet, have to find this object ref $('#Write').unbind('submit'); 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; }		$('#Write').bind('submit', function{NodeChatController.view.sendMessage.call(NodeChatController.view);}); } });

function ToggleAway { if($('#ChatHeader .User').hasClass('away') == true) { NodeChatController.view.setBack; }	else { NodeChatController.view.setAway; } }