Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Here is the full code for the chat toggle buttons script. Feel free to review/compress it yourself; good internet security is important!
- // Original code by /u/RenaKunisaki with /u/smog_alado's excellent notes
- // Spam button by /u/SRS-SRSLY. Chat Scroll Improvement by /u/schrobby
- // Dynamic regular expression and "democracy mode" by /u/red_agent
- // Compressed by http://javascriptcompressor.com.
- // Passes http://www.jshint.com on default settings
- /* global $ : false, CurrentChat : false*/
- (function(){
- "use_strict";
- // EDIT THIS IF YOU WANT TO BLOCK SOMETHING ELSE
- var BLOCKED_WORDS = [
- "left",
- "right",
- "up",
- "down",
- "start",
- "select",
- "a",
- "b",
- "democracy",
- "anarchy"
- ];
- var command_regex_src = BLOCKED_WORDS.join("|");
- //Match exactly one of the commands
- var ANARCHY_REGEX = new RegExp("^(" + command_regex_src + ")$", "i");
- //Match a sequence of one or more commands optionaly followed by a number 0-9
- //This includes things like `up2left4` or `start9`
- var DEMOCRACY_REGEX = new RegExp("^((" + command_regex_src + ")\\d?)+$", "i");
- //EDIT THIS TO CHOOSE THE FILTERING MODE
- var FILTER_REGEX = DEMOCRACY_REGEX;
- //Create buttons to toggle the command and non-command chats on and off.
- var CHAT_BUTTON = $("ul.segmented_tabs li a").first();
- $("<li><a class='CommandsToggle'>Commands</a><a class='ChatToggle'>Talk</a></li>").insertAfter(CHAT_BUTTON);
- // Reduce the width of the chat button by 71px.
- // This gives enough space for a spam button width 30px with 15px margins with an extra pixel of wiggle room
- CHAT_BUTTON.css("width", CHAT_BUTTON.width() - 71);
- $(".CommandsToggle").click(function () {
- $(this).toggleClass("selected");
- $("#chat_line_list").toggleClass("showCmd");
- });
- $(".ChatToggle").click(function () {
- $(this).toggleClass("selected");
- $("#chat_line_list").toggleClass("showTalk");
- });
- // Simulate a click on ChatToggle, so starts in the "on" position
- $(".ChatToggle").click();
- CurrentChat.line_buffer = 800;
- //This part creates a CSS rule
- //that hides all chat messages by default
- $(
- " <style type='text/css' > " +
- " .segmented_tabs li li a.CommandsToggle { " +
- " width: 50px; " +
- " padding-left: 0px; " +
- " padding-top: 0; " +
- " height: 8px; " +
- " line-height: 115%; " +
- " } " +
- " " +
- " .segmented_tabs li li a.ChatToggle { " +
- " width: 35px; " +
- " padding-left: 15px; " +
- " padding-top: 0; " +
- " height: 8px; " +
- " line-height: 115%; " +
- " } " +
- " " +
- " #chat_line_list li { display:none } " + // hide new, uncategorized messages
- " #chat_line_list.showCmd li.cCmd, " + // show messages that we know we want to read
- " #chat_line_list.showTalk li.cTalk " +
- " { " +
- " display:inline; " +
- " } " +
- " </style> "
- ).appendTo("head");
- //Update the chat status periodically
- setInterval(function () {
- // Thus, run for each chat box item,
- $('#chat_line_list li').each(function () {
- var cLine = $(this),
- cText = cLine.find(".chat_line").text();
- //TODO: WHY ARE WE TESTING `cText &&` here?
- if (cText && !cText.trim().match(FILTER_REGEX)) {
- cLine.addClass("cTalk");
- } else {
- cLine.addClass("cCmd");
- }
- });
- //TODO: WHAT DOES THIS LINE DO? SCROLL TO THE BOTTOM?
- if (CurrentChat.currently_scrolling) { CurrentChat.scroll_chat(); }
- }, 100); // <- number of miliseconds between updates
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement