Created
July 14, 2016 22:00
-
-
Save CreaturePhil/521bc8fbbed0b4a080922b07ad5328f2 to your computer and use it in GitHub Desktop.
macros
This file contains hidden or 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 macros | |
// @namespace http://www.reddit.com/user/contact_lens_linux/ | |
// @description Help your team with quick chat macros. | |
// @include http://*.koalabeast.com:* | |
// @include http://tangent.jukejuice.com:* | |
// @include http://*.newcompte.fr:* | |
// @exclude http://*.koalabeast.com:3000* | |
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html | |
// @author steppin, Watball | |
// @version 0.4 | |
// ==/UserScript== | |
if ((window.sessionStorage.toggles && JSON.parse(window.sessionStorage.toggles).macros)){ | |
// add your macros around line 125 | |
// each player who wishes to use macros on the competitive partition must install this script to tampermonkey | |
// for the number row, use 48 for the zero key, 49 for the one key, 50 for the two key, etc (through 57 for the nine key). | |
// for example, "macros[54]" = {...}; assigns a macro to the six key. | |
// for all other keys, you can either use the variables defined on lines 21 through 121 | |
// or you can use this link to determine the numbers associated with the keys you want to use for macros: http://keycode.info/ | |
// number keys | |
var n0 = 48; | |
var n1 = 49; | |
var n2 = 50; | |
var n3 = 51; | |
var n4 = 52; | |
var n5 = 53; | |
var n6 = 54; | |
var n7 = 55; | |
var n8 = 56; | |
var n9 = 57; | |
// arrow keys | |
var leftarrow = 37; | |
var uparrow = 38; | |
var rightarrow = 39; | |
var downarrow = 40; | |
// navigation keys | |
var pgdown = 33; | |
var pgup = 34; | |
var end = 35; | |
var home = 36; | |
var ins = 45; | |
var del = 46; | |
// a-z keys | |
var a = 65; | |
var b = 66; | |
var c = 67; | |
var d = 68; | |
var e = 69; | |
var f = 70; | |
var g = 71; | |
var h = 72; | |
var i = 73; | |
var j = 74; | |
var k = 75; | |
var l = 76; | |
var m = 77; | |
var n = 78; | |
var o = 79; | |
var p = 80; | |
var q = 81; | |
var r = 82; | |
var s = 83; | |
var t = 84; | |
var u = 85; | |
var v = 86; | |
var w = 87; | |
var x = 88; | |
var y = 89; | |
var z = 90; | |
// alphanumeric | |
var backspace = 8; | |
var tab = 9; | |
var enter = 13; | |
var shift = 16; | |
var capslock = 20; | |
var space = 32; | |
var semicolon = 186; | |
var equals = 187; | |
var comma = 188; | |
var dash = 189; | |
var period = 190; | |
var forwardslash = 191; | |
var graveaccent = 192; | |
var openbracket = 219; | |
var backslash = 220; | |
var closebracket = 221; | |
var singlequote = 222; | |
// numpad | |
var num0 = 96; | |
var num1 = 97; | |
var num2 = 98; | |
var num3 = 99; | |
var num4 = 100; | |
var num5 = 101; | |
var num6 = 102; | |
var num7 = 103; | |
var num8 = 104; | |
var num9 = 105; | |
var star = 106; | |
var add = 107; | |
var subtract = 109; | |
var decimal = 110; | |
var divide = 111; | |
var numlock = 144; | |
// function keys | |
var f1 = 112; | |
var f2 = 113; | |
var f3 = 114; | |
var f4 = 115; | |
var f6 = 117; | |
var f7 = 118; | |
var f8 = 119; | |
var f9 = 120; | |
var f10 = 121; | |
var f11 = 122; | |
var f12 = 123; | |
// control keys | |
var ctrl = 17; | |
var alt = 18; | |
var pausebreak = 19; | |
var esc = 27; | |
var leftwindows = 91; | |
var rightwindows = 92; | |
var select = 93; | |
var scrolllock = 145; | |
var macros = {}; | |
// >>>>>>> YOUR MACROS GO HERE <<<<<<< | |
macros[r] = {"message": "I'm on regrab", "toAll": false}; | |
macros[n] = {"message": "need re", "toAll": false}; | |
macros[p] = {"message": "I'm getting a pup", "toAll": false}; | |
macros[num1] = {"message": "FC in lane 1", "toAll": false}; | |
macros[num2] = {"message": "FC in lane 2", "toAll": false}; | |
macros[num3] = {"message": "FC in lane 3", "toAll": false}; | |
macros[num4] = {"message": "FC in lane 4", "toAll": false}; | |
macros[c] = {"message": "Base is clear", "toAll": false}; | |
macros[o] = {"message": "FC is out pass 2", "toAll": false}; | |
// >>>>>>> <<<<<<< | |
window.sessionStorage.macros = JSON.stringify(macros); | |
if (document.location.port >= 8050) return; | |
(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 = JSON.parse(sessionStorage.macros); | |
// 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); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment