Guest User

Untitled

a guest
May 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Chat Macros Userscript
  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. // @include http://tangent.jukejuice.com:*
  7. // @include http://maptest.newcompte.fr:*
  8. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  9. // @author steppin, Watball
  10. // @version 0.4
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. function contentEval(source) {
  16. // Check for function input.
  17. if ('function' == typeof source) {
  18. // Execute this function with no arguments, by adding parentheses.
  19. // One set around the function, required for valid syntax, and a
  20. // second empty set calls the surrounded function.
  21. source = '(' + source + ')();'
  22. }
  23.  
  24. // Create a script node holding this source code.
  25. var script = document.createElement('script');
  26. script.setAttribute("type", "application/javascript");
  27. script.textContent = source;
  28.  
  29. // Insert the script node into the page, so it will run, and immediately
  30. // remove it to clean up.
  31. document.body.appendChild(script);
  32. document.body.removeChild(script);
  33. }
  34.  
  35. function actualScript() {
  36. var macros = {};
  37. macros[90] = {"message": "You look like you're having trouble. Have you tried /r/learn2tagpro?", "toAll": true}; // Z
  38. macros[88] = {"message": "I'm sure you'll get it next time if you really put your mind to it!", "toAll": true}; // X
  39. macros[67] = {"message": "The first step to getting better is admitting that you're bad.", "toAll": true}; // C
  40. macros[86] = {"message": "If you keep up practising in PUBs, you might one day be as good as me!", "toAll": true}; // V
  41. macros[66] = {"message": "Winning in TagPro is 1% skill, 99% being on the other team as you.", "toAll": true}; // B
  42. macros[78] = {"message": "Don't worry mate, we all make easily-avoidable mistakes sometimes!", "toAll": true}; // N
  43. macros[77] = {"message": "You're so bad, I almost thought you were Hoog.", "toAll": true}; // M
  44. macros[188] = {"message": "No, no, no, silly ball -- the aim of the game is to WIN.", "toAll": true}; // ,
  45. macros[190] = {"message": "I don't know what makes you so terrible, but it really works.", "toAll": true}; // .
  46. macros[191] = {"message": "Murdering, murdering, yeah!, Murdering, mudering, yeah!", "toAll": true}; // /
  47. macros[49] = {"message": "Bummer. I'm gonna miss all the fun.", "toAll": true}; // 1
  48. macros[50] = {"message": "A heroic death.", "toAll": true}; // 2
  49. macros[51] = {"message": "Nothing wrong with... dying young...", "toAll": true}; // 3
  50. macros[52] = {"message": "Shot through the heart, and I'm to blame.", "toAll": true}; // 4
  51. macros[53] = {"message": "It's okay, no one saw that", "toAll": true}; // 5
  52. macros[54] = {"message": "A noble sacrifice.", "toAll": true}; // 6
  53. macros[55] = {"message": "//Switching to energy conservation mode//", "toAll": true}; // 7
  54.  
  55. // Game bindings overriding adapted from JohnnyPopcorn's NeoMacro https://gist.github.com/JohnnyPopcorn/8150909
  56. var handlerbtn = $('#macrohandlerbutton');
  57. handlerbtn.keydown(keydownHandler)
  58. .keyup(keyupHandler);
  59. handlerbtn.focus();
  60.  
  61. $(document).keydown(documentKeydown);
  62. function documentKeydown(event) {
  63. if (!tagpro.disableControls) {
  64. handlerbtn.focus(); // The handler button should be always focused
  65. }
  66. }
  67.  
  68. function keydownHandler(event) {
  69. var code = event.keyCode || event.which;
  70. if (code in macros && !tagpro.disableControls) {
  71. chat(macros[code]);
  72. event.preventDefault();
  73. event.stopPropagation();
  74. //console.log(macros[code]);
  75. }
  76. }
  77.  
  78. function keyupHandler(event) {
  79. if (event.keyCode in macros && !tagpro.disableControls) {
  80. event.preventDefault();
  81. event.stopPropagation();
  82. }
  83. }
  84.  
  85. var lastMessage = 0;
  86. var active = false;
  87. function chat(chatMessage) {
  88. var limit = 500 + 10;
  89. var now = new Date();
  90. var timeDiff = now - lastMessage;
  91. if (timeDiff > limit) {
  92. tagpro.socket.emit("chat", chatMessage);
  93. lastMessage = new Date();
  94. } else if (timeDiff >= 0 && !active) {
  95. active = true;
  96. setTimeout(function(chatMessage) { chat(chatMessage); active = false }, limit - timeDiff, chatMessage);
  97. }
  98. }
  99. }
  100.  
  101. // This dummy input will handle macro keypresses
  102. var btn = document.createElement("input");
  103. btn.style.opacity = 0;
  104. btn.style.position = "absolute";
  105. btn.style.top = "-100px";
  106. btn.style.left = "-100px";
  107. btn.id = "macrohandlerbutton";
  108. document.body.appendChild(btn);
  109.  
  110. contentEval(actualScript);
  111. })();
Add Comment
Please, Sign In to add comment