Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro No-Script Macros
  3. // @description Macros for no-script groups (updated for swj)
  4. // @version 0.1.1
  5. // @author Some Ball -1
  6. // @include *://*.koalabeast.com*
  7. // @include http://tagpro-*.koalabeast.com:*
  8. // @include http://tagpro*.koalabeast.com*
  9. // @run-at document-end
  10. // @grant unsafeWindow
  11. // ==/UserScript==
  12.  
  13. (function(window) {
  14. 'use strict';
  15. if(!window.tagpro) {
  16.  
  17. // Number on left side is the keyCode of the key you want to trigger the macro
  18. // Get keyCodes from here: http://keycode.info/
  19. // message should contain the message you want to send in quotes
  20. // sendTo should be 0, 1, or 2 to send the message to everyone, your team, your group, respectively
  21. const macros = {
  22. 73: {message: "Sample message to all players", sendTo: 0}, // I
  23. 79: {message: "Sample message to team", sendTo: 1}, // O
  24. 80: {message: "Sample message to group", sendTo: 2}, // P
  25. };
  26.  
  27. /////////////////////////////////////////////////////
  28.  
  29. const chatTo = [13, 84, 71]; //shouldn't need to change, default enter=13, t=84, g=71
  30.  
  31. function pressUnpress(key) {
  32. $(document).trigger($.Event('keydown',{keyCode: key, fake: true})); //fake so we don't trigger our own events
  33. $(document).trigger($.Event('keyup',{keyCode: key, fake: true}));
  34. }
  35.  
  36. //use e.which instead of e.keyCode because key remapper script changes e.keyCode
  37. $(document).keydown(function(e) {
  38. if(!e.fake && macros.hasOwnProperty(e.which) && e.originalEvent && !e.originalEvent.repeat && !$('#chat').is(':visible')) {
  39. let macro = macros[e.which];
  40. pressUnpress(macro.hasOwnProperty("sendTo") && macro.sendTo>=0 && macro.sendTo<chatTo.length ? chatTo[macro.sendTo] : chatTo[0]);
  41. $('#chat').val(macro.message || "");
  42. pressUnpress(13); //enter to send
  43. }
  44. });
  45.  
  46. }
  47. })(unsafeWindow);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement