Advertisement
Guest User

TagPro Chat Macros

a guest
Oct 28th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Chat Macros
  3. // @include http://tagpro-*.koalabeast.com:*
  4. // @include http://tangent.jukejuice.com:*
  5. // @include http://*.newcompte.fr:*
  6. // ==/UserScript==
  7.  
  8. (function() {
  9.  
  10. function contentEval(source) {
  11. // Check for function input.
  12. if ('function' == typeof source) {
  13. // Execute this function with no arguments, by adding parentheses.
  14. // One set around the function, required for valid syntax, and a
  15. // second empty set calls the surrounded function.
  16. source = '(' + source + ')();'
  17. }
  18.  
  19. // Create a script node holding this source code.
  20. var script = document.createElement('script');
  21. script.setAttribute("type", "application/javascript");
  22. script.textContent = source;
  23.  
  24. // Insert the script node into the page, so it will run, and immediately
  25. // remove it to clean up.
  26. document.body.appendChild(script);
  27. document.body.removeChild(script);
  28. }
  29.  
  30. function actualScript() {
  31. var macros = {};
  32. macros[49] = {"message": "gg", "toAll": true}; // 1
  33. macros[50] = {"message": "sorry mb", "toAll": true}; // 2
  34. macros[51] = {"message": "all good", "toAll": true}; // 3
  35.  
  36. // Game bindings overriding adapted from JohnnyPopcorn's NeoMacro https://gist.github.com/JohnnyPopcorn/8150909
  37. var handlerbtn = $('#macrohandlerbutton');
  38. handlerbtn.keydown(keydownHandler)
  39. .keyup(keyupHandler);
  40. handlerbtn.focus();
  41.  
  42. $(document).keydown(documentKeydown);
  43. function documentKeydown(event) {
  44. if (!tagpro.disableControls) {
  45. handlerbtn.focus(); // The handler button should be always focused
  46. }
  47. }
  48.  
  49. function keydownHandler(event) {
  50. var code = event.keyCode || event.which;
  51. if (code in macros && !tagpro.disableControls) {
  52. chat(macros[code]);
  53. event.preventDefault();
  54. event.stopPropagation();
  55. //console.log(macros[code]);
  56. }
  57. }
  58.  
  59. function keyupHandler(event) {
  60. if (event.keyCode in macros && !tagpro.disableControls) {
  61. event.preventDefault();
  62. event.stopPropagation();
  63. }
  64. }
  65.  
  66. var lastMessage = 0;
  67. var active = false;
  68. function chat(chatMessage) {
  69. var limit = 500 + 10;
  70. var now = new Date();
  71. var timeDiff = now - lastMessage;
  72. if (timeDiff > limit) {
  73. tagpro.socket.emit("chat", chatMessage);
  74. lastMessage = new Date();
  75. } else if (timeDiff >= 0 && !active) {
  76. active = true;
  77. setTimeout(function(chatMessage) { chat(chatMessage); active = false }, limit - timeDiff, chatMessage);
  78. }
  79. }
  80. }
  81.  
  82. // This dummy input will handle macro keypresses
  83. var btn = document.createElement("input");
  84. btn.style.opacity = 0;
  85. btn.style.position = "absolute";
  86. btn.style.top = "-100px";
  87. btn.style.left = "-100px";
  88. btn.id = "macrohandlerbutton";
  89. document.body.appendChild(btn);
  90.  
  91. contentEval(actualScript);
  92. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement