MediaWiki:Chat.js

/* Custom username hilite (goodbye intervals!) */ /* by Cod4 */

/* Listen for new messages and update hilite for each incoming message */ window.mainRoom.socket.bind('chat:add', function(message) {   var name = getName(message);    element = $('.Chat').first.find('ul').children.last.find('.username');    updateHighlight(element, name); });

/* Listen for new user joins and update hilite on the userlist accordingly */ window.mainRoom.socket.bind('join', function(message) {   var name = getName(message);    /* Loop around userlist to find appropriate element */    $('#WikiChatList').find('li.User').each(function { if ($(this).attr("data-user") == name) { updateHighlight($(this).find('span.username'), name); }   }); });

/* Listen for user status changes and keep user highlight on the userlist */ window.mainRoom.socket.bind('updateUser', function(message) {   var name = getName(message);    if (name == mw.config.get('wgUserName')) {        updateYourHighlight;    }    else {        $('#WikiChatList').find('li.User').each(function { if ($(this).attr("data-user") == name) { updateHighlight($(this).find('span.username'), name); }       });    } });

/* update your username and the existing userlist when you join chat */ updateHighlight; $('#WikiChatList').find('li.User').each(function {        updateHighlight($(this).find('span.username'), $(this).attr("data-user")); });

/* Get a username from a chat event to use */ function getName(messageData) { var userData = new models.User; userData.mport(messageData.data); return userData.get('name'); }

/* Function to update your highlight at the upper right */ function updateYourHighlight { var headerUserElement = $('#ChatHeader').find('div.User').find('span.username'); updateHighlight(headerUserElement, mw.config.get('wgUserName')); }

headerUserElement = $('#ChatHeader').find('div.User').find('span.username'); updateHighlight(headerUserElement, headerUserElement.text); /* function to add highlight class without needing regex. */ /* add usernames in the same format as necessary. */ function updateHighlight(element, name) { switch(name) { /* Bureaucrats */ case 'Killer365': case 'Superluigi6': case 'Pearl is awsome': element.addClass('bureaucrat').removeClass('chat-mod'); break; /* Admins */ case 'AwesomeSteven': case 'ThePK': element.addClass('admin').removeClass('chat-mod'); break; /* Bots */ case 'StevenBot': case 'GarnetBot': case 'KPehT': element.addClass('bot').removeClass('chat-mod'); break; /* VSTF */ case 'Callofduty4': case 'Cyanide3': case 'Ajraddatz': element.addClass('vstf').removeClass('chat-mod'); break; /* Chat Mods */ case 'Poorle': case 'JinxBinx': case 'Alcana': case 'Vérité et Masques': case 'Sharayna': case 'Strong In The Real Way': case 'AwesomePeridot': case 'Sticks the Badger': element.addClass('chatmod').removeClass('chat-mod'); break; /* Patrollers */ case 'Lizington': case 'LarsMars': case 'Lilduders': case 'Vogel100': element.addClass('patroller'); break; /* Rollbackers */ case 'The Diamond Man': element.addClass('rollback'); break; /* ICs */ case 'FinnManusia': element.addClass('ic'); } } /* Clear chat */ function addClearChatText { "use strict"; if ($('.clearChatText').length <= 0) { var clearChatText = document.createElement('span'); $('Clear chat ').prependTo('.Rail'); } } function clearChat { "use strict"; var chatSize = $('div.Chat:first ul li').size - 1; $('.Chat:first li:lt(' + chatSize + ')').remove; } window.onload = addClearChatText; /* Chat options */ var chatOptionsLoaded = false; if (!chatOptionsLoaded) { chatOptionsLoaded = true; } //—————————————————————————————— ! ! ! ———————————————————————————————// /* Import scripts. NOTE: Place scripts configurations above this line */ importArticles( {   type: 'script',    articles: [        'u:dev:ChatTags/code.js',        'u:dev:!mods/code.js',        'u:dev:ChatOptions/code.js'    ] } );

