Guest User

LawJik's TagPro Chat Macros v5

a guest
Jul 24th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. // ==UserScript==
  2. // @name LawJik's TagPro Chat Macros v5
  3. // @namespace http://www.reddit.com/user/contact_lens_linux/
  4. // @description Help your team with quick chat macros.
  5. // @include http://tagpro-*.koalabeast.com:*
  6. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  7. // @author steppin, Watball, Some Ball -1, monorail
  8. // @version 0.4
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.  
  13. function contentEval(source) {
  14. // Check for function input.
  15. if ('function' == typeof source) {
  16. // Execute this function with no arguments, by adding parentheses.
  17. // One set around the function, required for valid syntax, and a
  18. // second empty set calls the surrounded function.
  19. source = '(' + source + ')();'
  20. }
  21.  
  22. // Create a script node holding this source code.
  23. var script = document.createElement('script');
  24. script.setAttribute("type", "application/javascript");
  25. script.textContent = source;
  26.  
  27. // Insert the script node into the page, so it will run, and immediately
  28. // remove it to clean up.
  29. document.body.appendChild(script);
  30. document.body.removeChild(script);
  31. }
  32.  
  33. tagpro.timeLeft = function(kind){
  34. var end = tagpro.gameEndsAt;
  35. var curr = new Date();
  36. var ms = end.getMilliseconds()-curr.getMilliseconds();
  37. end = end.getMinutes()*60+end.getSeconds();
  38. curr = curr.getMinutes()*60+curr.getSeconds();
  39. if(curr>end) //stradling over an hour mark
  40. {
  41. end += 60*60; //add an hour to it
  42. }
  43. var min = Math.floor((end-curr)/60);
  44. var sec = Math.floor((end-curr)%60+ms/1000);
  45. if(ms<0)
  46. {
  47. ms += 1000;
  48. }
  49. ms = Math.round(ms/100);
  50. if(min<10)
  51. {
  52. min = '0'+min;
  53. }
  54. if(sec<10)
  55. {
  56. sec = '0'+sec;
  57. }
  58. if(kind==1) //just min
  59. {
  60. return min;
  61. }
  62. else if(kind==2) //just sec
  63. {
  64. return sec;
  65. }
  66. return min+':'+sec+'.'+ms;
  67. }
  68.  
  69. function actualScript() {
  70. var macros = {};
  71. //
  72. // *********************************************************
  73. // macros[###] is where you bind your keys. I have it setup for the numpad and home keys. Check webpage below for keycodes.
  74. // keyCodes: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  75. //
  76. // monorail's additional features: /s = seconds. /n = line break. etc.
  77. // http://www.reddit.com/r/TagPro/comments/2b4g2y/userscript_chat_macros_with_some_additional/
  78. //*********************************************************
  79. //
  80. macros[103] = { message:"Their FC is ↖ TOP LEFT ↖", allchat:0 }; // 7
  81. macros[104] = { message:"Their FC is ↑ TOP ↑", allchat:0 }; // 8
  82. macros[105] = { message:"Their FC is ↗ TOP RIGHT ↗", allchat:0 }; // 9
  83. macros[100] = { message:"Their FC is ← LEFT ←", allchat:0 }; // 4
  84. macros[101] = { message:"Their FC is ⊗ MIDDLE ⊗", allchat:0 }; // 5
  85. macros[102] = { message:"Their FC is → RIGHT →", allchat:0 }; // 6
  86. macros[97] = { message:"Their FC is ↙ BOTTOM LEFT ↙", allchat:0 }; // 1
  87. macros[98] = { message:"Their FC is ↓ BOTTOM ↓", allchat:0 }; // 2
  88. macros[99] = { message:"Their FC is ↘ BOTTOM RIGHT ↘", allchat:0 }; // 3
  89. macros[110] = { message:"• Button please •", allchat:0 }; // ./Del
  90. macros[111] = { message:"Base powerup grabbed at: /s", allchat:0 }; // /
  91. macros[106] = { message:"Mid powerup grabbed at: /s", allchat:0 }; // *
  92. macros[109] = { message:"Far powerup grabbed at: /s", allchat:0 }; // -
  93. macros[33] = { message:"Our FC is coming to cap. CLEAR PATH!", allchat:0 }; // PgUp
  94. macros[34] = { message:"Their FC is going to cap. KILL HIM!", allchat:0 }; // PgDown
  95. macros[36] = { message:"* Grab Power-Ups! *", allchat:0 }; // Home
  96. macros[35] = { message:"Where is their FC?", allchat:0 }; // End
  97. // These two chats go to everyone, not just team chat.
  98.  
  99. macros[45] = { message:"pls", allchat:1 }; // Insert
  100. macros[46] = { message:"Good Game Everyone!", allchat:1 }; // delete
  101.  
  102.  
  103. // Game bindings overriding adapted from JohnnyPopcorn's NeoMacro https://gist.github.com/JohnnyPopcorn/8150909
  104. var handlerbtn = $('#macrohandlerbutton');
  105. handlerbtn.keydown(keydownHandler)
  106. .keyup(keyupHandler);
  107. handlerbtn.focus();
  108.  
  109. $(document).keydown(documentKeydown);
  110. function documentKeydown(event) {
  111. if (!tagpro.disableControls) {
  112. handlerbtn.focus(); // The handler button should be always focused
  113. }
  114. }
  115.  
  116. // Prevent TagPro binds from firing on the same stuff as we have bound
  117. function keyupHandler(event) {
  118. if (event.keyCode in macros && !tagpro.disableControls) {
  119. event.preventDefault();
  120. event.stopPropagation();
  121. }
  122. }
  123.  
  124. var lastMessage = 0;
  125.  
  126. function chat(chatMessage) {
  127. function convert(msg) {
  128. msg = msg.replace(/\/t/g,tagpro.timeLeft(0));
  129. msg = msg.replace(/\/m/g,tagpro.timeLeft(1));
  130. msg = msg.replace(/\/s/g,tagpro.timeLeft(2));
  131. return msg
  132. }
  133. var limit = 500 + 10;
  134. var now = new Date();
  135. var timeDiff = now - lastMessage;
  136. if (timeDiff > limit) {
  137. tagpro.socket.emit("chat", {
  138. message: convert(chatMessage.message),
  139. toAll: chatMessage.allchat
  140. });
  141. lastMessage = new Date();
  142. } else if (timeDiff >= 0) {
  143. setTimeout(chat, limit - timeDiff, chatMessage)
  144. }
  145. }
  146.  
  147. function keydownHandler(event) {
  148. var code = event.keyCode || event.which;
  149. if (code in macros && !tagpro.disableControls) {
  150. for (var i = 0; i < macros[code].message.split('/n').length; i++) {
  151. chat({ message:macros[code].message.split('/n')[i], allchat:macros[code].allchat });
  152. }
  153. event.preventDefault();
  154. event.stopPropagation();
  155. //console.log(macros[code]);
  156. } else if (code == 191) {
  157. var press = $.Event('keydown');
  158. press.which = 84;
  159. press.keyCode = 84;
  160. handlerbtn.trigger(press);
  161. $('#chat').val("");
  162. }
  163. }
  164. }
  165.  
  166. // This dummy input will handle macro keypresses
  167. var btn = document.createElement("input");
  168. btn.style.opacity = 0;
  169. btn.style.position = "absolute";
  170. btn.style.top = "-100px";
  171. btn.style.left = "-100px";
  172. btn.id = "macrohandlerbutton";
  173. document.body.appendChild(btn);
  174.  
  175. contentEval(actualScript);
  176. })();
Add Comment
Please, Sign In to add comment