Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CrossVR/9271525 to your computer and use it in GitHub Desktop.
Save CrossVR/9271525 to your computer and use it in GitHub Desktop.
Improved chat filter and shows UTC time of your button presses
//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
$("#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.0</span></div><div style="float:right;padding-left:10px;margin-bottom:10px;margin-top:10px;">Your UTC: <span id="utcTIME" style="color:green;">00:00.00</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 > 0)
slowChatDelay -= 0.1;
if(slowChatDelay <= 0) {
$("#keyTIME").css('color', 'green');
utcUpdate();
}
$("#keyTIME").html(Math.round(slowChatDelay * 10) / 10);
}
var scdReset = function(){
slowChatDelay = 30;
$("#keyTIME").css('color', 'red');
utcUpdate();
}
var utcUpdate = function(){
var currentdate = new Date();
$("#utcTIME").html(('0' + currentdate.getMinutes()).slice(-2) + ':' + ('0' + currentdate.getSeconds()).slice(-2) + '.' + Math.floor(currentdate.getMilliseconds() / 100));
}
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 http://redd.it/1y8ukl
c = CurrentChat;
c._i = c.insert_chat_line;
c.insert_chat_line = function (e) {
!e.message.match(/^(up|down|left|right|a|b|start|select|anarchy|democracy?)$/i) && c._i(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment