Skip to content

Instantly share code, notes, and snippets.

@Splagoon
Created February 21, 2014 03:37
Show Gist options
  • Save Splagoon/9128318 to your computer and use it in GitHub Desktop.
Save Splagoon/9128318 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TPP Spammer
// @namespace kelle.tt
// @description Spam button inputs into Twitch Plays Pokemon
// @include http://www.twitch.tv/twitchplayspokemon
// @version 1
// @grant none
// ==/UserScript==
$(function(){
(function(){function pressButton(e){e.css("background","#372364");setTimeout(function(){e.css("background","")},400)}var prevTime=0;var paused=false;var interval=35;var turn=0;$("#controls").append('<div style="clear:both;"/></div><span class="primary_button autosend" style="width:120px;margin-left:20px">INPUT: <input style="width: 60px;text-align: center;" id="autosend_input" value="I like dicks"></span><a class="primary_button gamepad autosend" style="width:70px;margin-left:20px">AUTOSEND OFF</a>');$(".autosend").css({"text-align":"center",display:"block","float":"left"});$("a.autosend").on("click",function(e){e.preventDefault();paused=!paused;var t=Math.round((new Date).getTime()/1e3);$("a.autosend").text("SEND: "+(paused?"OFF":interval-(t-prevTime)))});$("#controls").append('<div style="clear:both;"/></div><span class="primary_button autosend1" style="width:120px;margin-left:20px">INPUT: <input style="width: 60px;text-align: center;" id="autosend1_input" value=""></span>');$(".autosend1").css({"text-align":"center",display:"block","float":"left"});setInterval(function(){var e=Math.round((new Date).getTime()/1e3);if(e-prevTime>interval&&!paused){prevTime=e;turn=Math.round(Math.random()%2);if(turn==0&&$(".autosend input").val()!=""){$("#chat_text_input").val($(".autosend input").val())}else{turn=1}if(turn==1&&$(".autosend1 input").val()!=""){$("#chat_text_input").val($(".autosend1 input").val())}$("#chat_speak").trigger("click");pressButton($("#autosend_command"));pressButton($("#chat_speak"))}if(!paused)$("a.autosend").text("SEND: "+(interval-(e-prevTime)))},400)})();
(function(){function min_edit(a,b){if(0===a.length)return b.length;if(0===b.length)return a.length;var d,c=[];for(d=0;d<=b.length;d++)c[d]=[d];var e;for(e=0;e<=a.length;e++)c[0][e]=e;for(d=1;d<=b.length;d++)for(e=1;e<=a.length;e++)c[d][e]=b.charAt(d-1)==a.charAt(e-1)?c[d-1][e-1]:Math.min(c[d-1][e-1]+1,Math.min(c[d][e-1]+1,c[d-1][e]+1));return c[b.length][a.length]}var BLOCKED_WORDS=["left","right","up","down","start","select","a","b","democracy","anarchy","oligarchy","bureaucracy","monarchy","alt f4","theocracy"],MINIMUM_MESSAGE_LENGTH=3,MAXIMUM_NON_ASCII_CHARACTERS=2,MINIMUM_DISTANCE_ERROR=2,REFRESH_MILLISECONDS=100,commands_regex=new RegExp("^(("+BLOCKED_WORDS.join("|")+")\\d?)+$","i"),message_is_spam=function(a){"use strict";if(a=a.replace(/\s/g,""),a.length<MINIMUM_MESSAGE_LENGTH)return!0;if(a.match(commands_regex))return!0;var b=BLOCKED_WORDS.map(function(b){return min_edit(b,a)}).reduce(function(a,b){return Math.min(a,b)});if(MINIMUM_DISTANCE_ERROR>=b)return!0;for(var c=0,d=0;d<a.length;d++)if(a.charCodeAt(d)>127&&(c++,c>MAXIMUM_NON_ASCII_CHARACTERS))return!0;return!1};$("<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 }#chat_line_list li.fromjtv,#chat_line_list.showSpam li.cSpam,#chat_line_list.showSafe li.cSafe {display:inherit;} </style>").appendTo("head");var chat_button=$("ul.segmented_tabs li a").first();chat_button.css("width",chat_button.width()-71),$("<li><a class='CommandsToggle'>Commands</a><a class='ChatToggle'>Talk</a></li>").insertAfter(chat_button),$(".CommandsToggle").click(function(){$(this).toggleClass("selected"),$("#chat_line_list").toggleClass("showSpam")}),$(".ChatToggle").click(function(){$(this).toggleClass("selected"),$("#chat_line_list").toggleClass("showSafe")}),$(".ChatToggle").click(),/*CurrentChat.line_buffer=800,*/setInterval(function(){"use strict";$("#chat_line_list li:not(.cSpam):not(.cSafe)").each(function(){var a=$(this),b=a.find(".chat_line").text();message_is_spam(b)?a.addClass("cSpam"):a.addClass("cSafe")}),CurrentChat.currently_scrolling&&CurrentChat.scroll_chat()},REFRESH_MILLISECONDS);})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment