User:MarshMelon/common.js

// time $.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 (m === null && s.toLowerCase.match(/infinity|never|infinite|indefinite|forever/i) !== null) { return 31536000000; } else if (m === null) { window.wasDefault = true; return window.defCBanDuration || 86400; // null } else 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) { window.wasDefault = true; return window.defCBanDuration || 86400; // equal to 0 seconds } else { return timeCount; }   } else { // no matches found - use default time window.wasDefault = true; return window.defCBanDuration || 86400; } }; Notification.requestPermission; var afterChat = function (chat) { var t = chat.attributes.text, n = chat.attributes.name, isInline = chat.attributes.isInlineAlert || false, context = mainRoom.viewDiscussion.chatUL.children.last; if ( / has been destabilized by /.test(t) && isInline && wgCityId == "621556") { var userr = t.match(/\[\[User:.*?\|(.*?)]]/)[1]; context.append('(Quick Ban)'); context.find('.quick-ban').click(function {           var time = prompt('Ban length', '20 minutes');            var reason = prompt('Ban reason', 'Misbehaving in chat');			if (!time || !reason) return;            mainRoom.socket.send(new models.BanCommand({                userToBan: userr,                 time: $.time(time),                 reason: reason            }).xport);        }); // Play the sound. $(' ', {           id: 'ping',            src: PING_SOUND,            autoplay: true        }).appendTo('body'); // Display desktop notifications. if (Notification.permission === 'granted') { new Notification(userr + " was kick'd!", {               body: 'Ban them quick man!',                icon: mainRoom.model.users.findByName(userr) ? mainRoom.model.users.findByName(userr).attributes.avatarSrc.slice(0, -2) + '150' : ''            }); }   } }; var interval = setInterval(function {    if (window.mainRoom && window.mainRoom.model && mainRoom.model.chats && mainRoom.model.chats.bind) {        mainRoom.model.chats.bind('afteradd', afterChat);        clearInterval(interval);    } }, 250);