//Chat's topic. Remember to escape single quotes in the topic using \' to prevent this from breaking. var chatTopic = 'Welcome to the Steven Universe Wiki chat. Please read the rules before chatting.' $(function { $('#ChatHeader .public.wordmark').prepend(''+chatTopic+' ') .find('a').attr('style','position:relative;text-decoration:none;') }) $('#ChatHeader .public.wordmark div:not(:first-child)').remove //Clear chat button function addClearChatText{ if ($('.clearChatText').length <= 0) { var clearChatText = document.createElement('span'); $('Clear chat ').prependTo('.Rail'); } } function clearChat{ $('.Chat li').remove; } window.onload=addClearChatText; //END Clear chat button //Switch to night button var night_button = 'Night theme'; //Switch to day button var day_button = 'Day theme'; // //Color scheme for DAY Chat // //Link color var linkColorDay = '#2C7E9A'; //All text Color var textColorDay = '#000000'; //Self text background color var selfTextColorDay = '#DCFBFD'; //Chat background color var backgroundColorDay = '#DCFBFD'; //Chat foreground color var foregroundColorDay = '#DCFBFD'; //User stats foreground color var userStatsColorDay = '#DCFBFD'; //END DAY Chat color scheme // //Color scheme for NIGHT Chat // //Link color var linkColor = '#FFD300'; //All text Color var textColor = '#ffffff'; //Self text background color var selfTextColor = '#012445'; //Chat background color var backgroundColor = '#012445'; //Chat foreground color var foregroundColor = '#012445'; //User stats foreground color var userStatsColor = '#012445'; //END NIGHT Chat color scheme //Day and night color schemes //Written by Foodbandlt function addDayStyle{ var styleElementDay = document.createElement('style'); styleElementDay.setAttribute("id", "day"); styleElementDay.innerHTML='body{background-color: '+backgroundColorDay+';}.username, .message, div.chattopic, .info .edits, .UserStatsMenu .info .since, #ChatHeader h1.private, .Write [name="message"]{color: '+textColorDay+';}.WikiaPage, .UserStatsMenu, .ChatHeader, .Write [name="message"]{background-color: '+foregroundColorDay+' !important;}.Chat .you{background: '+selfTextColorDay+';}a{color: '+linkColorDay+';}.UserStatsMenu .info{background-color:'+userStatsColorDay+';}'; $('head').append(styleElementDay); } function addNightStyle{ var styleElement = document.createElement('style'); styleElement.setAttribute("id", "night"); styleElement.innerHTML='body{background-color: '+backgroundColor+';}.username, .message, div.chattopic, .info .edits, .UserStatsMenu .info .since, #ChatHeader h1.private, .Write [name="message"]{color: '+textColor+';}.WikiaPage, .UserStatsMenu, .ChatHeader, .Write [name="message"]{background-color: '+foregroundColor+' !important;}.Chat .you{background: '+selfTextColor+';}a{color: '+linkColor+';}.UserStatsMenu .info{background-color:'+userStatsColor+';}'; $('head').append(styleElement); } function addDayNightButton{ $(''+night_button+' ').prependTo('.Rail'); if ($('style#night').size < 1 && $('style#nightUser').size < 1){ addDayStyle; } } function day_night(which){ if (which == "night"){ $('style#day').remove; $('.Rail .day-night-div .day-night-button').text(day_button); addNightStyle; }else{ $('style#night').remove; $('.Rail .day-night-div .day-night-button').text(night_button); addDayStyle; } } function switch_view{ if ($('.Rail .day-night-div .day-night-button').text == night_button){ day_night("night"); }else{ day_night("day"); } } if ($('.Rail .day-night-button').text == ""){ addDayNightButton; } while ($('.Rail .day-night-div').size > 1){ $('.WikiaPage .Rail div:last-child').remove }

/* ChatTags */ importScriptPage('ChatTags/code.js', 'dev');

/* ChatOptions */ importScriptPage('ChatOptions/code.js', 'dev');

/*Tab Insert*/ importScriptPage('User:Joeytje50/tabinsert.js','runescape')