Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name LawJik's TagPro Chat Macros v5
- // @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, Watball, Some Ball -1, monorail
- // @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);
- }
- tagpro.timeLeft = function(kind){
- var end = tagpro.gameEndsAt;
- var curr = new Date();
- var ms = end.getMilliseconds()-curr.getMilliseconds();
- end = end.getMinutes()*60+end.getSeconds();
- curr = curr.getMinutes()*60+curr.getSeconds();
- if(curr>end) //stradling over an hour mark
- {
- end += 60*60; //add an hour to it
- }
- var min = Math.floor((end-curr)/60);
- var sec = Math.floor((end-curr)%60+ms/1000);
- if(ms<0)
- {
- ms += 1000;
- }
- ms = Math.round(ms/100);
- if(min<10)
- {
- min = '0'+min;
- }
- if(sec<10)
- {
- sec = '0'+sec;
- }
- if(kind==1) //just min
- {
- return min;
- }
- else if(kind==2) //just sec
- {
- return sec;
- }
- return min+':'+sec+'.'+ms;
- }
- function actualScript() {
- var macros = {};
- //
- // *********************************************************
- // macros[###] is where you bind your keys. I have it setup for the numpad and home keys. Check webpage below for keycodes.
- // keyCodes: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
- //
- // monorail's additional features: /s = seconds. /n = line break. etc.
- // http://www.reddit.com/r/TagPro/comments/2b4g2y/userscript_chat_macros_with_some_additional/
- //*********************************************************
- //
- macros[103] = { message:"Their FC is ↖ TOP LEFT ↖", allchat:0 }; // 7
- macros[104] = { message:"Their FC is ↑ TOP ↑", allchat:0 }; // 8
- macros[105] = { message:"Their FC is ↗ TOP RIGHT ↗", allchat:0 }; // 9
- macros[100] = { message:"Their FC is ← LEFT ←", allchat:0 }; // 4
- macros[101] = { message:"Their FC is ⊗ MIDDLE ⊗", allchat:0 }; // 5
- macros[102] = { message:"Their FC is → RIGHT →", allchat:0 }; // 6
- macros[97] = { message:"Their FC is ↙ BOTTOM LEFT ↙", allchat:0 }; // 1
- macros[98] = { message:"Their FC is ↓ BOTTOM ↓", allchat:0 }; // 2
- macros[99] = { message:"Their FC is ↘ BOTTOM RIGHT ↘", allchat:0 }; // 3
- macros[110] = { message:"• Button please •", allchat:0 }; // ./Del
- macros[111] = { message:"Base powerup grabbed at: /s", allchat:0 }; // /
- macros[106] = { message:"Mid powerup grabbed at: /s", allchat:0 }; // *
- macros[109] = { message:"Far powerup grabbed at: /s", allchat:0 }; // -
- macros[33] = { message:"Our FC is coming to cap. CLEAR PATH!", allchat:0 }; // PgUp
- macros[34] = { message:"Their FC is going to cap. KILL HIM!", allchat:0 }; // PgDown
- macros[36] = { message:"* Grab Power-Ups! *", allchat:0 }; // Home
- macros[35] = { message:"Where is their FC?", allchat:0 }; // End
- // These two chats go to everyone, not just team chat.
- macros[45] = { message:"pls", allchat:1 }; // Insert
- macros[46] = { message:"Good Game Everyone!", allchat:1 }; // delete
- // 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
- }
- }
- // Prevent TagPro binds from firing on the same stuff as we have bound
- function keyupHandler(event) {
- if (event.keyCode in macros && !tagpro.disableControls) {
- event.preventDefault();
- event.stopPropagation();
- }
- }
- var lastMessage = 0;
- function chat(chatMessage) {
- function convert(msg) {
- msg = msg.replace(/\/t/g,tagpro.timeLeft(0));
- msg = msg.replace(/\/m/g,tagpro.timeLeft(1));
- msg = msg.replace(/\/s/g,tagpro.timeLeft(2));
- return msg
- }
- var limit = 500 + 10;
- var now = new Date();
- var timeDiff = now - lastMessage;
- if (timeDiff > limit) {
- tagpro.socket.emit("chat", {
- message: convert(chatMessage.message),
- toAll: chatMessage.allchat
- });
- lastMessage = new Date();
- } else if (timeDiff >= 0) {
- setTimeout(chat, limit - timeDiff, chatMessage)
- }
- }
- function keydownHandler(event) {
- var code = event.keyCode || event.which;
- if (code in macros && !tagpro.disableControls) {
- for (var i = 0; i < macros[code].message.split('/n').length; i++) {
- chat({ message:macros[code].message.split('/n')[i], allchat:macros[code].allchat });
- }
- event.preventDefault();
- event.stopPropagation();
- //console.log(macros[code]);
- } else if (code == 191) {
- var press = $.Event('keydown');
- press.which = 84;
- press.keyCode = 84;
- handlerbtn.trigger(press);
- $('#chat').val("");
- }
- }
- }
- // 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