MediaWiki:!ban/code.js

/* * !ban w:c:dev:!ban * * Allows to block from chat without using the usual ban modal * Syntax: !ban USER NAME for BAN DURATION because BAN REASON * @author: w:User:Dorumin */

// Taken from w:c:dev:MediaWiki:QuickModTools/code.js. $.time = function(s) { var time = {}, i18n = { second: 1, minute: 60, hour: 3600, day: 86400, week: 604800, month: 2592000, year: 31536000 },	m = s.toLowerCase.match(/(\d+|a) (second|minute|hour|day|week|month|year)/g); if ($.isArray(m)) { // found match(es) for (var i in m) { var a = m[i].split(" "); time[a[1]] = Number(a[0].replace('a', '1')) * i18n[a[1]]; }		var timeCount = 0; for (var i in time) { timeCount += time[i]; }		if (timeCount == 0) { return window.defCBanDuration || 86400; // equal to 0 seconds } else { return timeCount; }	} else { // no matches found - use default time return window.defCBanDuration || 86400; window.wasDefault = true; } };

function scrollToBottom { var chat = document.getElementById('Chat_' + mainRoom.roomId); chat.scrollTop = chat.scrollHeight; }

$(function {   if (mw.config.get('wgCanonicalSpecialPageName') != 'Chat' || !mainRoom.userMain.attributes.isModerator) return;    $('[name="message"]').keydown(function(e) { if (e.which == 13 && $(this).val.substr(0, 4) == '!ban' ) { var t = $(this).val.slice(5).split(/ for | because /gi); if ( t.length < 3 ) { t.push(t[1]); t[1] = ''; }           if ( t[0] == mw.config.get('wgUserName') ) { mainRoom.viewDiscussion.chatUL.append('You can\'t ban yourself.'); scrollToBottom; }           mainRoom.socket.send(new models.BanCommand({ userToBan: t[0], time: $.time(t[1]), reason: t[2] }).xport); if ( wasDefault ) { mainRoom.viewDiscussion.chatUL.append('Ban duration was invalid or undefined; default duration was used.'); wasDefault = false; }           $(this).val(''); }   }); });