Agma Animation Script

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

目前为 2019-07-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Agma Animation Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  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. // Key to use to start
  15. // USe this tool to find out key codes - just press a button: https://unixpapa.com/js/testkey.html
  16. // 220 = Key below "ESC" ("`" on English QWERTY layout, "^" on German QWERTZ keyboard layout)
  17. var startKeyCode = 220;
  18.  
  19. // True = Combine wacky with others animations,
  20. // False = Only other aninmations
  21. var combine = true;
  22.  
  23. console.log('Agma Animation Script started! 🌸');
  24.  
  25. /**
  26. * Returns a random number between min (inclusive) and max (exclusive)
  27. * Source: MDN
  28. */
  29. var getRandomArbitrary = function(min, max) {
  30. return Math.random() * (max - min) + min;
  31. }
  32.  
  33. window.addEventListener('keydown', function(event)
  34. {
  35. if (event.keyCode == startKeyCode && ! event.shiftKey) {
  36. // The available commands
  37. var items = ['spin', 'flip', 'shake', 'jump'];
  38.  
  39. // Choose randomly an item of the items array
  40. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  41. var item = items[Math.floor(Math.random()*items.length)];
  42.  
  43. if (combine) {
  44. item = 'wacky' + item;
  45. }
  46.  
  47. // Add text into the chatbox and focus it
  48. $('#chtbox').val('/' + item).focus();
  49.  
  50. sendKey(13);
  51.  
  52. // Stop the event so that the pressed key won't be written into the chatbox!
  53. event.preventDefault();
  54. }
  55. });
  56. })();