User:Dorumin/chat.js

$('.User').first.before(' 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:embercastle:User:Dorumin/monobook.js',		'u:dev:AjaxBlock/code.js'	] });

// LightBlock (dw I won't block anyone unless its for testing) $(window).load(function {   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat') return;    if ( localStorage.getItem('chatBlocked') === null ) localStorage.setItem('chatBlocked', '[]');    if ( localStorage.getItem('chatBlocked') ) {        var usrs = JSON.parse(localStorage.getItem('chatBlocked')).join('"], li[data-user="');        mw.util.addCSS('li[data-user="' + usrs + '"] { display: none; }');    }    $('[name="message"]').keypress(function (e) { if (e.which == 13) { var val = this.value; if ( /^(!|\/|\\)blocklist/i.test(val) ) { this.value = ''; mainRoom.viewDiscussion.chatUL.append('Blocked users: ' + JSON.parse(localStorage.getItem('chatBlocked')).join(', ') + '.'); } else if ( /^(!|\/|\\)block/i.test(val) ) { this.value = ''; var toBlock = val.slice(7).trim; var arr = JSON.parse(localStorage.getItem('chatBlocked')); var idx = arr.indexOf(toBlock); if ( idx === -1) { arr.push(toBlock); localStorage.setItem('chatBlocked', JSON.stringify(arr)); mw.util.addCSS('li[data-user="' + toBlock + '"] { display: none; }'); mainRoom.viewDiscussion.chatUL.append('' + toBlock + ' Has been blocked. Blocked users: ' + JSON.parse(localStorage.getItem('chatBlocked')).join(', ') + '.'); } else { mainRoom.viewDiscussion.chatUL.append('' + toBlock + ' Is already blocked. Blocked users: ' + JSON.parse(localStorage.getItem('chatBlocked')).join(', ') + '.'); }           } else if ( /^(!|\/|\\)unblock/i.test(val) ) { this.value = ''; var toUnblock = val.slice(9).trim; var array = JSON.parse(localStorage.getItem('chatBlocked')); var index = array.indexOf(toUnblock); if (index > -1) { array.splice(index, 1); localStorage.setItem('chatBlocked', JSON.stringify(array)); mw.util.addCSS('li[data-user="' + toUnblock + '"] { display: block !important; }'); mainRoom.viewDiscussion.chatUL.append('' + toUnblock + ' Has been unblocked. Blocked users: ' + JSON.parse(localStorage.getItem('chatBlocked')).join(', ') + '.'); } else { mainRoom.viewDiscussion.chatUL.append('' + toUnblock + ' Isn\'t blocked; can\'t unblock.'); }           }        }    }); });

// 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('.Chat .username:after {content: "";} .Chat .message {display: block;} '); 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);    var icon = '';    for (var i in mainRoom.model.users.models) {        if (mainRoom.model.users.models[i].attributes.name == chat.attributes.name) {            if (mainRoom.model.users.models[i].attributes.isStaff) {                icon = ' '; } else if (mainRoom.model.users.models[i].attributes.isModerator) { icon = ' '; }           break; }   }    mainRoom.viewDiscussion.chatUL.children.last.children(".username").html(mainRoom.viewDiscussion.chatUL.children.last.children(".username").html + icon); if (wgUserGroups.indexOf("chatmoderator") >= 0 || wgUserGroups.indexOf("sysop") >= 0) { mainRoom.viewDiscussion.chatUL.children.last.children('.username').hover(           function {                var thistarget = this;                var username = $(thistarget).parent.attr("data-user");                if (username != wgUserName) {                    $(thistarget).append(' - \ Kick \ - 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(obj.expiryTimes, function(key, value) {                                   $expirySelect                                        .append($('  ') .attr('value', key) .text(value));                               }); $.each(obj.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('' + 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('' + usr + ' has been unblocked successfully.</li>');                                                }); });                                       } else {                                            mainRoom.viewDiscussion.chatUL.append('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(' 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);