User:OtisElevatorGuy1/chat.js

/** * Chat stuff *  Copyright © 2013, User:AnimatedCartoons * ____       _         * |  _ \     | |        * | |_) | ___| |_ __ _  * |  _ < / _ \ __/ _` | * | |_) |  __/ || (_| | * |____/ \___|\__\__,_| * * This script is specifically made for The Amazing World of Gumball Wiki * * To request features or report bugs, please message me. * * Importing *   Please add the following here: Special:MyPage/chat.js *   Please do not include the asterisk and spaces (*   ) * *   importScript('User:AnimatedCartoons/chat.js'); * * Supported browsers *   Chrome (Linux, Mac, and Windows) *   Firefox (Linux, Mac, and Windows) *   Internet Explorer 10+ (Windows) *   Safari (Mac) * * Features *   Automatic scroll *   Color-coded messages *   Favicons next to links *   Inline alert timestamps *   Input box content is automatically saved *   Link to user's contributions count and user page *   Messages and users count *   Private message yourself *   Reorder users in the list *  Show audios, images, videos, Wikipedia articles, YouTube videos and playlists without clicking their URLs *  Show own username in the list *  Simplified title *  Wider list of users */ "use strict"; if (mediaWiki.config.get('wgServer') === 'http://theamazingworldofgumball.wikia.com' && mediaWiki.config.get('wgSiteName') === 'The Amazing World of Gumball Wiki') { navigator.detect = (function {        var agent = navigator.userAgent.match(/(chrome|firefox|msie|safari)\/?\s*(\.?\d+(\.\d+)*)/i),            agent2;        if (agent && (agent2 = navigator.userAgent.match(/version\/([\.\d]+)/i)) !== null) {            agent[2] = agent2[1];        }        agent = agent ? [agent[1], agent[2]] : [navigator.appName, navigator.appVersion, '-?'];        return agent;    }); if ((navigator.detect[0] === 'MSIE' && navigator.detect[1] >= 10) || ((navigator.detect[0] === 'Chrome' || navigator.detect[0] === 'Firefox') && (navigator.platform.indexOf('Linux') > -1 || navigator.platform.indexOf('Mac') > -1 || navigator.platform.indexOf('Win') > -1)) || (navigator.detect[0] === 'Safari' && navigator.platform.indexOf('Mac') > -1)) { if (mediaWiki.config.get('wgCanonicalSpecialPageName') === 'Chat') { $(function {                // Import                importStylesheet('User:AnimatedCartoons/chat.css');                // Change title                document.title = 'Chat - TAWoG Wiki';                // Show own username in the list                $('.User#user-' + mediaWiki.config.get('wgUserName')).attr('style', 'display: block !important');                // Get local storage                if (localStorage.getItem('message') === 'undefined') {                    $('.Write [name="message"]').val('');                } else {                    $('.Write [name="message"]').val(localStorage.getItem('message'));                }            }); // Messages and users count $('.Rail').prepend('   '); setInterval(function {                // Replacements                // Audios                $('.Chat .message a[href$=".mp3"]').each(function  { $(this).replaceWith('  '); });               // Videos                $('.Chat .message a[href$=".mp4"], .Chat .message a[href$=".webm"]').each(function  { $(this).replaceWith('  '); });               // Images                $('.Chat .message a[href$=".bmp"], .Chat .message a[href$=".gif"], .Chat .message a[href$=".jpeg"], .Chat .message a[href$=".jpg"], .Chat .message a[href$=".png"], .Chat .message a[href$=".svg"], .Chat .message a[href$=".tif"], .Chat .message a[href$=".tiff"], .Chat .message a[href$=".webp"]').each(function  { $(this).replaceWith('  '); });               // Wikipedia articles                $('.Chat .message a[href*="wikipedia.org/wiki/"]').each(function  { var $this = $(this).text, result = $this.replace('wikipedia.org', 'm.wikipedia.org'), result2; if ($this.indexOf('http://') === 0) { result2 = result.slice(7); } else if ($this.indexOf('https://') === 0) { result2 = result.slice(8); }                   $(this).replaceWith('  '); });               // YouTube videos                $('.Chat .message a[href*="www.youtube.com/watch?v="]').each(function  { var $this = $(this).text, result = $this.replace('www.youtube.com/watch?v=', 'www.youtube.com/embed/'), result2; if (result.indexOf('http://') === 0) { result2 = result.slice(7); } else if (result.indexOf('https://') === 0) { result2 = result.slice(8); }                   $(this).replaceWith('  '); });               // YouTube playlists                $('.Chat .message a[href*="www.youtube.com/playlist?list="]').each(function  { var $this = $(this).text, result = $this.replace('www.youtube.com', 'www.youtube.com/embed'), result2; if (result.indexOf('http://') === 0) { result2 = result.slice(7); } else if (result.indexOf('https://') === 0) { result2 = result.slice(8); }                   $(this).replaceWith('  '); });               // Save input box content to local storage                localStorage.setItem('message', $('.Write [name="message"]').val);                // Favicons next to links                $('.Chat .message a[href^="http"], .Chat .message a[href^="https"]').each(function  { $(this).css({                       background: 'url(https://getfavicon.appspot.com/' + this.href + '?defaulticon=lightpng) left center no-repeat',                        backgroundSize: '16px',                        paddingLeft: '20px'                    }); });               // Inline alert timestamps                var today = new Date;                var h = today.getHours;                var m = today.getMinutes;                switch (h) {                case 13:                    h = 1;                    break;                case 14:                    h = 2;                    break;                case 15:                    h = 3;                    break;                case 16:                    h = 4;                    break;                case 17:                    h = 5;                    break;                case 18:                    h = 6;                    break;                case 19:                    h = 7;                    break;                case 20:                    h = 8;                    break;                case 21:                    h = 9;                    break;                case 22: h = 10; break; case 23: h = 11; break; case 0: h = 12; break; }               if (m < 10) { m = '0' + m;               } $('.Chat ul li.inline-alert').each(function {                    if ($(this).is(':last-child') && !$(this).find('.inline-time').length) {                        $(this).append(' ' + h + ':' + m + ' ');                    }                }); // Color-coded messages $('.Chat .username').each(function {                    var $name = $(this).text;                    if ($name.match(/Ailourophile|Gumballamiyumi|InvaderrrZIM|Killer365|MisterJim|Randomced859|StickVentures2/g)) {                        $(this).css('color', '#FF0');                        $(this).siblings('.message').css('color', '#FF0');                    }                    if ($name.match(/Chibitracy|DeviantSerpent|Miggy7215/g)) {                        $(this).css('color', '#F7984D');                        $(this).siblings('.message').css('color', '#F7984D');                    }                }); // Messages count $('.Rail .messages').html($('.Chat .message').length); // Users count $('.Rail .users').html($('li.User').length); }, 1);           // Sort list of users            mediaWiki.loader.using('jquery.ui.sortable', function  { $('.WikiChatList').sortable({                   revert: true,                    containment: '.Rail',                    handle: 'img',                    start: function (e, ui) {                        ui.placeholder.height(ui.item.height);                    }                }).disableSelection; $('.PrivateChatList').sortable({                   revert: true,                    containment: '.Rail',                    handle: 'img',                    start: function (e, ui) {                        ui.placeholder.height(ui.item.height);                    }                }).disableSelection; });           $('.WikiChatList').on('click', 'li.User', function  { // Link to user's user page $('.UserStatsMenu .info .username').each(function {                    var user = $(this).text;                    $(this).replaceWith(' ' + user + '');                }); // Link to user's contributions count $('.UserStatsMenu .info .edits').each(function {                    var user = $(this).siblings('.username').text;                    $(this).replaceWith(' ' + $(this).text + '');                }); });           // Add custom actions/links            $('li.User#user-' + mediaWiki.config.get('wgUserName') + ' .UserStatsMenu .actions').append(' ');            // Automatic scroll            $('.WikiChatList').on('click', 'li.User', function  { if (localStorage.getItem('autoscroll') === '' || localStorage.getItem('autoscroll') === null || localStorage.getItem('autoscroll') === 'false') { $('.UserStatsMenu ul.custom-actions li.autoscroll').html(' Enable autoscroll'); } else { $('.UserStatsMenu ul.custom-actions li.autoscroll').html(' Disable autoscroll</a>'); }           });            $('body').on('click', '.UserStatsMenu ul.custom-actions li.autoscroll a.a', function  { NodeChatDiscussion.prototype.scrollToBottom = function { var forceScroll = this.forceScroll; setTimeout($.proxy(function { this.chatDiv.scrollTop(this.chatDiv.get(0).scrollHeight); this.forceScroll = forceScroll; }, this), 0); };               function c(chat) { if (chat.attributes.text) { mainRoom.viewDiscussion.scrollToBottom; }               }                mainRoom.model.chats.bind('afteradd', c); $(this).attr('class', 'b').text('Disable autoscroll'); localStorage.setItem('autoscroll', 'true'); });           $('body').on('click', '.UserStatsMenu ul.custom-actions li.autoscroll a.b', function  { NodeChatDiscussion.prototype.scrollToBottom = function {}; function c(chat) { if (chat.attributes.text) { mainRoom.viewDiscussion.scrollToBottom; }               }                mainRoom.model.chats.bind('afteradd', c); $(this).attr('class', 'a').text('Enable autoscroll'); localStorage.setItem('autoscroll', 'false'); });           // Bug fixes            $('li.continued:first-child').removeClass('continued');            $('li.inline-alert').next('li.continued:not(.inline-alert)').removeClass('continued');            if (console) {                console.log('Chat stuff activated!');            }        }    } }