Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Quick Mod Tools
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Quick access to the chatmod tools
- // @author http://dev.wikia.com/wiki/QuickModTools
- // @match http://*/*
- // @grant none
- // @include http://elderscrolls.wikia.com/wiki/Special:Chat
- // @include http://tl.elderscrolls.wikia.com/wiki/Special:Chat
- // @include http://kallenbearrp.wikia.com/wiki/Special:Chat
- // @include http://terraria.wikia.com/wiki/Special:Chat
- // ==/UserScript==
- /* jshint -W097 */
- 'use strict';
- // Your code here...
- //
- // BAN LENGTH TABLE
- //
- // "7200" = 2 hours
- // "43200" = 12 hours
- // "86400" = 1 day
- // "259200" = 3 days
- // "604800" = 1 week
- // "1209600" = 2 weeks
- // "2592000" = 1 month
- // "7776000" = 3 months
- // "15552000" = 6 months
- // "31536000" = 1 year
- // "31536000000" = infinite
- window.QuickModTools = {
- quickreasons: [
- "Sockpuppet",
- "Spamming",
- "Trolling",
- "Repeated all caps",
- "Drama",
- "Raid",
- "Chat dating",
- "Under-aged user",
- "Misbehaving in chat",
- "Account no longer in use"
- ],
- defbanreason: "Misbehaving in chat",
- defbanlength: "31536000000"
- };
- if ($("body").hasClass("chat-mod")) {
- /* ================================================== *\
- # create objects
- \* ================================================== */
- QuickModTools = typeof QuickModTools !== "undefined" ? QuickModTools : {};
- QuickModTools.defbanreason = typeof QuickModTools.defbanreason === "string" ? QuickModTools.defbanreason : mw.config.get("wgMessages")["chat-log-reason-banadd"]; // quick reasons
- QuickModTools.quickreasons = $.isArray(QuickModTools.quickreasons) ? QuickModTools.quickreasons : []; // quick reasons
- QuickModTools.defbanlength = $.isNumeric(QuickModTools.defbanlength) ? QuickModTools.defbanlength : 259200; // default ban length
- QuickModTools.storage = ""; // user referred to
- QuickModTools.fn = typeof QuickModTools.fn !== "undefined" ? QuickModTools.fn : {};
- /* ================================================== *\
- # functions
- \* ================================================== */
- QuickModTools.fn.kick = function() {
- // kick user
- mainRoom.kick({
- name: QuickModTools.storage
- })
- }
- QuickModTools.fn.ban = function(time, reason) {
- QuickModTools.fn.closeMenu();
- var a = new models.BanCommand({
- userToBan: QuickModTools.storage,
- time: time,
- reason: reason
- });
- mainRoom.socket.send(a.xport());
- $('#specialmodmodule input[type="text"]').val("");
- }
- QuickModTools.fn.openMenu = function(user) {
- $("#specialmodmodule .name").html(user);
- QuickModTools.storage = user;
- $("#specialmodmodule").show();
- }
- QuickModTools.fn.closeMenu = function() {
- $("#specialmodmodule").hide();
- }
- QuickModTools.fn.time = function(s) {
- var s = s.toLowerCase(),
- time = {},
- i18n = {
- second: 1,
- minute: 60,
- hour: 3600,
- day: 86400,
- week: 604800,
- month: 2592000,
- year: 31536000
- },
- m = s.match(/\d+ (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]) * i18n[a[1]];
- }
- var timeCount = 0;
- for (var i in time) {
- timeCount += time[i];
- }
- if (timeCount == 0) {
- return QuickModTools.defbanlength; // equal to 0 seconds
- } else {
- return timeCount;
- }
- } else {
- // no matches found - use default time
- return QuickModTools.defbanlength;
- }
- }
- QuickModTools.fn.glitchPatrol = function(node) {
- if ($(node).find(".message").text().search(/[\u0300-\u036f]/) > -1) {
- // contains glitchy text
- var firstNotContinued = QuickModTools.fn.firstNotContinued(node);
- console.info({node: node, firstNotContinued: firstNotContinued});
- if (!$(firstNotContinued).hasClass("quick-mod-tools-glitchy")) {
- var img = $('<img />').attr({
- src: "http://www.famfamfam.com/lab/icons/mini/icons/icon_alert.gif",
- title: "Notice! This message contains \"glitchy text\". Characters of this sort are usually posted for spamming."
- }).css({
- cursor: "help"
- });
- $(firstNotContinued).addClass("quick-mod-tools-glitchy").find(".username").append(img);
- }
- }
- }
- QuickModTools.fn.firstNotContinued = function(node) {
- if ($(node).hasClass("continued")) {
- return $(node).prevAll("li:not(.continued):first");
- } else {
- return $(node);
- }
- }
- /* ================================================== *\
- # events and markup modifiers
- \* ================================================== */
- // on right click - open module if right click && ctrl && user != mod
- $("#WikiaPage").on("contextmenu", function(e) {
- if (e.ctrlKey) {
- var msg = false;
- if (typeof $(e.target).attr("data-user") === "string" && $(e.target).parents().eq(1).hasClass("Chat")) {
- // target is the 'li' element itself
- msg = $(e.target);
- } else if ($(e.target).parents(".Chat > ul > [data-user]").length == 1) {
- // a child/descendant of a message
- msg = $(e.target).parents(".Chat > ul > [data-user]");
- }
- if (msg) {
- var user = mainRoom.model.users.findByName($(msg).attr("data-user"));
- if (user) {
- if (!user.attributes.isModerator) {
- e.preventDefault();
- QuickModTools.fn.openMenu(user.attributes.name);
- }
- }
- }
- }
- });
- // when a new messge is sent - check for "glitchy characters"
- // note! consider using mainRoom.model.chats.models[ LAST ].attributes instead, and also, only apply on the non-continue message and don't apply multiple times
- QuickModTools.glitchyObs = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- Array.prototype.forEach.call(mutation.addedNodes, function(node) {
- if (node.nodeType == 1) {
- // an element node
- if (typeof $(node).attr("data-user") === "string" && $(node).parents().eq(1).hasClass("Chat")) {
- // check if contains glitchy text
- QuickModTools.fn.glitchPatrol(node);
- }
- }
- });
- });
- });
- QuickModTools.glitchyObs.observe(document.querySelector("#WikiaPage"), {
- childList: true,
- subtree: true
- });
- // get the default ban module, and once loaded, update the quick tools interface
- $.getJSON(window.wgScript + "?action=ajax&rs=ChatAjax&method=BanModal", function(data) {
- var a = data.template.split('<select name=\"expires\">')[1].split("</select>")[0].replace(/<\/option>/g, "</option>\n").replace(/<option value=\'/g, '\t\t<li class="specialmodmodule-ban-li specialmodmodule-label" data-ban="').replace(/\'>/g, "\">").replace(/<\/option>/g, "</li>"),
- b = '<div id="specialmodmodule">\n' +
- '\t<p>User inspected:<br /> <span class="name" style="font-family: monotype, arial, sans, sans serif, serif; color: #cc0000;"></span></p>\n' +
- '\t<p>Kicks:</p>\n' +
- '\t<ul id="specialmodmodule-kick">\n' +
- '\t\t<li class="specialmodmodule-label">Kick</li>\n' +
- '\t</ul>\n' +
- '\t<p>Bans:</p>\n' +
- '\t<ul id="specialmodmodule-ban">\n' +
- '\t\t<li id="specialmodmodule-ban-open" class="specialmodmodule-ban-li specialmodmodule-label">Open module</li>' +
- '\t\t<li id="specialmodmodule-ban-time" class="specialmodmodule-dontclose specialmodmodule-textbox"><input type="text" placeholder="Custom length" title="A custom length for the ban" /></li>\n' +
- '\t\t<li id="specialmodmodule-ban-reason" class="specialmodmodule-dontclose specialmodmodule-textbox"><input type="text" placeholder="Custom reason" title="A custom summary for the ban" /></li>\n' +
- a + "\n" +
- '\t</ul>\n' +
- '</div>';
- $("body").prepend(b);
- // check for custom quick reasons. if none exist, use the default
- if (QuickModTools.quickreasons.length > 0) {
- var quickreasons = '';
- for (var i in QuickModTools.quickreasons) {
- quickreasons += '\n\t<li>' + QuickModTools.quickreasons[i] + '</li>';
- }
- $("body").append('<ul id="specialmodmodule-quickreason">' + quickreasons + '\n</ul>');
- } else {
- $("body").append(
- '<ul id="specialmodmodule-quickreason">\n' +
- '\t<li>Swearing</li>\n' +
- '\t<li>Spamming/flooding</li>\n' +
- '\t<li>Causing troubles</li>\n' +
- '\t<li>Inappropriate talking</li>\n' +
- '\t<li>Bullying</li>\n' +
- '</ul>'
- );
- }
- // kick button
- $("#specialmodmodule ul#specialmodmodule-kick > li").click(function() {
- QuickModTools.fn.kick();
- });
- // buttons for not closing the menu
- $("#specialmodmodule li:not(.specialmodmodule-dontclose)").click(function() {
- QuickModTools.fn.closeMenu();
- });
- // reveal quick reasons list
- $("#specialmodmodule-ban [data-ban]").mouseover(function() {
- $("#specialmodmodule-quickreason").appendTo(this);
- });
- // banning via the lists
- $("#specialmodmodule .specialmodmodule-ban-li").click(function(e) {
- if (typeof $(this).attr("data-ban") == "undefined") {
- mainRoom.ban({
- name: QuickModTools.storage
- });
- } else {
- QuickModTools.fn.ban(
- $(this).attr("data-ban"),
- e.target.parentNode.id == "specialmodmodule-quickreason" ?
- e.target.innerText : // quick reason
- ( // reason from input
- $("#specialmodmodule-ban-reason input").val().length == 0 ?
- $("#specialmodmodule-ban-reason input").attr("placeholder") : // valid input
- $("#specialmodmodule-ban-reason input").val() // invalid input - use default message
- )
- );
- }
- });
- // close interface when pressing the chat's main area
- $("section#WikiaPage").mousedown(function() {
- QuickModTools.fn.closeMenu();
- });
- // custom ban length textbox
- $("#specialmodmodule-ban-time input").keydown(function(e) {
- if (e.keyCode == 13) {
- QuickModTools.fn.ban(
- QuickModTools.fn.time($(this).val()),
- $("#specialmodmodule-ban-reason input").val().length > 0 ? $$("#specialmodmodule-ban-reason input").val() : QuickModTools.defbanreason
- );
- } else if (e.keyCode == 9) {
- // jump to reason textbox on tab
- $(this).parent().next().find("input").select();
- }
- });
- // custom ban reason textbox
- $("#specialmodmodule-ban-reason input").keydown(function(e) {
- if (e.keyCode == 13) {
- QuickModTools.fn.ban(
- QuickModTools.fn.time($("#specialmodmodule-ban-time input").val()),
- $(this).val().length > 0 ? $(this).val() : QuickModTools.defbanreason
- );
- }
- });
- });
- /* ================================================== *\
- # css
- \* ================================================== */
- mw.util.addCSS(
- '#specialmodmodule {\n' +
- '\tdisplay: none;\n' +
- '\tposition: fixed;\n' +
- '\ttop: 2px;\n' +
- '\tleft: 2px;\n' +
- '\tz-index: 999999999999;\n' +
- '\twidth: 130px;\n' +
- '\tpadding: 0px 1px;\n' +
- '\tbackground: #fafafa;\n' +
- '\tborder: 1px solid #dddddd;\n' +
- '\t-moz-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '\t-webkit-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '\tbox-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '\tfont-size: 12px;\n' +
- '\tline-height: 12px;\n' +
- '\tcolor: #333333;\n' +
- '}\n' +
- '#specialmodmodule p {\n' +
- '\tmargin: 0px;\n' +
- '\tpadding: 3px;\n' +
- '\tfont-weight: bold;\n' +
- '}\n' +
- '#specialmodmodule ul {\n' +
- '\tmargin: 0px;\n' +
- '}\n' +
- '#specialmodmodule ul > li {\n' +
- '\tmargin: 0px;\n' +
- '\tpadding: 2px 2px 2px 5px;\n' +
- '\tlist-style-type: none;\n' +
- '}\n' +
- '#specialmodmodule ul > li:hover {\n' +
- '\tbackground: rgba(70,130,180,0.4);\n' +
- '}\n' +
- '#specialmodmodule li.specialmodmodule-label::before {\n' +
- '\tcontent: "> ";\n' +
- '\tfont-size: 10px;\n' +
- '}\n' +
- '#specialmodmodule ul > li:not(:last-child) {\n' +
- '\tmargin-top: 1px;\n' +
- '}\n' +
- '#specialmodmodule input[type="text"] {\n' +
- '\theight: 12px;\n' +
- '\tmargin: 0px;\n' +
- '\twidth: 100px;\n' +
- '\tvertical-align: middle;\n' +
- '\tfont-size: 12px;\n' +
- '}\n' +
- '#specialmodmodule ul > li:not(.specialmodmodule-textbox) {\n' +
- '\tposition: relative;\n' +
- '\tcursor: hand;\n' +
- '\tcursor: pointer;\n' +
- '}' +
- '#specialmodmodule-ban [data-ban]:hover ul {\n' +
- '\tdisplay: block;\n' +
- '}\n' +
- '#specialmodmodule-quickreason {\n' +
- '\twidth: 180px;\n' +
- '\tdisplay: none;\n' +
- '\tposition: absolute;\n' +
- '\ttop: 0;\n' +
- '\tleft: 130px;\n' +
- '\tbackground: #fafafa;\n' +
- '\tborder: 1px solid #dddddd;\n' +
- '\t-moz-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '\t-webkit-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '\tbox-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
- '}\n' +
- '#specialmodmodule-quickreason li:hover {\n' +
- '\tbackground: rgba(255,255,255,0.2);\n' +
- '}'
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement