Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==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:*
- // @include http://tangent.jukejuice.com:*
- // @include http://maptest.newcompte.fr:*
- // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
- // @author steppin, Watball
- // @version 0.4
- // ==/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[90] = {"message": "You look like you're having trouble. Have you tried /r/learn2tagpro?", "toAll": true}; // Z
- macros[88] = {"message": "I'm sure you'll get it next time if you really put your mind to it!", "toAll": true}; // X
- macros[67] = {"message": "The first step to getting better is admitting that you're bad.", "toAll": true}; // C
- macros[86] = {"message": "If you keep up practising in PUBs, you might one day be as good as me!", "toAll": true}; // V
- macros[66] = {"message": "Winning in TagPro is 1% skill, 99% being on the other team as you.", "toAll": true}; // B
- macros[78] = {"message": "Don't worry mate, we all make easily-avoidable mistakes sometimes!", "toAll": true}; // N
- macros[77] = {"message": "You're so bad, I almost thought you were Hoog.", "toAll": true}; // M
- macros[188] = {"message": "No, no, no, silly ball -- the aim of the game is to WIN.", "toAll": true}; // ,
- macros[190] = {"message": "I don't know what makes you so terrible, but it really works.", "toAll": true}; // .
- macros[191] = {"message": "Murdering, murdering, yeah!, Murdering, mudering, yeah!", "toAll": true}; // /
- macros[49] = {"message": "Bummer. I'm gonna miss all the fun.", "toAll": true}; // 1
- macros[50] = {"message": "A heroic death.", "toAll": true}; // 2
- macros[51] = {"message": "Nothing wrong with... dying young...", "toAll": true}; // 3
- macros[52] = {"message": "Shot through the heart, and I'm to blame.", "toAll": true}; // 4
- macros[53] = {"message": "It's okay, no one saw that", "toAll": true}; // 5
- macros[54] = {"message": "A noble sacrifice.", "toAll": true}; // 6
- macros[55] = {"message": "//Switching to energy conservation mode//", "toAll": true}; // 7
- // 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;
- var active = false;
- 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 && !active) {
- active = true;
- setTimeout(function(chatMessage) { chat(chatMessage); active = false }, 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);
- })();
Add Comment
Please, Sign In to add comment