Last active
July 19, 2018 18:31
-
-
Save gabstv/9038899 to your computer and use it in GitHub Desktop.
Twitch Plays Pokemon: Controls
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
//reddit: regulargabs | |
//MIT license | |
// USAGE: | |
// go to http://www.twitch.tv/twitchplayspokemon | |
// Paste the "components" that you want on the javascript console of your browser and run. | |
// ############### | |
// # COMPONENTS: # | |
// ############### | |
// CONTROLS: | |
// Puts GameBoy controls below the chat button | |
// Minified Version (use this one!): | |
$("#controls").append('<div style="float:left;padding-left:20px;"><a id="keyUP" class="primary_button" style="width:20px;text-align:center;">↑</a></div><div style="float:left;padding-left:100px;"><a id="keyA" class="primary_button" style="width:20px;text-align:center;">A</a></div><div style="clear:both;"></div><div style="float:left;padding-left:0px;"><a id="keyLEFT" class="primary_button" style="width:20px;text-align:center;">←</a></div><div style="float:left;padding-left:20px;"><a id="keyRIGHT" class="primary_button" style="width:20px;text-align:center;">→</a></div><div style="float:left;padding-left:60px;"><a id="keyB" class="primary_button" style="width:20px;text-align:center;">B</a></div><div style="clear:both;"></div><div style="float:left;padding-left:20px;"><a id="keyDOWN" class="primary_button" style="width:20px;text-align:center;">↓</a></div><div style="clear:both;"></div><div style="float:left;padding-left:60px;"><a id="keySELECT" class="primary_button" style="width:60px;text-align:center;">SELECT</a></div><div style="float:left;padding-left:10px;"><a id="keySTART" class="primary_button" style="width:60px;text-align:center;">START</a></div><div style="clear:both;"></div><div style="float:left;padding-left:10px;margin-bottom:10px;margin-top:10px;">Slow chat limit:<span id="keyTIME" style="color:green;">0</span></div>');var keyIn=function(e,t){e.preventDefault();$("#chat_text_input").val(t);$("#chat_speak").trigger("click");console.log(t)};$("#keyUP").on("click",function(e){keyIn(e,"up")});$("#keyDOWN").on("click",function(e){keyIn(e,"down")});$("#keyLEFT").on("click",function(e){keyIn(e,"left")});$("#keyRIGHT").on("click",function(e){keyIn(e,"right")});$("#keyA").on("click",function(e){keyIn(e,"a")});$("#keyB").on("click",function(e){keyIn(e,"b")});$("#keySELECT").on("click",function(e){keyIn(e,"select")});$("#keySTART").on("click",function(e){if(confirm("Do you really want to screw everyone's lives?")){keyIn(e,"start")}});var slowChatDelay=0;var scdUpdate=function(){if(slowChatDelay>-1)slowChatDelay-=.1;if(slowChatDelay<=0)$("#keyTIME").css("color","green");$("#keyTIME").html(Math.round(slowChatDelay*10)/10)};var scdReset=function(){slowChatDelay=30;$("#keyTIME").css("color","red")};setInterval(scdUpdate,100);$("#chat_speak").on("click",scdReset);$("#chat_text_input").keypress(function(e){if(e.which==13){scdReset()}}) | |
//Raw version (for development): | |
/*$("#controls").append('<div style="float:left;padding-left:20px;"><a id="keyUP" class="primary_button" style="width:20px;text-align:center;">↑</a></div><div style="float:left;padding-left:100px;"><a id="keyA" class="primary_button" style="width:20px;text-align:center;">A</a></div><div style="clear:both;"></div><div style="float:left;padding-left:0px;"><a id="keyLEFT" class="primary_button" style="width:20px;text-align:center;">←</a></div><div style="float:left;padding-left:20px;"><a id="keyRIGHT" class="primary_button" style="width:20px;text-align:center;">→</a></div><div style="float:left;padding-left:60px;"><a id="keyB" class="primary_button" style="width:20px;text-align:center;">B</a></div><div style="clear:both;"></div><div style="float:left;padding-left:20px;"><a id="keyDOWN" class="primary_button" style="width:20px;text-align:center;">↓</a></div><div style="clear:both;"></div><div style="float:left;padding-left:60px;"><a id="keySELECT" class="primary_button" style="width:60px;text-align:center;">SELECT</a></div><div style="float:left;padding-left:10px;"><a id="keySTART" class="primary_button" style="width:60px;text-align:center;">START</a></div><div style="clear:both;"></div><div style="float:left;padding-left:10px;margin-bottom:10px;margin-top:10px;">Slow chat limit:<span id="keyTIME" style="color:green;">0</span></div>'); | |
var keyIn = function(e, key){ | |
e.preventDefault(); | |
$("#chat_text_input").val(key); | |
$("#chat_speak").trigger("click"); | |
console.log(key); | |
} | |
$("#keyUP").on('click', function(event) { | |
keyIn(event, "up"); | |
}); | |
$("#keyDOWN").on('click', function(event) { | |
keyIn(event, "down"); | |
}); | |
$("#keyLEFT").on('click', function(event) { | |
keyIn(event, "left"); | |
}); | |
$("#keyRIGHT").on('click', function(event) { | |
keyIn(event, "right"); | |
}); | |
$("#keyA").on('click', function(event) { | |
keyIn(event, "a"); | |
}); | |
$("#keyB").on('click', function(event) { | |
keyIn(event, "b"); | |
}); | |
$("#keySELECT").on('click', function(event) { | |
keyIn(event, "select"); | |
}); | |
$("#keySTART").on('click', function(event) { | |
if(confirm("Do you really want to screw everyone's lives?")){ | |
keyIn(event, "start"); | |
} | |
}); | |
var slowChatDelay = 0; | |
var scdUpdate = function(){ | |
if(slowChatDelay > -1) | |
slowChatDelay -= 0.1; | |
if(slowChatDelay <= 0) | |
$("#keyTIME").css('color', 'green'); | |
$("#keyTIME").html(Math.round(slowChatDelay * 10) / 10); | |
} | |
var scdReset = function(){ | |
slowChatDelay = 30; | |
$("#keyTIME").css('color', 'red'); | |
} | |
setInterval(scdUpdate, 100); | |
$("#chat_speak").on('click', scdReset); | |
// Suggested by WolfgangSho | |
$("#chat_text_input").keypress(function (e) { | |
if (e.which == 13) { | |
scdReset(); | |
} | |
});*/ | |
// HIDE COMMANDS FROM CHAT | |
// extracted from github.com/jpgohlke/twitch-chat-filter | |
var FILTER_REGEX=/^\s*((left|right|up|down|start|select|a|b|democracy|anarchy)\d?)+\s*$/i;$("<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");a.length>0&&(b.text().match(FILTER_REGEX)?a.addClass("cSpam"):a.addClass("cSafe"))}),CurrentChat.currently_scrolling&&CurrentChat.scroll_chat()},100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And here's my version that shows the UTC time of your last button press and has a lighter chat filter: https://gist.github.com/Armada651/9271525