Miracle Scripts

Let your cell spin, jump, shake, flip and wacky! Copy & paste custom emojis to the chatbox! Dance! Use Chat replacements!

当前为 2019-10-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 1.0
  5. // @description Let your cell spin, jump, shake, flip and wacky! Copy & paste custom emojis to the chatbox! Dance! Use Chat replacements!
  6. // @homepage http://agarioforums.net/member.php?action=profile&uid=21263
  7. // @author You
  8. // @license MIT
  9. // @icon https://abload.de/img/mh3k8o.png
  10. // @match http://agma.io/
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Source: http://stackoverflow.com/questions/1772179/get-character-value-from-keycode-in-javascript-then-trim#answer-23377822
  15. window.keyboardMap = [
  16. "", // [0]
  17. "", // [1]
  18. "", // [2]
  19. "CANCEL", // [3]
  20. "", // [4]
  21. "", // [5]
  22. "HELP", // [6]
  23. "", // [7]
  24. "BACK_SPACE", // [8]
  25. "TAB", // [9]
  26. "", // [10]
  27. "", // [11]
  28. "CLEAR", // [12]
  29. "ENTER", // [13]
  30. "ENTER_SPECIAL", // [14]
  31. "", // [15]
  32. "SHIFT", // [16]
  33. "CONTROL", // [17]
  34. "ALT", // [18]
  35. "PAUSE", // [19]
  36. "CAPS_LOCK", // [20]
  37. "KANA", // [21]
  38. "EISU", // [22]
  39. "JUNJA", // [23]
  40. "FINAL", // [24]
  41. "HANJA", // [25]
  42. "", // [26]
  43. "ESCAPE", // [27]
  44. "CONVERT", // [28]
  45. "NONCONVERT", // [29]
  46. "ACCEPT", // [30]
  47. "MODECHANGE", // [31]
  48. "SPACE", // [32]
  49. "PAGE_UP", // [33]
  50. "PAGE_DOWN", // [34]
  51. "END", // [35]
  52. "HOME", // [36]
  53. "LEFT", // [37]
  54. "UP", // [38]
  55. "RIGHT", // [39]
  56. "DOWN", // [40]
  57. "SELECT", // [41]
  58. "PRINT", // [42]
  59. "EXECUTE", // [43]
  60. "PRINTSCREEN", // [44]
  61. "INSERT", // [45]
  62. "DELETE", // [46]
  63. "", // [47]
  64. "0", // [48]
  65. "1", // [49]
  66. "2", // [50]
  67. "3", // [51]
  68. "4", // [52]
  69. "5", // [53]
  70. "6", // [54]
  71. "7", // [55]
  72. "8", // [56]
  73. "9", // [57]
  74. "COLON", // [58]
  75. "SEMICOLON", // [59]
  76. "LESS_THAN", // [60]
  77. "EQUALS", // [61]
  78. "GREATER_THAN", // [62]
  79. "QUESTION_MARK", // [63]
  80. "AT", // [64]
  81. "A", // [65]
  82. "B", // [66]
  83. "C", // [67]
  84. "D", // [68]
  85. "E", // [69]
  86. "F", // [70]
  87. "G", // [71]
  88. "H", // [72]
  89. "I", // [73]
  90. "J", // [74]
  91. "K", // [75]
  92. "L", // [76]
  93. "M", // [77]
  94. "N", // [78]
  95. "O", // [79]
  96. "P", // [80]
  97. "Q", // [81]
  98. "R", // [82]
  99. "S", // [83]
  100. "T", // [84]
  101. "U", // [85]
  102. "V", // [86]
  103. "W", // [87]
  104. "X", // [88]
  105. "Y", // [89]
  106. "Z", // [90]
  107. "OS_KEY", // [91] Windows Key (Windows) or Command Key (Mac)
  108. "", // [92]
  109. "CONTEXT_MENU", // [93]
  110. "", // [94]
  111. "SLEEP", // [95]
  112. "NUMPAD0", // [96]
  113. "NUMPAD1", // [97]
  114. "NUMPAD2", // [98]
  115. "NUMPAD3", // [99]
  116. "NUMPAD4", // [100]
  117. "NUMPAD5", // [101]
  118. "NUMPAD6", // [102]
  119. "NUMPAD7", // [103]
  120. "NUMPAD8", // [104]
  121. "NUMPAD9", // [105]
  122. "MULTIPLY", // [106]
  123. "ADD", // [107]
  124. "SEPARATOR", // [108]
  125. "SUBTRACT", // [109]
  126. "DECIMAL", // [110]
  127. "DIVIDE", // [111]
  128. "F1", // [112]
  129. "F2", // [113]
  130. "F3", // [114]
  131. "F4", // [115]
  132. "F5", // [116]
  133. "F6", // [117]
  134. "F7", // [118]
  135. "F8", // [119]
  136. "F9", // [120]
  137. "F10", // [121]
  138. "F11", // [122]
  139. "F12", // [123]
  140. "F13", // [124]
  141. "F14", // [125]
  142. "F15", // [126]
  143. "F16", // [127]
  144. "F17", // [128]
  145. "F18", // [129]
  146. "F19", // [130]
  147. "F20", // [131]
  148. "F21", // [132]
  149. "F22", // [133]
  150. "F23", // [134]
  151. "F24", // [135]
  152. "", // [136]
  153. "", // [137]
  154. "", // [138]
  155. "", // [139]
  156. "", // [140]
  157. "", // [141]
  158. "", // [142]
  159. "", // [143]
  160. "NUM_LOCK", // [144]
  161. "SCROLL_LOCK", // [145]
  162. "WIN_OEM_FJ_JISHO", // [146]
  163. "WIN_OEM_FJ_MASSHOU", // [147]
  164. "WIN_OEM_FJ_TOUROKU", // [148]
  165. "WIN_OEM_FJ_LOYA", // [149]
  166. "WIN_OEM_FJ_ROYA", // [150]
  167. "", // [151]
  168. "", // [152]
  169. "", // [153]
  170. "", // [154]
  171. "", // [155]
  172. "", // [156]
  173. "", // [157]
  174. "", // [158]
  175. "", // [159]
  176. "CIRCUMFLEX", // [160]
  177. "EXCLAMATION", // [161]
  178. "DOUBLE_QUOTE", // [162]
  179. "HASH", // [163]
  180. "DOLLAR", // [164]
  181. "PERCENT", // [165]
  182. "AMPERSAND", // [166]
  183. "UNDERSCORE", // [167]
  184. "OPEN_PAREN", // [168]
  185. "CLOSE_PAREN", // [169]
  186. "ASTERISK", // [170]
  187. "PLUS", // [171]
  188. "PIPE", // [172]
  189. "HYPHEN_MINUS", // [173]
  190. "OPEN_CURLY_BRACKET", // [174]
  191. "CLOSE_CURLY_BRACKET", // [175]
  192. "TILDE", // [176]
  193. "", // [177]
  194. "", // [178]
  195. "", // [179]
  196. "", // [180]
  197. "VOLUME_MUTE", // [181]
  198. "VOLUME_DOWN", // [182]
  199. "VOLUME_UP", // [183]
  200. "", // [184]
  201. "", // [185]
  202. "SEMICOLON", // [186]
  203. "EQUALS", // [187]
  204. "COMMA", // [188]
  205. "MINUS", // [189]
  206. "PERIOD", // [190]
  207. "SLASH", // [191]
  208. "BACK_QUOTE", // [192]
  209. "", // [193]
  210. "", // [194]
  211. "", // [195]
  212. "", // [196]
  213. "", // [197]
  214. "", // [198]
  215. "", // [199]
  216. "", // [200]
  217. "", // [201]
  218. "", // [202]
  219. "", // [203]
  220. "", // [204]
  221. "", // [205]
  222. "", // [206]
  223. "", // [207]
  224. "", // [208]
  225. "", // [209]
  226. "", // [210]
  227. "", // [211]
  228. "", // [212]
  229. "", // [213]
  230. "", // [214]
  231. "", // [215]
  232. "", // [216]
  233. "", // [217]
  234. "", // [218]
  235. "OPEN_BRACKET", // [219]
  236. "BACK_SLASH", // [220]
  237. "CLOSE_BRACKET", // [221]
  238. "QUOTE", // [222]
  239. "", // [223]
  240. "META", // [224]
  241. "ALTGR", // [225]
  242. "", // [226]
  243. "WIN_ICO_HELP", // [227]
  244. "WIN_ICO_00", // [228]
  245. "", // [229]
  246. "WIN_ICO_CLEAR", // [230]
  247. "", // [231]
  248. "", // [232]
  249. "WIN_OEM_RESET", // [233]
  250. "WIN_OEM_JUMP", // [234]
  251. "WIN_OEM_PA1", // [235]
  252. "WIN_OEM_PA2", // [236]
  253. "WIN_OEM_PA3", // [237]
  254. "WIN_OEM_WSCTRL", // [238]
  255. "WIN_OEM_CUSEL", // [239]
  256. "WIN_OEM_ATTN", // [240]
  257. "WIN_OEM_FINISH", // [241]
  258. "WIN_OEM_COPY", // [242]
  259. "WIN_OEM_AUTO", // [243]
  260. "WIN_OEM_ENLW", // [244]
  261. "WIN_OEM_BACKTAB", // [245]
  262. "ATTN", // [246]
  263. "CRSEL", // [247]
  264. "EXSEL", // [248]
  265. "EREOF", // [249]
  266. "PLAY", // [250]
  267. "ZOOM", // [251]
  268. "", // [252]
  269. "PA1", // [253]
  270. "WIN_OEM_CLEAR", // [254]
  271. "" // [255]
  272. ];
  273.  
  274.  
  275. (function() {
  276. 'use strict';
  277.  
  278. var settings = localStorage.getItem('miracleScripts');
  279.  
  280. if (settings == null) {
  281. settings = {
  282. bindings: {
  283. animation: 17, // CRTL
  284. paste: 36, // POS1
  285. dance: 35 // END
  286. },
  287. replacements: ':D|:smile:\n:*(|:sob:'
  288. };
  289. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  290. } else {
  291. settings = JSON.parse(settings);
  292. }
  293.  
  294. // We need to have a delay, because the menu is not laoded right away
  295. setTimeout(function() {
  296. var $playButton = $('#playBtn');
  297. var $specateButton = $('#spectateBtn');
  298.  
  299. $playButton.get(0).style.width = '40%';
  300. $specateButton.get(0).style.width = '40%';
  301.  
  302. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">⚙️</button>');
  303. $settingsButton.insertAfter($playButton);
  304.  
  305. var changeKey = function(event) {
  306. var name = this.name.substr(4);
  307. $(this).val(window.keyboardMap[event.keyCode]);
  308. settings.bindings[name] = event.keyCode;
  309. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  310. };
  311.  
  312. // Weird Agma scripting... press enter in the replacements textarea and the chatbox gets focused!
  313. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  314. // focus again (delayed) and go to the end of the text where the linebreak is.
  315. // We can improve this later on...
  316. var addReturn = function(event) {
  317. if (event.keyCode == 13) {
  318. var textarea = this;
  319. $(textarea).text($(this).text() + '\n').focus();
  320. setTimeout(function(){
  321. $(textarea).focus();
  322. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  323. }, 1);
  324. }
  325. };
  326. var changeReplacements = function(event) {
  327. settings.replacements = $(this).val();
  328. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  329. };
  330.  
  331. var $modal = $('<div id="miracle-settings" style="position: fixed; width: 100%; height: 100%; padding: 50px; color: #FF69B4; background-color: rgba(0,0,0,0.95); z-index: 999; display: none"></div>');
  332. $modal.append('<h1>Miracle Scripts Settings</h1>');
  333. $modal.append('<small style="color: #717171">This script does not work on mobile devices! Support: <a href="http://agarioforums.net/showthread.php?tid=61388" target="_blank" style="color: #717171">agarioforums.net</small>');
  334. var $element = $('<input name="key_animation" value="' + window.keyboardMap[settings.bindings.animation] + '"/>').keyup(changeKey);
  335. $modal.append('<br><br>Animation-Key:<br>', $element);
  336. $element = $('<input name="key_paste" value="' + window.keyboardMap[settings.bindings.paste] + '"/>').keyup(changeKey);
  337. $modal.append('<br>Paste-Key:<br>', $element);
  338. $element = $('<input name="key_dance" value="' + window.keyboardMap[settings.bindings.dance] + '"/>').keyup(changeKey);
  339. $modal.append('<br>Dance-Key:<br>', $element);
  340. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px">').text(settings.replacements).keydown(addReturn).keyup(changeReplacements);
  341. $modal.append('<br><br>Chat-Replacements (1 per line):<br>', $element, '<br>🧐 <span style="color: #717171">Avoid using the search text in the replacement!</span>');
  342. $modal.append($('<br><a href="#" style="display: inline-block; margin-top: 20px; padding: 10px; color: white; background-color: #FF69B4">Close</a>').click(function() { $modal.hide() }));
  343.  
  344. $('body').append($modal);
  345.  
  346. $settingsButton.click(function(event)
  347. {
  348. $modal.show();
  349.  
  350. event.preventDefault();
  351. });
  352. }, 500);
  353. })();
  354.  
  355.  
  356. (function() {
  357. 'use strict';
  358.  
  359. /**
  360. * Returns a random number between min (inclusive) and max (exclusive)
  361. * Source: MDN
  362. */
  363. var getRandomArbitrary = function(min, max) {
  364. return Math.random() * (max - min) + min;
  365. }
  366.  
  367. var chatAnimate = function()
  368. {
  369. // The available commands
  370. var items = ['spin', 'flip', 'shake', 'jump'];
  371.  
  372. // Choose randomly an item of the items array
  373. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  374. var item = items[Math.floor(Math.random()*items.length)];
  375.  
  376. // Combine with wacky
  377. item = 'wacky' + item;
  378.  
  379. // Add text into the chatbox and focus it (Note: acutally "/" is no longer necessary)
  380. $('#chtbox').val('/' + item).focus();
  381.  
  382. // Stop the event so that the pressed key won't be written into the chatbox!
  383. event.preventDefault();
  384. }
  385.  
  386. window.addEventListener('keydown', function(event)
  387. {
  388. // Do nothing if menu is open
  389. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  390. return;
  391. }
  392.  
  393. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  394.  
  395. if (event.keyCode == settings.bindings.animation) {
  396. chatAnimate();
  397. }
  398. });
  399. })();
  400.  
  401.  
  402. (function() {
  403. 'use strict';
  404.  
  405. window.addEventListener('keydown', function(event)
  406. {
  407. // Do nothing if menu is open
  408. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  409. return;
  410. }
  411.  
  412. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  413.  
  414. if (event.keyCode == settings.bindings.paste) {
  415. var text = prompt('Please paste your text or emjoi here');
  416.  
  417. // focus() only works when there is a delay after the prompt has been closed
  418. setTimeout(function(){
  419. // Add text into the chatbox and focus it
  420. $('#chtbox').val($('#chtbox').val() + text).focus();
  421. }, 200);
  422. }
  423. });
  424. })();
  425.  
  426.  
  427. (function() {
  428. 'use strict';
  429.  
  430. var angle = 0;
  431. var angleSpeed = 20;
  432. var distance = 50;
  433. var dancing = false;
  434.  
  435. var dance = function()
  436. {
  437. angle += angleSpeed;
  438. if (angle > 360) {
  439. angle = 0;
  440. }
  441.  
  442. var x = window.innerWidth/2 + Math.sin(angle * Math.PI / 180) * distance;
  443. var y = window.innerHeight/2 + Math.cos(angle * Math.PI / 180) * distance;
  444. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  445.  
  446. if (dancing) {
  447. window.requestAnimationFrame(dance);
  448. }
  449. }
  450.  
  451. window.addEventListener('keyup', function()
  452. {
  453. // Do nothing if menu is open
  454. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  455. return;
  456. }
  457.  
  458. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  459.  
  460. if (event.keyCode == settings.bindings.dance) {
  461. dancing = ! dancing;
  462.  
  463. if (dancing) {
  464. window.requestAnimationFrame(dance);
  465. }
  466. }
  467. });
  468. })();
  469.  
  470.  
  471. (function() {
  472. 'use strict';
  473.  
  474. $('#chtbox').keyup(function(event)
  475. {
  476. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  477.  
  478. var lines = settings.replacements.split('\n');
  479.  
  480. var text = $('#chtbox').val();
  481.  
  482. lines.forEach(function(line) {
  483. var replacement = line.split('|');
  484. if (replacement.length == 2) {
  485. text = text.replace(replacement[0], replacement[1]);
  486. $('#chtbox').val(text).focus();
  487. }
  488. });
  489. });
  490. })();
  491.  
  492.  
  493. console.log('🌸 Miracle Scripts successfully loaded!');
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.