User:Rosette Addams/chat.js

setInterval(function {   if (!window.mainRoom || !mainRoom.socket) return;    if (!mainRoom.socket.socket || !mainRoom.socket.connected || !mainRoom.socket.socket.connected) {        mainRoom.socket.connect;        if (mainRoom.socket.socket) {            mainRoom.socket.socket.connect;        }    } }, 10000); /* PrivateHistory * * Keeps chat history on the user's browser, and is recovered after a private chat is opened with the other user. * @scope: any * @author: Dorumin * (function($, mw) {	if (wgCanonicalSpecialPageName != 'Chat' || window.PrivateHistoryInit) return;	window.PrivateHistoryInit = true;	// Check if the browser supports the feature we'll mostly use here	if (!window.localStorage) {		// Since the user is already running a stone-age browser, better check if console.log is a thing.		if (console && console.log)			console.log('Your browser does not support localStorage; exiting PrivateHistory...');		return;	}	var PrivateHistory = {		avatars: {},		indexes: {},		complete: [],		Unix: {			small: function(n) {				return Number(n.toString.slice(0, -4));			},			big: function(n) {				return Number(n.toString + '000');			}		},		loadMessages: function(usrs, key, privateRoom) {			var script = PrivateHistory,			arr = JSON.parse(localStorage.getItem(key)),			users = [wgUserName].concat(usrs),			old = privateRoom.model.chats.models.map(function(e) { var a = e.attributes; if (a.isScriptAddition) return false; var b = script.Unix.small(a.timeStamp), c = a.text, d = usrs.indexOf(a.name) + 1; return [b, c, d]; }).filter(Boolean);/*			arr = arr.concat(old).map(function(el, i, a) { return a.map(function(e) {return JSON.stringify(e);}).lastIndexOf(JSON.stringify(el)) != i ? null : el; }).filter(Boolean);* /			var $ul = privateRoom.viewDiscussion.chatUL;			if (privateRoom.model.chats.models.length == arr.length)				return;			else				console.log(privateRoom.model.chats.models.length, arr.length);			while (privateRoom.model.chats.models[0])				privateRoom.model.chats.remove(privateRoom.model.chats.models[0]);			var oArr = Infinity;			if (arr.length > 50) {				oArr = arr.length;				var idx = script.indexes,				k = usrs.join('|');				idx[k] = idx[k] || 0;				idx[k] += 50;				arr = arr.slice(-script.indexes[k]);			}			for (var i in arr) {				var item = arr[i],				time = item[0],				text = item[1],				name = users[item[2]],				main = mainRoom.model.users.findByName(name);				if (!script.avatars[name])					console.log(name, users, item[2]);				privateRoom.model.chats.add( new models.ChatEntry({						timeStamp: script.Unix.big(time),						avatarSrc: script.avatars[name] || (main ? main.attributes.avatarSrc : ''),						name: name,						text: text,						isScriptAddition: true					}) );			}			if (privateRoom.model.chats.models.length >= oArr)				script.complete.push(usrs.join('|'));		},		init: function {			var script = this;			var mainUsers = mainRoom.model.users.models;			for (var i in mainUsers) {				var a = mainUsers[i].attributes;				script.avatars[a.name] = a.avatarSrc;			}			mainRoom.model.users.bind('add', function(usr) { var a = usr.attributes; script.avatars[a.name] = a.avatarSrc; });			// Bind function to Private chat updates			mainRoom.model.privateUsers.bind('add', function(u) { var name = u.attributes.name, PMId = u.attributes.roomId, privateRoom = mainRoom.chats.privates[PMId]; function initRoom { if (!privateRoom.model.users.models.length) return; clearInterval(interval); var usrs = privateRoom.model.privateRoom.attributes.users.map(function(n) {						if (n == mw.config.get('wgUserName')) return null;						return n;					}).filter(Boolean).sort, key = 'PrivateHistory-' + usrs.join('|'), privateHistory = localStorage.getItem(key), afterChat = function(chat) { var attrs = chat.attributes; if (attrs.isInlineAlert || attrs.isScriptAddition) return; var time = script.Unix.small(attrs.timeStamp), user = usrs.indexOf(attrs.name) + 1, text = attrs.text, value = JSON.parse(localStorage.getItem(key)), push = [time, text, user]; if (value.indexOf(push) == -1) value.push(push); localStorage.setItem(key, JSON.stringify(value)); },					scroll = function(e) { if (e.target.scrollTop < 500 && script.complete.indexOf(usrs.join('|')) === -1) script.loadMessages(usrs, key, privateRoom); };					if (privateHistory === null) localStorage.setItem(key, '[]'); else script.loadMessages(usrs, key, privateRoom); privateRoom.viewDiscussion.chatDiv[0].addEventListener('scroll', scroll, {passive: true}); privateRoom.model.chats.models.forEach(afterChat); privateRoom.model.chats.bind('afteradd', afterChat); }				var interval = setInterval(initRoom, 50); });		}	};	var interval = setInterval(function { if (!window.mainRoom) return; clearInterval(interval); PrivateHistory.init; }, 250);	window.PrivateHistory = PrivateHistory; })(window.jQuery, window.mediaWiki);*/ $.msg = $.msg || function(msg) { console.log(msg); }; window.mobilecheck = function { var check = false; (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a)) check = true;})(navigator.userAgent||navigator.vendor||window.opera); return check; }; if (/*mobilecheck*/ window.falsre) { alert('Oh NO! You are using mobile! Shame on you.'); // Remove everything $(document.body).add(document.head).empty; $.each(document.body.attributes, function(key, value) {       try {            document.body.removeAttribute(value.nodeName);        } catch (e) {}    }); // Utility functions var loadSVG = function(url, callback) { $.ajax({           url: 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '',            dataType: 'xml',            success: function(xml) {                var $el = $($(xml).find('results').html);                if ($.isFunction(callback)) callback($el);            }        }); };   // Start doing stuff document.title = 'Chat - ' + mw.config.get('wgSiteName'); var css = '/* - - - - - - - - - - - - - - - - - - - - - -\ - START OF CHATHEADER \ - - - - - - - - - - - - - - - - - - - - - -\   */\    .header {\ -webkit-box-align: center;\ -webkit-align-items: center;\ -ms-flex-align: center;\ align-items: center;\ background-color: #FFF;\ border-bottom: 1px solid #F6F6F6;\ border-top: .375rem solid #092344;\ direction: ltr;\ display: -webkit-box;\ display: -webkit-flex;\ display: -ms-flexbox;\ display: flex;\ -webkit-box-orient: horizontal;\ -webkit-box-direction: normal;\ -webkit-flex-direction: row;\ -ms-flex-direction: row;\ flex-direction: row;\ -webkit-flex-wrap: nowrap;\ -ms-flex-wrap: nowrap;\ flex-wrap: nowrap;\ height: 3.4375rem;\ -webkit-box-pack: justify;\ -webkit-justify-content: space-between;\ -ms-flex-pack: justify;\ justify-content: space-between;\ left: 0;\ margin: 0 auto;\ padding: 0 6px;\ position: fixed;\ right: 0;\ text-align: center;\ -webkit-transition: box-shadow .5s;\ transition: box-shadow .5s;\ -webkit-transform: translate3d(0,0,0);\ transform: translate3d(0,0,0);\ top: 0;\ width: 100%;\ z-index: 700;\ }\   \    .share-header .site-head-icon-nav, \ .share-header .site-head-icon-search, \ .header .options, \ .header .userlist {\ -webkit-box-flex: 0;\ -webkit-flex: 0 0 48px;\ -ms-flex: 0 0 48px;\ flex: 0 0 48px;\ }\   \    .icon-button {\ cursor: pointer;\ }\   \    .icon-button svg {\ height: 24px;\ width: 24px;\ }\   \    .userlist, .options {\ -webkit-box-flex: 0;\ -webkit-flex: 0 0 48px;\ -ms-flex: 0 0 48px;\ flex: 0 0 48px;\ }\   \    .logo {\ margin: 0 auto;\ }\   \	body, html {\ color: #39424D;\ padding: 0;\ margin: 0;\ font-family: "Helvetica Neue",Arial,sans-serif;\ font-style: normal;\ line-height: 150%;\ cursor: auto;\ overflow-y: scroll;\ word-wrap: break-word;\ height: 100%;\ font-size: 16px;\ position: relative;\ font-weight: 400;\ }\	* {\		box-sizing: inherit;\ }\   \    .logo svg{\ width: 130px;\ padding-bottom: 15px;\ }\   \    /* - - - - - - - - - - - - - - - - - - - - - -\       --- END OF CHAT HEADER  ---\ - - - - - - - - - - - - - - - - - - - - - -\      -- START OF CHATVIEW  -\ - - - - - - - - - - - - - - - - - - - - - -\   */\    #ChatView {\ height: 80vh;\ width: 103%;\ margin-top: 3.9375rem;\ background-color: lavender;\ }\   \    .Chat {\ height: 100%;\ width: 100%;\ overflow-y: visible;\ }\   \    .Chat ul {\ list-style-type: none;\ padding-left: 0;\ }\   \    .Chat li {\ padding: 3px;\ \   }\    \    .Chat .time {\ color: #9C9C9C;\ }\   \    .Chat .username {\ font-weight: bold;\ }\   \    /* - - - - - - - - - - - - - - - - - - - - - -\       --- END OF CHATVIEW  --\ - - - - - - - - - - - - - - - - - - - - - -\      -- START OF TEXTAREA  -\ - - - - - - - - - - - - - - - - - - - - - -\   */\    \    #Write {\ position: relative;\ height: calc(20vh - 3.9375rem - 7px);\ width: 100%;\ }\   \    #message {\ height: 100%;\ width: 90%;\ resize: none;\ }\   \    #send-button.disabled {\ background-color: #93dcf7;\ }\   \    #send-button {\ position: absolute;\ right: -7px;\ top: 3px;\ height: 100%;\ width: 10%;\ border-radius: 50%;\ background-color: #00aff0;\ }\   \    #send-button.active:hover {\ height: 90%;\ width: 9%;\ right: -2px;\ top: 7px;\ }\   #send-button.active:active {\ background-color: red !important;\ }\   \    #send-button svg {\ transform: rotate(25deg);\ }';   var style = mw.util.addCSS(css); style.id = 'mobile-chat-style'; var HTML = '   \ \           \                \ \ \           \            \                \ <path d=\ "M100.6,58.8V0h13.2v33l3.5-4.4l7.4-8.8h18.9L128,35.2l16.5,23.7h-17.2l-9-14.9l-4.6,4.3v10.5H100.6z M51.8,20.1l-5,26.4l-6.4-26.4h-6h-0.3h-2.7h-0.3h-6l-6.4,26.4l-5-26.4H0l10.1,38.8h17.7l5-20.4l5,20.4h17.7l10.1-38.8H51.8z M217.1,47.5l0.7,11.3h-12.1l-0.9-4.2c-2.8,2.9-6.2,5.4-12.3,5.4c-11,0-17-7.1-17-20.6c0-13.5,6-20.6,17-20.6c6.1,0,9.5,2.4,12.3,5.4l0.9-4.2h12.1l-0.7,11.3V47.5z M203.9,34.4c-1.7-2.2-4.3-3.7-7.8-3.7c-4,0-7.1,2.6-7.1,8.7c0,6.1,3.2,8.7,7.1,8.7c3.5,0,6.1-1.5,7.8-3.7V34.4zM79.8,0.2c-4.2,0-7.6,3.4-7.6,7.6c0,4.2,3.4,7.6,7.6,7.6c4.2,0,7.6-3.4,7.6-7.6C87.4,3.6,84,0.2,79.8,0.2 M91.2,27.8v-8.3h-5.7H72.2v13.4v12.5v13.1v0.3h19v-8.2h-5.9V27.8H91.2z M153.7,7.8c0,4.2,3.4,7.6,7.6,7.6c4.2,0,7.6-3.4,7.6-7.6c0-4.2-3.4-7.6-7.6-7.6C157.1,0.2,153.7,3.6,153.7,7.8 M155.8,27.8v22.8h-5.9v8.2h19v-0.3V45.4V32.9V19.5h-13.2h-5.7v8.3H155.8z"\ fill="#000"> \ \           \                \ \ \ \ \                       \ \                   \ \ \                    \ \ \                   \ \                \ \       \        \    	 \    		<div id="Chat_main" class="Chat">\ <ul>\ </ul>\ \   	 \    	\    	 \    		  \    		 \    			<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="-300 -340 1800 1800" enable-background="new 0 0 1 1" xml:space="preserve">\ \ <path d="M10,387.9l396.1,129.2l251-171.8l-172.4,252l122.2,394.4L990,8.2L10,387.9z" fill="white"> \ </g>\ \   		 \    	 ';    document.body.innerHTML = HTML; var $ChatView = $('#ChatView'); // Detect new messages; rudimentary IRC look for now mainRoom.model.chats.bind('afteradd', function(e) {       var a = e.attributes,            n = a.name,            t = a.text,            s = a.timeStamp,            i = a.isInlineAlert,            d = new Date(s === '' ? Date.now : s),           b = '[' + d.getHours + ':' + d.getMinutes + ':' + d.getSeconds + ']';        e = $('<li>').addClass(i ? 'alert' : ).append(' ' + b + ' ' + (i ?  : ' ' + n + ' : ') + ' ' + t + ' ').appendTo('#Chat_main ul');   }); // Add active/disabled classes on the send button var $msg = $('#message'), $send = $('#send-button'); $msg.on('keyup', function(e) {       var val = $msg.val;        if (!val.trim.length) $send.addClass('disabled').removeClass('active');        else $send.addClass('active').removeClass('disabled');    }); // Send message on send button click $send.click(function {       if ($send.hasClass('disabled')) return;        mainRoom.socket.send(new models.ChatEntry({            roomId: this.roomId,            name: mw.config.get('wgUserName'),            text: $msg.val.trim        }).xport);        $msg.val('');    }); } // Ajax Block settings AjaxBlock = { expiryTimes: { '2 hours': '2 hours', '5 hours': '5 hours', '12 hours': '12 hours', '1 day': '1 day', '3 days': '3 days', '5 days': '5 days', '1 week': '1 week', '2 weeks': '2 weeks', '1 month': '1 month', '3 months': '3 months', '6 months': '6 months', '1 year': '1 year', '2 years': '2 years', '3 years': '3 years', 'infinite': 'Infinite' },   blockReasons: { 'Vandalism': 'Vandalism', 'Spam': 'Spam', 'Repeated policy violations': 'Repeated violations', 'Sockpuppetry/Ban Evasion': 'Sockpuppetry', 'Removing content/blanking pages': 'Page blanking', 'Inserting false information or nonsense': 'Gibberish', 'Intimidating behaviour/harassment/trolling': 'Troll/Harassment', 'Unacceptable username, avatar, or global masthead': 'Name/avatar', 'Under the legal age': 'COPPA', 'Failing to comply with the File Policy': 'File Policy', 'Posting/Discussing leaked content': 'Leaks' },   check: { creation: true, talk: true, autoBlock: true, override: true } }; var desktopNotifications = true; $('.User').first.before('<button style="float:right;position:absolute;top:5px;right:150px;" class="HideRailButton" onclick="$(&quot;#Rail&quot;).toggle;var toggleWidth = ($(window).width - ($(&quot;.Chat&quot;).offset.left+$(&quot;.Chat&quot;).outerWidth)) > 150 ? &quot;0px&quot; : &quot;150px&quot;;$(&quot;.Chat, .Write&quot;).css({right:toggleWidth});var txt = ($(&quot;.HideRailButton&quot;).text == &quot;Hide Rail&quot;) ? &quot;Show Rail&quot; : &quot;Hide Rail&quot;;$(&quot;.HideRailButton&quot;).text(txt);">Hide Rail '); importArticles({   type: "script",    articles: ['u:embercastle:User:Dorumin/chat.js', 'u:dev:MessageBlocker/code.js'] }); // ChatPlugins var ChatPlugins = { release: { version: 1.1, branch: "Stable" },   models: { feature: function(id, name, access, script) { this.enabled = false; this.id = id; this.name = name; this.access = access; this.script = script; },       alert: function(text) { newInlineAlert = new models.InlineAlert; newInlineAlert.attributes.text = text; mainRoom.model.chats.add(newInlineAlert); },       command: function(command, script) { this.command = command; this.script = script; }   },    features: {}, settings: { release: { version: 1.0, branch: "Stable" },       icons: { staffIcon: "http://img1.wikia.nocookie.net/__cb20140626173406/gamedezyner/images/6/60/StaffIcon.png", modIcon: "http://img1.wikia.nocookie.net/__cb20140626173343/gamedezyner/images/8/89/ModIcon.png" },       sounds: { pingSound: "http://images.wikia.com/gamedezyner/images/7/7e/PingSound.ogg" },       features: { pings: false }   },    save: function { ChatPlugins.settings.features.pings = ChatPlugins.features.pings.enabled; api.functions.editPage("User:" + wgUserName + "/ChatPlugins.js", JSON.stringify(ChatPlugins.settings)); },   load: function { new ChatPlugins.models.alert("Welcome to Chat Plugins 1.0!"); pagecontents = api.functions.getPageContents("User:" + wgUserName + "/ChatPlugins.js"); if (pagecontents == "error") { new ChatPlugins.models.alert("There seems to be something wrong with your settings file, or it doesn't exist yet. Default settings have been saved."); ChatPlugins.save; } else { ChatPlugins.settings = JSON.parse(pagecontents); ChatPlugins.features.pings.enabled = ChatPlugins.settings.features.pings; ChatPlugins.features.pings.words = ChatPlugins.settings.pings; }       pagecontents = api.functions.getPageContents("MediaWiki:ChatPluginsSettings.js"); if (pagecontents != "error") { wikicustom = JSON.parse(pagecontents); if (typeof(wikicustom.settings) != "object") { new ChatPlugins.models.alert("This wiki has a custom settings page, but it is broken."); } else { ChatPlugins.settings.icons = wikicustom.settings.icons; //Load Wiki-specific icons ChatPlugins.settings.sounds = wikicustom.settings.sounds; //Load Wiki-specific sounds new ChatPlugins.models.alert("This wiki has custom settings and they have been applied."); }       }    } }; // Call API function callAPI(data, method, callback) { data.format = 'json'; $.ajax({       data: data,        dataType: 'json',        url: wgScriptPath + '/api.php',        type: method,        success: function(response) {            if (response.error) showError('API error: ' + response.error.info);            else callback(response);        },        error: function(xhr, error) {            showError('AJAX error: ' + error);        }    }); } // Inline-mod tools function scrollToBottom { var chat = document.getElementById('Chat_' + mainRoom.roomId); chat.scrollTop = chat.scrollHeight; } $("head").append('<style id="ChatPluginsModIconsStyle">.Chat .username:after { content: "" !important; } '); ChatPlugins.features.modIcons = new ChatPlugins.models.feature(null, "Mod Icons", 0, function(chat) {   var time = new Date;    var hours = time.getHours;    var minutes = time.getMinutes;    var seconds = time.getSeconds;    if (hours < 10) hours = '0' + hours;    if (minutes < 10) minutes = "0" + minutes;    if (seconds < 10) seconds = "0" + seconds;    mainRoom.viewDiscussion.chatUL.children.last.children(".message").attr('msg-source', chat.attributes.text);    mainRoom.viewDiscussion.chatUL.children.last.children(".message").attr('msg-time', hours + ':' + minutes + ':' + seconds);    if (wgUserGroups.indexOf("chatmoderator") >= 0 || wgUserGroups.indexOf("sysop") >= 0) {        mainRoom.viewDiscussion.chatUL.children.last.children('.username').hover(function { var thistarget = this; var username = chat.attributes.name; if (username != wgUserName) { $(thistarget).append(' \                   <span class="inline-kick" style="color: #3cd7fa !important;cursor:pointer;">Kick \                     - <span class="inline-block" data-usr="' + username + '" style="color: #3cd7fa !important;cursor:pointer;">Block \                     - <a href="/wiki/Special:Log/chatban?page=User:' + username.replace(' ', '+') + '" target="_blank" style="color: #3cd7fa !important;">Log</a> '); $(thistarget).children.children('.inline-kick').click(function {                   mainRoom.kick({ name: username });               });                $(thistarget).children.children('.inline-block').click(function(e) {                    var usr = $(this).attr('data-usr'),                        token = mw.user.tokens.get('editToken');                    // Show the block modal                    $.showCustomModal('Ajax Block: ' + usr, 'Expiry:<select id="AjaxBlockExpirySelect"> Other <input id="AjaxBlockCustomExpiry" type="text" size="50"> Reason:<select id="AjaxBlockReasonSelect"> Other <input id="AjaxBlockCustomReason" type="text" size="50"> <input id="accountCreation" type="checkbox"> <label for="accountCreation">Prevent account creation <input id="disableWall" type="checkbox"> <label for="disableWall">Prevent from posting on message wall <input id="autoBlock" type="checkbox"> <label for="autoBlock">Block all IPs from this user (AutoBlock) <input id="overrideBlock" type="checkbox"> <label for="overrideBlock">Override any blocks already in effect ', { id: 'ajaxBlockModal', callback: function { // Auto checks checkboxes (customizable) $('#accountCreation').attr('checked', true); $('#disableWall').attr('checked', true); $('#autoBlock').attr('checked', true); $('#overrideBlock').attr('checked', true); var $expirySelect = $('#AjaxBlockExpirySelect'); var $reasonSelect = $('#AjaxBlockReasonSelect'); // Adds the common times and reasons (customizable) $.each(AjaxBlock.expiryTimes, function(key, value) {                               $expirySelect.append($('  ').attr('value', key).text(value));                            }); $.each(AjaxBlock.blockReasons, function(key, value) {                               $reasonSelect.append($('  ').attr('value', key).text(value));                            }); },                       buttons: [{ // Block button id: 'ajaxBlockBlock', defaultButton: true, message: 'Block this user', handler: function { var blockDuration = ($('#AjaxBlockExpirySelect').val == 'other') ? $('#AjaxBlockCustomExpiry').val.toLowerCase : $('#AjaxBlockExpirySelect').val.toLowerCase; var blockReason = ($('#AjaxBlockReasonSelect').val == 'other') ? $('#AjaxBlockCustomReason').val : $('#AjaxBlockReasonSelect').val + (($('#AjaxBlockCustomReason').val.trim !== ) ? ':' + $('#AjaxBlockCustomReason').val : ); // Creates the base block object var config = { action: 'block', user: usr, expiry: blockDuration, reason: blockReason, bot: true, token: token };                               if ($('#accountCreation').is(':checked')) config.nocreate = 1; if ($('#autoBlock').is(':checked')) config.autoblock = 1; if (!$('#disableWall').is(':checked')) config.allowusertalk = 1; if ($('#overrideBlock').is(':checked')) config.reblock = 1; callAPI(config, 'POST', function(d) { // Does the actual blocking                                   if (!d.error) {                                        mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + usr + ' has been blocked successfully. (<span class="undo-AjaxBlock" style="color:#3cd7fa; cursor: pointer;" data-usr="' + usr + '">undo )</li>');                                       mainRoom.kick({ name: usr });                                       $('.undo-AjaxBlock').last.click(function(e) { callAPI({ // Does the actual unblocking                                               action: 'unblock',                                                user: $(this).attr('data-usr'),                                                reason: 'undo',                                                token: token                                            }, 'POST', function {                                                mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + usr + ' has been unblocked successfully.</li>');                                            }); });                                   } else {                                        mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">Block for ' + usr + ' failed: ' + d.error.code + '</li>');                                    }                                }); $('#ajaxBlockModal').closeModal; // Close the modal }                       }, { // Cancel button id: 'ajaxBlockCancel', defaultButton: true, message: 'Cancel', handler: function { $('#ajaxBlockModal').closeModal; }                       }]                    });                });            }        }, function { $(this).children('.inlinemod').remove; });       mainRoom.viewDiscussion.chatUL.children.last.children('.message').hover(function { thistarget = this; username = $(thistarget).parent.attr("data-user"); timestamp = $(thistarget).attr('msg-time'); message = $(thistarget).attr('msg-source'); $(thistarget).append('<span class="inline-quote" style="color: #3cd7fa !important; cursor:pointer;"> Quote '); $(thistarget).children('.inline-quote').click(function(e) {               if (e.shiftKey) {                    $('.message textarea').val($('.message textarea').val + '[' + timestamp + '] ' + username + ": " + message.replace(/^\/me/, "* " + username) + '\n');                } else {                    $('.message textarea').val('[' + timestamp + '] ' + username + ": " + message.replace(/^\/me/, "* " + username) + '\n');                    scrollToBottom;                }                $(".message textarea").focus;            }); }, function { $(this).children('.inline-quote').remove; });   } }); //Bind function to chat updates setTimeout(function {   mainRoom.model.chats.bind('afteradd', ChatPlugins.features.modIcons.script, mainRoom.viewDiscussion); }, 15000); /* PrivateChatList responsive design */ // The actual thing that calculates the height and crap var calcRail = function { var nodes = [].slice.call(document.querySelectorAll('#Rail > *:not(#WikiChatList)')); var height = 0; nodes.forEach(function(el) {       height = height + (el.scrollHeight - 1);    }); if (height > window.innerHeight / 2) height = window.innerHeight / 2; document.getElementById('WikiChatList').style.height = (document.getElementById('Rail').offsetHeight - height - 70) + 'px'; }; // Bind function to window resize $(window).resize(calcRail); // select the target node var targets = [].slice.call(document.querySelectorAll('#PrivateChatList, #WikiChatList')); // create an observer instance var observer = new MutationObserver(function(mutations) {   mutations.forEach(function(mutation) { if (mutation.type == 'attributes' && mutation.attributeName == 'style') return; calcRail; }); }); // configuration of the observer: var config = { attributes: true, childList: true, characterData: true, subtree: true }; // pass in the target node, as well as the observer options targets.forEach(function(target) {   observer.observe(target, config); }); // execute all that observer crap when the window loads $(function {   mw.util.addCSS('#PrivateChatList {max-height: 40vh !important; overflow-y: auto;} #WikiChatList {overflow-y: auto; max-height: 666vh;} #Rail {overflow: hidden !important;}');    calcRail;    var interval = setInterval(calcRail, 200);    // clear the interval after the window is fully loaded    setTimeout(function { clearInterval(interval); }, 15000); }); // BlockList $(function {   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat' || $('#ignore-list').length) return;    if (localStorage.getItem('chat-blocked') === null) localStorage.setItem('chat-blocked', '[]');    $('head').append('<style id="ignore-list" />');    var updateIgnore = function {        var usrs = JSON.parse(localStorage.getItem('chat-blocked'));        var html = '#Chat_' + mainRoom.roomId + ' li[data-user="' + usrs.join('"],li[data-user="') + '"]{height:0 !important;min-height: 0 !important;overflow:hidden !important;display:none !important;padding:0 !important;margin:0 !important;}#Chat_' + mainRoom.roomId + '  li[data-user="' + usrs.join('"] .username,li[data-user="') + '"] *{height:0 !important;min-height: 0 !important;overflow:hidden !important;display:none !important;padding:0 !important;margin:0 !important;}';        $('#ignore-list').html(html);    };    if (localStorage.getItem('chat-blocked')) updateIgnore; $('[name="message"]').keypress(function(e) {       if (e.which == 13) {            var val = this.value;            if (/^(!|\/|\\)blocklist/i.test(val)) {                this.value = ;                mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">Blocked users: ' + JSON.parse(localStorage.getItem('chat-blocked')).join(', ').replace(/, (?!.*, )/, ', and ') + '.</li>');                mainRoom.viewDiscussion.scrollToBottom;            } else if (/^(!|\/|\\)block/i.test(val)) {                this.value = ;                var toBlock = val.slice(7).trim;                var arr = JSON.parse(localStorage.getItem('chat-blocked'));                var idx = arr.indexOf(toBlock);                if (idx === -1) {                    arr.push(toBlock);                    localStorage.setItem('chat-blocked', JSON.stringify(arr));                    updateIgnore; mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + toBlock + ' Has been blocked. Blocked users: ' + JSON.parse(localStorage.getItem('chat-blocked')).join(', ').replace(/, (?!.*, )/, ', and ') + '.</li>'); mainRoom.viewDiscussion.scrollToBottom; } else { mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + toBlock + ' Is already blocked. Blocked users: ' + JSON.parse(localStorage.getItem('chat-blocked')).join(', ').replace(/, (?!.*, )/, ', and ') + '.</li>'); mainRoom.viewDiscussion.scrollToBottom; }           } else if (/^(!|\/|\\)unblock/i.test(val)) { this.value = ''; var toUnblock = val.slice(9).trim; var array = JSON.parse(localStorage.getItem('chat-blocked')); var index = array.indexOf(toUnblock); if (index > -1) { array.splice(index, 1); localStorage.setItem('chat-blocked', JSON.stringify(array)); updateIgnore; mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + toUnblock + ' Has been unblocked. Blocked users: ' + JSON.parse(localStorage.getItem('chat-blocked')).join(', ').replace(/, (?!.*, )/, ', and ') + '.</li>'); mainRoom.viewDiscussion.scrollToBottom; } else { mainRoom.viewDiscussion.chatUL.append('<li class="inline-alert">' + toUnblock + ' Isn\'t blocked; can\'t unblock.</li>'); mainRoom.viewDiscussion.scrollToBottom; }           }        }    }); });