apajohnson

Untitled

Aug 7th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Chat Macros Userscript UPDATED
  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
  8. // @version 0.4
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. /********************
  13. **EDIT THESE VALUES**
  14. ********************/
  15. //all macros by defult will be sent to your team
  16. //if you want your macro sent to all chat, to group chat, or to not actually send (just fill in the text), then follow these instructions
  17.  
  18. //Step 1. Scroll down and find the lines which have all your macros
  19. //Step 2. Choose which ones you want to be sent to everyone
  20. //Step 3. Copy down the number to the left of every macro you went sent to the regular chat everyone sees
  21. //Step 4. Add the numbers between the square brackets below with commas between each number (if you only have 1 number, then no commas, if you don't want any, then leave it alone
  22. //So the line should like this where the numbers are taken from your macros below (don't worry about spaces, you can add them or not it doesn't matter)
  23. // var allChatMacros = [1, 2, 3, 4];
  24. var allChatMacros = [];
  25.  
  26. //Step 5. Repeat Steps 2-4 but this time choose the number that corresponds to the macros you want to be sent to group chat, then fill them in between the squarey brackets below
  27. //Again, it should like similar to this but with your own numbers in there, if you only have one number, then do not put any commas, if no numbers, then leave the brackets empty
  28. // var groupChatMacros = [28, 27, 12];
  29. var groupChatMacros = [];
  30.  
  31. //Step 6. Repeat Steps 2-4 but this time you're picking which macros you want to not be sent
  32. //These macros will instead autofill in your chat bar as if you've typed them, but they will not actually be sent
  33. //A potential use might be when new powerups will spawn
  34. //Your macro would be "Powerups will be respawning at: ", allowing you to then manually enter the time before hitting enter
  35. //Make sure to an extra space at the end so anything you type after isn't attached to your last word
  36. //By default, after you add additional text and hit enter, the chat will go to team chat
  37. var notSentTeamChatMacros = [49];
  38.  
  39. //All macros not included above will be sent to team chat by default
  40.  
  41. /************
  42. **END EDITS**
  43. ************/
  44.  
  45. function contentEval(source) {
  46. // Check for function input.
  47. if ('function' == typeof source) {
  48. // Execute this function with no arguments, by adding parentheses.
  49. // One set around the function, required for valid syntax, and a
  50. // second empty set calls the surrounded function.
  51. source = '(' + source + ')();';
  52. }
  53.  
  54. // Create a script node holding this source code.
  55. var script = document.createElement('script');
  56. script.setAttribute("type", "application/javascript");
  57. script.textContent = source;
  58.  
  59. // Insert the script node into the page, so it will run, and immediately
  60. // remove it to clean up.
  61. document.body.appendChild(script);
  62. document.body.removeChild(script);
  63. }
  64.  
  65. function actualScript(allChatMacros,groupChatMacros,notSentTeamChatMacros) {
  66. var macros = {};
  67. macros[50] = "Powerups spawning soon!"; // 2
  68. macros[51] = "Go chase the enemy flag carrier so we can score :)"; // 3
  69. macros[49] = "Powerup: /t"; // 1
  70.  
  71.  
  72. // Game bindings overriding adapted from JohnnyPopcorn's NeoMacro https://gist.github.com/JohnnyPopcorn/8150909
  73. var handlerbtn = $('#macrohandlerbutton');
  74. handlerbtn.keydown(keydownHandler)
  75. .keyup(keyupHandler);
  76. handlerbtn.focus();
  77.  
  78. $(document).keydown(documentKeydown);
  79. function documentKeydown(event) {
  80. if (!tagpro.disableControls) {
  81. handlerbtn.focus(); // The handler button should be always focused
  82. }
  83. }
  84.  
  85. // Prevent TagPro binds from firing on the same stuff as we have bound
  86. function keyupHandler(event) {
  87. if (event.keyCode in macros && !tagpro.disableControls) {
  88. event.preventDefault();
  89. event.stopPropagation();
  90. }
  91. }
  92.  
  93. var lastMessage = 0;
  94. function chat(chatMessage,code) {
  95. var limit = 500 + 10;
  96. var now = new Date();
  97. var timeDiff = now - lastMessage;
  98. if (timeDiff > limit) {
  99. if(allChatMacros.indexOf(code)>-1) //macro is in all chat array
  100. {
  101. tagpro.socket.emit("chat", {
  102. message: chatMessage,
  103. toAll: 1
  104. });
  105. }
  106. else if(groupChatMacros.indexOf(code)>-1 && tagpro.group.socket) //macro is in group chat array
  107. {
  108. tagpro.group.socket.emit("chat", chatMessage);
  109. }
  110. else if(notSentTeamChatMacros.indexOf(code)>-1) //macro is in don't hit enter array
  111. {
  112. var press = $.Event('keydown');
  113. press.which = 84;
  114. press.keyCode = 84;
  115. handlerbtn.trigger(press);
  116. $('#chat').val(chatMessage);
  117. }
  118. else
  119. {
  120. tagpro.socket.emit("chat", {
  121. message: chatMessage,
  122. toAll: 0
  123. });
  124. }
  125. lastMessage = new Date();
  126. } else if (timeDiff >= 0) {
  127. setTimeout(chat, limit - timeDiff, chatMessage)
  128. }
  129. }
  130.  
  131. function keydownHandler(event) {
  132. var code = event.keyCode || event.which;
  133. if (code in macros && !tagpro.disableControls) {
  134. chat(macros[code],code);
  135. event.preventDefault();
  136. event.stopPropagation();
  137. //console.log(macros[code]);
  138. }
  139. }
  140. }
  141.  
  142. // This dummy input will handle macro keypresses
  143. var btn = document.createElement("input");
  144. btn.style.opacity = 0;
  145. btn.style.position = "absolute";
  146. btn.style.top = "-100px";
  147. btn.style.left = "-100px";
  148. btn.id = "macrohandlerbutton";
  149. document.body.appendChild(btn);
  150.  
  151. contentEval(actualScript(allChatMacros,groupChatMacros,notSentTeamChatMacros));
  152. })();
Add Comment
Please, Sign In to add comment