User:Monchoman45/ChatHacks.js

//Too bad this doesn't write over the functions properly. Going to have to figure out why. window.onload = 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; NodeChatController.view.setBack;}}); //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)); }		}

//Unbind current stuff, so that changes will take effect NodeChatController.view.model.chats.unbind('add'); NodeChatController.view.model.users.unbind('add'); NodeChatController.view.model.users.unbind('remove'); NodeChatController.view.model.users.unbind('all');

//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; }

//Rebind the stuff we unbound, thus (hopefully) successfully editing the functions NodeChatController.view.model.chats.bind('add', NodeChatController.view.addChat); NodeChatController.view.model.users.bind('add', NodeChatController.view.addUser); NodeChatController.view.model.users.bind('remove', NodeChatController.view.removeUser); NodeChatController.view.model.users.bind('all', NodeChatController.view.beautifyUserList); } }

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