Advertisement
RenzXVI

Quick Mod Tools

Aug 10th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Quick Mod Tools
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Quick access to the chatmod tools
  6. // @author       http://dev.wikia.com/wiki/QuickModTools
  7. // @match        http://*/*
  8. // @grant        none
  9. // @include      http://elderscrolls.wikia.com/wiki/Special:Chat
  10. // @include      http://tl.elderscrolls.wikia.com/wiki/Special:Chat
  11. // @include      http://kallenbearrp.wikia.com/wiki/Special:Chat
  12. // @include      http://terraria.wikia.com/wiki/Special:Chat
  13. // ==/UserScript==
  14. /* jshint -W097 */
  15. 'use strict';
  16.  
  17. // Your code here...
  18. //
  19. // BAN LENGTH TABLE
  20. //
  21. // "7200" = 2 hours
  22. // "43200" = 12 hours
  23. // "86400" = 1 day
  24. // "259200" = 3 days
  25. // "604800" = 1 week
  26. // "1209600" = 2 weeks
  27. // "2592000" = 1 month
  28. // "7776000" = 3 months
  29. // "15552000" = 6 months
  30. // "31536000" = 1 year
  31. // "31536000000" = infinite
  32.  
  33. window.QuickModTools = {
  34.     quickreasons: [
  35.         "Sockpuppet",
  36.         "Spamming",
  37.         "Trolling",
  38.         "Repeated all caps",
  39.         "Drama",
  40.         "Raid",
  41.         "Chat dating",
  42.         "Under-aged user",
  43.         "Misbehaving in chat",
  44.         "Account no longer in use"
  45.     ],
  46.     defbanreason: "Misbehaving in chat",
  47.     defbanlength: "31536000000"
  48. };
  49.  
  50. if ($("body").hasClass("chat-mod")) {
  51.  
  52. /* ================================================== *\
  53.     # create objects
  54. \* ================================================== */
  55.  
  56. QuickModTools = typeof QuickModTools !== "undefined" ? QuickModTools : {};
  57. QuickModTools.defbanreason = typeof QuickModTools.defbanreason === "string" ? QuickModTools.defbanreason : mw.config.get("wgMessages")["chat-log-reason-banadd"]; // quick reasons
  58. QuickModTools.quickreasons = $.isArray(QuickModTools.quickreasons) ? QuickModTools.quickreasons : []; // quick reasons
  59. QuickModTools.defbanlength = $.isNumeric(QuickModTools.defbanlength) ? QuickModTools.defbanlength : 259200; // default ban length
  60. QuickModTools.storage = ""; // user referred to
  61. QuickModTools.fn = typeof QuickModTools.fn !== "undefined" ? QuickModTools.fn : {};
  62.  
  63. /* ================================================== *\
  64.     # functions
  65. \* ================================================== */
  66. QuickModTools.fn.kick = function() {
  67.     // kick user
  68.     mainRoom.kick({
  69.         name: QuickModTools.storage
  70.     })
  71. }
  72. QuickModTools.fn.ban = function(time, reason) {
  73.     QuickModTools.fn.closeMenu();
  74.     var a = new models.BanCommand({
  75.         userToBan: QuickModTools.storage,
  76.         time: time,
  77.         reason: reason
  78.     });
  79.     mainRoom.socket.send(a.xport());
  80.     $('#specialmodmodule input[type="text"]').val("");
  81. }
  82. QuickModTools.fn.openMenu = function(user) {
  83.     $("#specialmodmodule .name").html(user);
  84.     QuickModTools.storage = user;
  85.     $("#specialmodmodule").show();
  86. }
  87. QuickModTools.fn.closeMenu = function() {
  88.     $("#specialmodmodule").hide();
  89. }
  90.  
  91. QuickModTools.fn.time = function(s) {
  92.     var s = s.toLowerCase(),
  93.         time = {},
  94.         i18n = {
  95.             second: 1,
  96.             minute: 60,
  97.             hour: 3600,
  98.             day: 86400,
  99.             week: 604800,
  100.             month: 2592000,
  101.             year: 31536000
  102.         },
  103.         m = s.match(/\d+ (second|minute|hour|day|week|month|year)/g);
  104.     if ($.isArray(m)) {
  105.         // found match(es)
  106.         for (var i in m) {
  107.             var a = m[i].split(" ");
  108.             time[a[1]] = Number(a[0]) * i18n[a[1]];
  109.         }
  110.         var timeCount = 0;
  111.         for (var i in time) {
  112.             timeCount += time[i];
  113.         }
  114.         if (timeCount == 0) {
  115.             return QuickModTools.defbanlength; // equal to 0 seconds
  116.         } else {
  117.             return timeCount;
  118.         }
  119.     } else {
  120.         // no matches found - use default time
  121.         return QuickModTools.defbanlength;
  122.     }
  123. }
  124.  
  125. QuickModTools.fn.glitchPatrol = function(node) {
  126.     if ($(node).find(".message").text().search(/[\u0300-\u036f]/) > -1) {
  127.         // contains glitchy text
  128.         var firstNotContinued = QuickModTools.fn.firstNotContinued(node);
  129.         console.info({node: node, firstNotContinued: firstNotContinued});
  130.         if (!$(firstNotContinued).hasClass("quick-mod-tools-glitchy")) {
  131.             var img = $('<img />').attr({
  132.                     src: "http://www.famfamfam.com/lab/icons/mini/icons/icon_alert.gif",
  133.                     title: "Notice! This message contains \"glitchy text\". Characters of this sort are usually posted for spamming."
  134.                 }).css({
  135.                     cursor: "help"
  136.                 });
  137.             $(firstNotContinued).addClass("quick-mod-tools-glitchy").find(".username").append(img);
  138.         }
  139.     }
  140. }
  141.  
  142. QuickModTools.fn.firstNotContinued = function(node) {
  143.     if ($(node).hasClass("continued")) {
  144.         return $(node).prevAll("li:not(.continued):first");
  145.     } else {
  146.         return $(node);
  147.     }
  148. }
  149.  
  150.  
  151. /* ================================================== *\
  152.     # events and markup modifiers
  153. \* ================================================== */
  154.  
  155. // on right click - open module if right click && ctrl && user != mod
  156. $("#WikiaPage").on("contextmenu", function(e) {
  157.     if (e.ctrlKey) {
  158.         var msg = false;
  159.         if (typeof $(e.target).attr("data-user") === "string" && $(e.target).parents().eq(1).hasClass("Chat")) {
  160.             // target is the 'li' element itself
  161.             msg = $(e.target);
  162.         } else if ($(e.target).parents(".Chat > ul > [data-user]").length == 1) {
  163.             // a child/descendant of a message
  164.             msg = $(e.target).parents(".Chat > ul > [data-user]");
  165.         }
  166.         if (msg) {
  167.             var user = mainRoom.model.users.findByName($(msg).attr("data-user"));
  168.             if (user) {
  169.                 if (!user.attributes.isModerator) {
  170.                     e.preventDefault();
  171.                     QuickModTools.fn.openMenu(user.attributes.name);
  172.                 }
  173.             }
  174.         }
  175.     }
  176. });
  177.  
  178. // when a new messge is sent - check for "glitchy characters"
  179. // 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
  180. QuickModTools.glitchyObs = new MutationObserver(function(mutations) {
  181.     mutations.forEach(function(mutation) {
  182.         Array.prototype.forEach.call(mutation.addedNodes, function(node) {
  183.             if (node.nodeType == 1) {
  184.                 // an element node
  185.                 if (typeof $(node).attr("data-user") === "string" && $(node).parents().eq(1).hasClass("Chat")) {
  186.                     // check if contains glitchy text
  187.                     QuickModTools.fn.glitchPatrol(node);
  188.                 }
  189.             }
  190.         });
  191.     });
  192. });
  193. QuickModTools.glitchyObs.observe(document.querySelector("#WikiaPage"), {
  194.     childList: true,
  195.     subtree: true
  196. });
  197.  
  198. // get the default ban module, and once loaded, update the quick tools interface
  199. $.getJSON(window.wgScript + "?action=ajax&rs=ChatAjax&method=BanModal", function(data) {
  200.     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>"),
  201.         b = '<div id="specialmodmodule">\n' +
  202.             '\t<p>User inspected:<br />&nbsp;<span class="name" style="font-family: monotype, arial, sans, sans serif, serif; color: #cc0000;"></span></p>\n' +
  203.             '\t<p>Kicks:</p>\n' +
  204.             '\t<ul id="specialmodmodule-kick">\n' +
  205.                 '\t\t<li class="specialmodmodule-label">Kick</li>\n' +
  206.             '\t</ul>\n' +
  207.             '\t<p>Bans:</p>\n' +
  208.             '\t<ul id="specialmodmodule-ban">\n' +
  209.                 '\t\t<li id="specialmodmodule-ban-open" class="specialmodmodule-ban-li specialmodmodule-label">Open module</li>' +
  210.                 '\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' +
  211.                 '\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' +
  212.                 a + "\n" +
  213.             '\t</ul>\n' +
  214.         '</div>';
  215.     $("body").prepend(b);
  216.     // check for custom quick reasons. if none exist, use the default
  217.     if (QuickModTools.quickreasons.length > 0) {
  218.         var quickreasons = '';
  219.         for (var i in QuickModTools.quickreasons) {
  220.             quickreasons += '\n\t<li>' + QuickModTools.quickreasons[i] + '</li>';
  221.         }
  222.         $("body").append('<ul id="specialmodmodule-quickreason">' + quickreasons + '\n</ul>');
  223.     } else {
  224.         $("body").append(
  225.             '<ul id="specialmodmodule-quickreason">\n' +
  226.                 '\t<li>Swearing</li>\n' +
  227.                 '\t<li>Spamming/flooding</li>\n' +
  228.                 '\t<li>Causing troubles</li>\n' +
  229.                 '\t<li>Inappropriate talking</li>\n' +
  230.                 '\t<li>Bullying</li>\n' +
  231.             '</ul>'
  232.         );
  233.     }
  234.     // kick button
  235.     $("#specialmodmodule ul#specialmodmodule-kick > li").click(function() {
  236.         QuickModTools.fn.kick();
  237.     });
  238.     // buttons for not closing the menu
  239.     $("#specialmodmodule li:not(.specialmodmodule-dontclose)").click(function() {
  240.         QuickModTools.fn.closeMenu();
  241.     });
  242.     // reveal quick reasons list
  243.     $("#specialmodmodule-ban [data-ban]").mouseover(function() {
  244.         $("#specialmodmodule-quickreason").appendTo(this);
  245.     });
  246.     // banning via the lists
  247.     $("#specialmodmodule .specialmodmodule-ban-li").click(function(e) {
  248.         if (typeof $(this).attr("data-ban") == "undefined") {
  249.             mainRoom.ban({
  250.                 name: QuickModTools.storage
  251.             });
  252.         } else {
  253.             QuickModTools.fn.ban(
  254.                 $(this).attr("data-ban"),
  255.                 e.target.parentNode.id == "specialmodmodule-quickreason" ?
  256.                     e.target.innerText : // quick reason
  257.                     ( // reason from input
  258.                         $("#specialmodmodule-ban-reason input").val().length == 0 ?
  259.                         $("#specialmodmodule-ban-reason input").attr("placeholder") : // valid input
  260.                         $("#specialmodmodule-ban-reason input").val() // invalid input - use default message
  261.                     )
  262.             );
  263.         }
  264.     });
  265.     // close interface when pressing the chat's main area
  266.     $("section#WikiaPage").mousedown(function() {
  267.         QuickModTools.fn.closeMenu();
  268.     });
  269.     // custom ban length textbox
  270.     $("#specialmodmodule-ban-time input").keydown(function(e) {
  271.         if (e.keyCode == 13) {
  272.             QuickModTools.fn.ban(
  273.                 QuickModTools.fn.time($(this).val()),
  274.                 $("#specialmodmodule-ban-reason input").val().length > 0 ? $$("#specialmodmodule-ban-reason input").val() : QuickModTools.defbanreason
  275.             );
  276.         } else if (e.keyCode == 9) {
  277.             // jump to reason textbox on tab
  278.             $(this).parent().next().find("input").select();
  279.         }
  280.     });
  281.     // custom ban reason textbox
  282.     $("#specialmodmodule-ban-reason input").keydown(function(e) {
  283.         if (e.keyCode == 13) {
  284.             QuickModTools.fn.ban(
  285.                 QuickModTools.fn.time($("#specialmodmodule-ban-time input").val()),
  286.                 $(this).val().length > 0 ? $(this).val() : QuickModTools.defbanreason
  287.             );
  288.         }
  289.     });
  290. });
  291.  
  292. /* ================================================== *\
  293.     # css
  294. \* ================================================== */
  295. mw.util.addCSS(
  296.     '#specialmodmodule {\n' +
  297.         '\tdisplay: none;\n' +
  298.         '\tposition: fixed;\n' +
  299.         '\ttop: 2px;\n' +
  300.         '\tleft: 2px;\n' +
  301.         '\tz-index: 999999999999;\n' +
  302.         '\twidth: 130px;\n' +
  303.         '\tpadding: 0px 1px;\n' +
  304.         '\tbackground: #fafafa;\n' +
  305.         '\tborder: 1px solid #dddddd;\n' +
  306.         '\t-moz-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  307.         '\t-webkit-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  308.         '\tbox-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  309.         '\tfont-size: 12px;\n' +
  310.         '\tline-height: 12px;\n' +
  311.         '\tcolor: #333333;\n' +
  312.     '}\n' +
  313.     '#specialmodmodule p {\n' +
  314.         '\tmargin: 0px;\n' +
  315.         '\tpadding: 3px;\n' +
  316.         '\tfont-weight: bold;\n' +
  317.     '}\n' +
  318.     '#specialmodmodule ul {\n' +
  319.         '\tmargin: 0px;\n' +
  320.     '}\n' +
  321.     '#specialmodmodule ul > li {\n' +
  322.         '\tmargin: 0px;\n' +
  323.         '\tpadding: 2px 2px 2px 5px;\n' +
  324.         '\tlist-style-type: none;\n' +
  325.     '}\n' +
  326.     '#specialmodmodule ul > li:hover {\n' +
  327.         '\tbackground: rgba(70,130,180,0.4);\n' +
  328.     '}\n' +
  329.     '#specialmodmodule li.specialmodmodule-label::before {\n' +
  330.         '\tcontent: "> ";\n' +
  331.         '\tfont-size: 10px;\n' +
  332.     '}\n' +
  333.     '#specialmodmodule ul > li:not(:last-child) {\n' +
  334.         '\tmargin-top: 1px;\n' +
  335.     '}\n' +
  336.     '#specialmodmodule input[type="text"] {\n' +
  337.         '\theight: 12px;\n' +
  338.         '\tmargin: 0px;\n' +
  339.         '\twidth: 100px;\n' +
  340.         '\tvertical-align: middle;\n' +
  341.         '\tfont-size: 12px;\n' +
  342.     '}\n' +
  343.     '#specialmodmodule ul > li:not(.specialmodmodule-textbox) {\n' +
  344.         '\tposition: relative;\n' +
  345.         '\tcursor: hand;\n' +
  346.         '\tcursor: pointer;\n' +
  347.     '}' +
  348.     '#specialmodmodule-ban [data-ban]:hover ul {\n' +
  349.         '\tdisplay: block;\n' +
  350.     '}\n' +
  351.     '#specialmodmodule-quickreason {\n' +
  352.         '\twidth: 180px;\n' +
  353.         '\tdisplay: none;\n' +
  354.         '\tposition: absolute;\n' +
  355.         '\ttop: 0;\n' +
  356.         '\tleft: 130px;\n' +
  357.         '\tbackground: #fafafa;\n' +
  358.         '\tborder: 1px solid #dddddd;\n' +
  359.         '\t-moz-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  360.         '\t-webkit-box-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  361.         '\tbox-shadow: 2px 3px 2px 1px rgba(0,0,0,0.4);\n' +
  362.     '}\n' +
  363.     '#specialmodmodule-quickreason li:hover {\n' +
  364.         '\tbackground: rgba(255,255,255,0.2);\n' +
  365.     '}'
  366. );
  367.  
  368.  
  369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement