Agma Animation Script

Let your cell spin, jump, shake, flip and wacky!

目前为 2019-08-02 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Agma Animation Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Let your cell spin, jump, shake, flip and wacky!
  6. // @author You
  7. // @match http://agma.io/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Mouse button to use to start. Nell = do not listen to mosue click.
  15. // 0 = left, 1 = middle, 2 = right
  16. var startMouseButton = null
  17.  
  18. // Key to use to start. Null = do not key press..
  19. // Use this tool to find out key codes - just press a button: https://unixpapa.com/js/testkey.html
  20. // 17 = CTRL
  21. var startKeyCode = 17;
  22.  
  23. // True = Combine wacky with others animations,
  24. // False = Only other aninmations
  25. var combine = true;
  26.  
  27. console.log('Agma Animation Script started! ?');
  28.  
  29. /**
  30. * Returns a random number between min (inclusive) and max (exclusive)
  31. * Source: MDN
  32. */
  33. var getRandomArbitrary = function(min, max) {
  34. return Math.random() * (max - min) + min;
  35. }
  36.  
  37. var chatAnimate = function()
  38. {
  39. // The available commands
  40. var items = ['spin', 'flip', 'shake', 'jump'];
  41.  
  42. // Choose randomly an item of the items array
  43. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  44. var item = items[Math.floor(Math.random()*items.length)];
  45.  
  46. if (combine) {
  47. item = 'wacky' + item;
  48. }
  49.  
  50. // Add text into the chatbox and focus it
  51. $('#chtbox').val('/' + item).focus();
  52.  
  53. // Stop the event so that the pressed key won't be written into the chatbox!
  54. event.preventDefault();
  55. }
  56.  
  57. window.addEventListener('mousedown', function(event)
  58. {
  59. if (event.button == startMouseButton) {
  60. chatAnimate();
  61. }
  62. });
  63. window.addEventListener('keydown', function(event)
  64. {
  65. if (event.keyCode == startKeyCode && ! event.shiftKey) {
  66. chatAnimate();
  67. }
  68. });
  69. })();