Last active
August 29, 2015 13:56
-
-
Save hzoo/9074877 to your computer and use it in GitHub Desktop.
TwitchPlaysPokemon chat filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//here's a cleaner version. same functionality | |
//just easier to change since the regex is at the beginning of the code. | |
//help from /u/BBQCalculator | |
//http://www.regexper.com/ | |
//http://regexpal.com/ | |
//modfied from a lot of others | |
//moved regex to top for simple pasting if it needs to change | |
var REGEX = /^((up|down|left|right|a|b|start|select|anarchy|democracy)\d*)+$/i; | |
var chatButton = $("ul.segmented_tabs li a").first(); | |
if ($(".CommandsToggle").length === 0 && chatButton.length !== 0) { | |
$("<li><a class='CommandsToggle'>Commands</a><a class='ChatToggle'>Talk</a></li>").insertAfter(chatButton); | |
chatButton.css("width", chatButton.width() - 71); | |
$(".CommandsToggle").click(function () { | |
"use strict"; | |
$("a.CommandsToggle").toggleClass("selected"); | |
if ($(".commandsHideCSS").length !== 0) { | |
$(".commandsHideCSS").remove(); | |
} else { | |
$("<style type='text/css' class='commandsHideCSS'>#chat_line_list li.cSpam{display:inline;}</style>").appendTo("head"); | |
} | |
}); | |
$(".ChatToggle").click( | |
function () { | |
"use strict"; | |
$("a.ChatToggle").toggleClass("selected"); | |
if ($(".chatHideCSS").length !== 0) { | |
$(".chatHideCSS").remove(); | |
} else { | |
$("<style type='text/css' class='chatHideCSS'>#chat_line_list li.cSafe{display:inline;}</style>").appendTo("head"); | |
} | |
}); | |
$(".ChatToggle").click(); | |
} else { | |
$("<style type='text/css' class='chatHideCSS'>#chat_line_list li.cSafe{display:inline;}</style>").appendTo("head"); | |
} | |
if (!extraCSS) { | |
CurrentChat.line_buffer = 800; | |
var extraCSS = " <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; " + " } " + " </style> "; | |
$(extraCSS).appendTo("head"); | |
} | |
var filterFn = function () { | |
"use strict"; | |
$('#chat_line_list li:not(.cSpam):not(.cSafe)').each( | |
function () { | |
var a = $(this), | |
cText = a.find(".chat_line").text(); | |
if (cText && !cText.match(REGEX)) { | |
a.addClass("cSafe"); | |
} else { | |
a.addClass("cSpam"); | |
} | |
}); | |
if (CurrentChat.currently_scrolling) { | |
CurrentChat.scroll_chat(); | |
} | |
} | |
clearInterval(filter); | |
var filter = setInterval(filterFn, 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var REGEX=/^((up|down|left|right|a|b|start|select|anarchy|democracy)\d*)+$/i;var chatButton=$("ul.segmented_tabs li a").first();if($(".CommandsToggle").length===0&&chatButton.length!==0){$("<li><a class='CommandsToggle'>Commands</a><a class='ChatToggle'>Talk</a></li>").insertAfter(chatButton);chatButton.css("width",chatButton.width()-71);$(".CommandsToggle").click(function(){$("a.CommandsToggle").toggleClass("selected");if($(".commandsHideCSS").length!==0){$(".commandsHideCSS").remove();}else{$("<style type='text/css' class='commandsHideCSS'>#chat_line_list li.cSpam{display:inline;}</style>").appendTo("head");}});$(".ChatToggle").click(function(){$("a.ChatToggle").toggleClass("selected");if($(".chatHideCSS").length!==0){$(".chatHideCSS").remove();}else{$("<style type='text/css' class='chatHideCSS'>#chat_line_list li.cSafe{display:inline;}</style>").appendTo("head");}});$(".ChatToggle").click();}else{$("<style type='text/css' class='chatHideCSS'>#chat_line_list li.cSafe{display:inline;}</style>").appendTo("head");}if(!extraCSS){CurrentChat.line_buffer=800;var extraCSS=" <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; } </style> ";$(extraCSS).appendTo("head");}var filterFn=function(){$("#chat_line_list li:not(.cSpam):not(.cSafe)").each(function(){var a=$(this),cText=a.find(".chat_line").text();if(cText&&!cText.match(REGEX)){a.addClass("cSafe");}else{a.addClass("cSpam");}});if(CurrentChat.currently_scrolling){CurrentChat.scroll_chat();}};clearInterval(filter);var filter=setInterval(filterFn,100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment