Advertisement
Guest User

twitchplayspokemon chat toggle

a guest
Feb 18th, 2014
2,771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Here is the full code for the chat toggle buttons script. Feel free to review/compress it yourself; good internet security is important!
  2. // Original code by /u/RenaKunisaki with /u/smog_alado's excellent notes
  3. // Spam button by /u/SRS-SRSLY. Chat Scroll Improvement by /u/schrobby
  4. // Dynamic regular expression and "democracy mode" by /u/red_agent
  5. // Compressed by http://javascriptcompressor.com.
  6. // Passes http://www.jshint.com on default settings
  7.  
  8. /* global $ : false, CurrentChat : false*/
  9.  
  10. (function(){
  11.   "use_strict";
  12.  
  13.   // EDIT THIS IF YOU WANT TO BLOCK SOMETHING ELSE
  14.   var BLOCKED_WORDS = [
  15.       "left",
  16.       "right",
  17.       "up",
  18.       "down",
  19.       "start",
  20.       "select",
  21.       "a",
  22.       "b",
  23.       "democracy",
  24.       "anarchy"
  25.   ];
  26.  
  27.   var command_regex_src = BLOCKED_WORDS.join("|");
  28.  
  29.   //Match exactly one of the commands
  30.   var ANARCHY_REGEX = new RegExp("^(" + command_regex_src + ")$", "i");
  31.  
  32.   //Match a sequence of one or more commands optionaly followed by a number 0-9
  33.   //This includes things like `up2left4` or `start9`
  34.   var DEMOCRACY_REGEX = new RegExp("^((" + command_regex_src + ")\\d?)+$", "i");
  35.  
  36.   //EDIT THIS TO CHOOSE THE FILTERING MODE
  37.   var FILTER_REGEX = DEMOCRACY_REGEX;
  38.  
  39.  
  40.   //Create buttons to toggle the command and non-command chats on and off.
  41.   var CHAT_BUTTON   = $("ul.segmented_tabs li a").first();
  42.   $("<li><a class='CommandsToggle'>Commands</a><a class='ChatToggle'>Talk</a></li>").insertAfter(CHAT_BUTTON);
  43.  
  44.   // Reduce the width of the chat button by 71px.
  45.   // This gives enough space for a spam button width 30px with 15px margins with an extra pixel of wiggle room
  46.   CHAT_BUTTON.css("width", CHAT_BUTTON.width() - 71);
  47.  
  48.   $(".CommandsToggle").click(function () {
  49.       $(this).toggleClass("selected");
  50.       $("#chat_line_list").toggleClass("showCmd");
  51.   });
  52.  
  53.   $(".ChatToggle").click(function () {
  54.       $(this).toggleClass("selected");
  55.       $("#chat_line_list").toggleClass("showTalk");
  56.   });
  57.  
  58.   // Simulate a click on ChatToggle, so starts in the "on" position
  59.   $(".ChatToggle").click();
  60.  
  61.   CurrentChat.line_buffer = 800;
  62.  
  63.   //This part creates a CSS rule
  64.   //that hides all chat messages by default
  65.   $(
  66.       " <style type='text/css' >                     " +
  67.       " .segmented_tabs li li a.CommandsToggle {     " +
  68.       "     width: 50px;                             " +
  69.       "     padding-left: 0px;                       " +
  70.       "     padding-top: 0;                          " +
  71.       "     height: 8px;                             " +
  72.       "     line-height: 115%;                       " +
  73.       " }                                            " +
  74.       "                                              " +
  75.       " .segmented_tabs li li a.ChatToggle {         " +
  76.       "     width: 35px;                             " +
  77.       "     padding-left: 15px;                      " +
  78.       "     padding-top: 0;                          " +
  79.       "     height: 8px;                             " +
  80.       "     line-height: 115%;                       " +
  81.       " }                                            " +
  82.       "                                              " +
  83.       " #chat_line_list li { display:none }          " +  // hide new, uncategorized messages
  84.       " #chat_line_list.showCmd li.cCmd,             " +  // show messages that we know we want to read
  85.       " #chat_line_list.showTalk li.cTalk            " +
  86.       " {                                            " +
  87.       "     display:inline;                          " +
  88.       " }                                            " +
  89.       " </style>                                     "
  90.   ).appendTo("head");
  91.  
  92.   //Update the chat status periodically
  93.   setInterval(function () {
  94.       // Thus, run for each chat box item,
  95.       $('#chat_line_list li').each(function () {
  96.           var cLine = $(this),
  97.               cText = cLine.find(".chat_line").text();
  98.  
  99.           //TODO: WHY ARE WE TESTING `cText &&` here?
  100.           if (cText && !cText.trim().match(FILTER_REGEX)) {
  101.               cLine.addClass("cTalk");
  102.           } else {
  103.               cLine.addClass("cCmd");
  104.           }
  105.       });
  106.  
  107.       //TODO: WHAT DOES THIS LINE DO? SCROLL TO THE BOTTOM?
  108.       if (CurrentChat.currently_scrolling) { CurrentChat.scroll_chat(); }
  109.  
  110.   }, 100);  // <- number of miliseconds between updates
  111.  
  112. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement