Last active
December 15, 2015 16:58
-
-
Save steppin/5292526 to your computer and use it in GitHub Desktop.
TagPro Chat Macros Userscript
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
// ==UserScript== | |
// @name TagPro Chat Macros Userscript | |
// @namespace http://www.reddit.com/user/contact_lens_linux/ | |
// @description Help your team with quick chat macros. | |
// @include http://tagpro-*.koalabeast.com:* | |
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html | |
// @author steppin | |
// @version 0.2 | |
// ==/UserScript== | |
(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[49] = "Enemy TagPro coming in"; // 1 | |
macros[50] = "FC has rolling bomb"; // 2 | |
macros[51] = "need button support"; // 3 | |
macros[52] = "I have button"; // 4 | |
macros[53] = ""; // 5 | |
macros[96] = "I'm coming in for a cap; get ready to block"; // grave | |
macros[39] = "Flag is northwest"; // ' | |
macros[44] = "Flag is north"; // , | |
macros[46] = "Flag is northeast"; // . | |
macros[97] = "Flag is west"; // a | |
macros[111] = "Flag is middle"; // o | |
macros[101] = "Flag is east"; // e | |
macros[59] = "Flag is southwest"; // ; | |
macros[113] = "Flag is south"; // q | |
macros[106] = "Flag is southeast"; // j | |
document.addEventListener('keypress', keypressHandler, false); | |
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", { | |
message: chatMessage, | |
toAll: 0 | |
}); | |
lastMessage = new Date(); | |
} else if (timeDiff >= 0) { | |
setTimeout(chat, limit - timeDiff, chatMessage) | |
} | |
} | |
function keypressHandler(event) { | |
var code = event.keyCode || event.which; | |
if (code in macros && !tagpro.disableControls) { | |
chat(macros[code]); | |
//console.log(macros[code]); | |
} | |
} | |
} | |
contentEval(actualScript); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment