Skip to content

Instantly share code, notes, and snippets.

@rogerscg
Created October 28, 2014 23:49
Show Gist options
  • Save rogerscg/ca4d8724b3f10a19f8c5 to your computer and use it in GitHub Desktop.
Save rogerscg/ca4d8724b3f10a19f8c5 to your computer and use it in GitHub Desktop.
/*// ==UserScript==
// @name Audio Macros
// @namespace http://www.reddit.com/u/SuperSans
// @description Recognizes chat macros, plays corresponding sound.
// @include http://tagpro-*.koalabeast.com:*
// @include http://tangent.jukejuice.com:*
// @include http://maptest.newcompte.fr:*
// @include http://maptest2.newcompte.fr:*
// @include http://justletme.be:*
// @license WTFPL; http://www.wtfpl.net/txt/copying/
// @author SuperSans
// @version 1.0
// ==/UserScript==*/
var snd1 = new Audio();
var src1 = document.createElement("source");
src1.type = "audio/mpeg";
src1.src = "http://k007.kiwi6.com/hotlink/tv0pzfxrbr/EnemyDown.mp3";
snd1.appendChild(src1);
var snd2 = new Audio();
var src2 = document.createElement("source");
src2.type = "audio/mpeg";
src2.src = "http://k007.kiwi6.com/hotlink/5bk5h2s35m/NeedBackup.mp3";
snd2.appendChild(src2);
var snd3 = new Audio();
var src3 = document.createElement("source");
src3.type = "audio/mpeg";
src3.src = "http://k007.kiwi6.com/hotlink/y8hlibevdp/baseClear.mp3";
snd3.appendChild(src3);
var snd4 = new Audio();
var src4 = document.createElement("source");
src4.type = "audio/mpeg";
src4.src = "http://k007.kiwi6.com/hotlink/808vtxifj7/boostingIn.mp3";
snd4.appendChild(src4);
var snd5 = new Audio();
var src5 = document.createElement("source");
src5.type = "audio/mpeg";
src5.src = "http://k007.kiwi6.com/hotlink/valiugp5hm/onRe.mp3";
snd5.appendChild(src5);
var snd6 = new Audio();
var src6 = document.createElement("source");
src6.type = "audio/mpeg";
src6.src = "http://k007.kiwi6.com/hotlink/s6n2lwhbve/yes.mp3";
snd6.appendChild(src6);
var snd7 = new Audio()
var src7 = document.createElement("source");
src7.type = "audio/mpeg";
src7.src = "http://k007.kiwi6.com/hotlink/y1tn5otvvt/no.mp3";
snd7.appendChild(src7);
var snd8 = new Audio()
var src8 = document.createElement("source");
src8.type = "audio/mpeg";
src8.src = "http://k007.kiwi6.com/hotlink/3mnycmi42n/takeLap.mp3";
snd8.appendChild(src8);
var snd9 = new Audio()
var src9 = document.createElement("source");
src9.type = "audio/mpeg";
src9.src = "http://k007.kiwi6.com/hotlink/2kxolqqewt/giveLead.mp3";
snd9.appendChild(src9);
var snd10 = new Audio()
var src10 = document.createElement("source");
src10.type = "audio/mpeg";
src10.src = "http://k007.kiwi6.com/hotlink/xchu8k2h3h/incomingTP.mp3";
snd10.appendChild(src10);
var snd11 = new Audio()
var src11 = document.createElement("source");
src11.type = "audio/mpeg";
src11.src = "http://k007.kiwi6.com/hotlink/d5v7iyytt2/reset.mp3";
snd11.appendChild(src11);
//Reads chat and plays sounds
window.addEventListener('load', function () {
tagpro.ready(function () {
tagpro.socket.on('chat', function (message) {
if (message.from == tagpro.playerId) {
m = message.message.toLowerCase();
if (m == "got him"){
snd1.play();
}
else if (m == "2 on d" || m == "2 on o"){
snd2.play();
}
else if (m == "base clear"){ //important
snd3.play();
}
else if (m == "coming into base" || m == "coming in hot"){ //important
snd4.play();
}
else if (m == "on re" || m == "re"){ //important
snd5.play();
}
else if (m == "yes" || m == "got it"){ //impt
snd6.play();
}
else if (m == "no" || m == "nah"|| m == "nope"){ //impt
snd7.play();
}
else if (m == "take a lap"){
snd8.play();
}
else if (m == "give me a lead"){
snd9.play();
}
else if (m == "incoming tagpro"){
snd10.play();
}
else if (m == "reset"){
snd11.play();
}
}
});
});
});
//macros code taken from Chat Macros by steppin and Watball. You can adjust which keys are used for the macros, just not the message.
(function() {
function contentEval(source) {
// Check for function input.
if ('function' == typeof source) {
// Execute this function with no arguments, by adding parentheses.
// One set around the function, required for valid syntax, and a
// second empty set calls the surrounded function.
source = '(' + source + ')();'
}
// Create a script node holding this source code.
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = source;
// Insert the script node into the page, so it will run, and immediately
// remove it to clean up.
document.body.appendChild(script);
document.body.removeChild(script);
}
function actualScript() {
var macros = {};
macros[89] = {"message": "yes", "toAll": false}; // Y
macros[78] = {"message": "no", "toAll": false}; // N
macros[66] = {"message": "base clear", "toAll": false}; // B
macros[82] = {"message": "on re", "toAll": false}; // R
macros[74] = {"message": "coming into base", "toAll": false}; // J
macros[50] = {"message": "2 on d", "toAll": false}; // 2
macros[71] = {"message": "got him", "toAll": false}; // G
macros[76] = {"message": "give me a lead", "toAll": false}; // L
macros[77] = {"message": "take a lap", "toAll": false}; // M
macros[75] = {"message": "incoming tagpro", "toAll": false}; // K
macros[72] = {"message": "reset", "toAll": false}; // H
// Game bindings overriding adapted from JohnnyPopcorn's NeoMacro https://gist.github.com/JohnnyPopcorn/8150909
var handlerbtn = $('#macrohandlerbutton');
handlerbtn.keydown(keydownHandler)
.keyup(keyupHandler);
handlerbtn.focus();
$(document).keydown(documentKeydown);
function documentKeydown(event) {
if (!tagpro.disableControls) {
handlerbtn.focus(); // The handler button should be always focused
}
}
function keydownHandler(event) {
var code = event.keyCode || event.which;
if (code in macros && !tagpro.disableControls) {
chat(macros[code]);
event.preventDefault();
event.stopPropagation();
//console.log(macros[code]);
}
}
function keyupHandler(event) {
if (event.keyCode in macros && !tagpro.disableControls) {
event.preventDefault();
event.stopPropagation();
}
}
var lastMessage = 0;
function chat(chatMessage) {
var limit = 500 + 10;
var now = new Date();
var timeDiff = now - lastMessage;
if (timeDiff > limit) {
tagpro.socket.emit("chat", chatMessage);
lastMessage = new Date();
} else if (timeDiff >= 0) {
setTimeout(chat, limit - timeDiff, chatMessage)
}
}
}
// This dummy input will handle macro keypresses
var btn = document.createElement("input");
btn.style.opacity = 0;
btn.style.position = "absolute";
btn.style.top = "-100px";
btn.style.left = "-100px";
btn.id = "macrohandlerbutton";
document.body.appendChild(btn);
contentEval(actualScript);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment