Miracle Scripts

Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chatlog! Dance! Use chat replacements! Display the time!

当前为 2020-02-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 2.3.0
  5. // @description Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chatlog! Dance! Use chat replacements! Display the time!
  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 *://agma.io/
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. window.miracleScripts = {
  18.  
  19. // Source: http://stackoverflow.com/questions/1772179/get-character-value-from-keycode-in-javascript-then-trim#answer-23377822
  20. keyboardMap: [
  21. '', // [0]
  22. '', // [1]
  23. '', // [2]
  24. 'CANCEL', // [3]
  25. '', // [4]
  26. '', // [5]
  27. 'HELP', // [6]
  28. '', // [7]
  29. 'BACK_SPACE', // [8]
  30. 'TAB', // [9]
  31. '', // [10]
  32. '', // [11]
  33. 'CLEAR', // [12]
  34. 'ENTER', // [13]
  35. 'ENTER_SPECIAL', // [14]
  36. '', // [15]
  37. 'SHIFT', // [16]
  38. 'CONTROL', // [17]
  39. 'ALT', // [18]
  40. 'PAUSE', // [19]
  41. 'CAPS_LOCK', // [20]
  42. 'KANA', // [21]
  43. 'EISU', // [22]
  44. 'JUNJA', // [23]
  45. 'FINAL', // [24]
  46. 'HANJA', // [25]
  47. '', // [26]
  48. 'ESCAPE', // [27]
  49. 'CONVERT', // [28]
  50. 'NONCONVERT', // [29]
  51. 'ACCEPT', // [30]
  52. 'MODECHANGE', // [31]
  53. 'SPACE', // [32]
  54. 'PAGE_UP', // [33]
  55. 'PAGE_DOWN', // [34]
  56. 'END', // [35]
  57. 'HOME', // [36]
  58. 'LEFT', // [37]
  59. 'UP', // [38]
  60. 'RIGHT', // [39]
  61. 'DOWN', // [40]
  62. 'SELECT', // [41]
  63. 'PRINT', // [42]
  64. 'EXECUTE', // [43]
  65. 'PRINTSCREEN', // [44]
  66. 'INSERT', // [45]
  67. 'DELETE', // [46]
  68. '', // [47]
  69. '0', // [48]
  70. '1', // [49]
  71. '2', // [50]
  72. '3', // [51]
  73. '4', // [52]
  74. '5', // [53]
  75. '6', // [54]
  76. '7', // [55]
  77. '8', // [56]
  78. '9', // [57]
  79. 'COLON', // [58]
  80. 'SEMICOLON', // [59]
  81. 'LESS_THAN', // [60]
  82. 'EQUALS', // [61]
  83. 'GREATER_THAN', // [62]
  84. 'QUESTION_MARK', // [63]
  85. 'AT', // [64]
  86. 'A', // [65]
  87. 'B', // [66]
  88. 'C', // [67]
  89. 'D', // [68]
  90. 'E', // [69]
  91. 'F', // [70]
  92. 'G', // [71]
  93. 'H', // [72]
  94. 'I', // [73]
  95. 'J', // [74]
  96. 'K', // [75]
  97. 'L', // [76]
  98. 'M', // [77]
  99. 'N', // [78]
  100. 'O', // [79]
  101. 'P', // [80]
  102. 'Q', // [81]
  103. 'R', // [82]
  104. 'S', // [83]
  105. 'T', // [84]
  106. 'U', // [85]
  107. 'V', // [86]
  108. 'W', // [87]
  109. 'X', // [88]
  110. 'Y', // [89]
  111. 'Z', // [90]
  112. 'OS_KEY', // [91] Windows Key (Windows) or Command Key (Mac)
  113. '', // [92]
  114. 'CONTEXT_MENU', // [93]
  115. '', // [94]
  116. 'SLEEP', // [95]
  117. 'NUMPAD0', // [96]
  118. 'NUMPAD1', // [97]
  119. 'NUMPAD2', // [98]
  120. 'NUMPAD3', // [99]
  121. 'NUMPAD4', // [100]
  122. 'NUMPAD5', // [101]
  123. 'NUMPAD6', // [102]
  124. 'NUMPAD7', // [103]
  125. 'NUMPAD8', // [104]
  126. 'NUMPAD9', // [105]
  127. 'MULTIPLY', // [106]
  128. 'ADD', // [107]
  129. 'SEPARATOR', // [108]
  130. 'SUBTRACT', // [109]
  131. 'DECIMAL', // [110]
  132. 'DIVIDE', // [111]
  133. 'F1', // [112]
  134. 'F2', // [113]
  135. 'F3', // [114]
  136. 'F4', // [115]
  137. 'F5', // [116]
  138. 'F6', // [117]
  139. 'F7', // [118]
  140. 'F8', // [119]
  141. 'F9', // [120]
  142. 'F10', // [121]
  143. 'F11', // [122]
  144. 'F12', // [123]
  145. 'F13', // [124]
  146. 'F14', // [125]
  147. 'F15', // [126]
  148. 'F16', // [127]
  149. 'F17', // [128]
  150. 'F18', // [129]
  151. 'F19', // [130]
  152. 'F20', // [131]
  153. 'F21', // [132]
  154. 'F22', // [133]
  155. 'F23', // [134]
  156. 'F24', // [135]
  157. '', // [136]
  158. '', // [137]
  159. '', // [138]
  160. '', // [139]
  161. '', // [140]
  162. '', // [141]
  163. '', // [142]
  164. '', // [143]
  165. 'NUM_LOCK', // [144]
  166. 'SCROLL_LOCK', // [145]
  167. 'WIN_OEM_FJ_JISHO', // [146]
  168. 'WIN_OEM_FJ_MASSHOU', // [147]
  169. 'WIN_OEM_FJ_TOUROKU', // [148]
  170. 'WIN_OEM_FJ_LOYA', // [149]
  171. 'WIN_OEM_FJ_ROYA', // [150]
  172. '', // [151]
  173. '', // [152]
  174. '', // [153]
  175. '', // [154]
  176. '', // [155]
  177. '', // [156]
  178. '', // [157]
  179. '', // [158]
  180. '', // [159]
  181. 'CIRCUMFLEX', // [160]
  182. 'EXCLAMATION', // [161]
  183. 'DOUBLE_QUOTE', // [162]
  184. 'HASH', // [163]
  185. 'DOLLAR', // [164]
  186. 'PERCENT', // [165]
  187. 'AMPERSAND', // [166]
  188. 'UNDERSCORE', // [167]
  189. 'OPEN_PAREN', // [168]
  190. 'CLOSE_PAREN', // [169]
  191. 'ASTERISK', // [170]
  192. 'PLUS', // [171]
  193. 'PIPE', // [172]
  194. 'HYPHEN_MINUS', // [173]
  195. 'OPEN_CURLY_BRACKET', // [174]
  196. 'CLOSE_CURLY_BRACKET', // [175]
  197. 'TILDE', // [176]
  198. '', // [177]
  199. '', // [178]
  200. '', // [179]
  201. '', // [180]
  202. 'VOLUME_MUTE', // [181]
  203. 'VOLUME_DOWN', // [182]
  204. 'VOLUME_UP', // [183]
  205. '', // [184]
  206. '', // [185]
  207. 'SEMICOLON', // [186]
  208. 'EQUALS', // [187]
  209. 'COMMA', // [188]
  210. 'MINUS', // [189]
  211. 'PERIOD', // [190]
  212. 'SLASH', // [191]
  213. 'BACK_QUOTE', // [192]
  214. '', // [193]
  215. '', // [194]
  216. '', // [195]
  217. '', // [196]
  218. '', // [197]
  219. '', // [198]
  220. '', // [199]
  221. '', // [200]
  222. '', // [201]
  223. '', // [202]
  224. '', // [203]
  225. '', // [204]
  226. '', // [205]
  227. '', // [206]
  228. '', // [207]
  229. '', // [208]
  230. '', // [209]
  231. '', // [210]
  232. '', // [211]
  233. '', // [212]
  234. '', // [213]
  235. '', // [214]
  236. '', // [215]
  237. '', // [216]
  238. '', // [217]
  239. '', // [218]
  240. 'OPEN_BRACKET', // [219]
  241. 'BACK_SLASH', // [220]
  242. 'CLOSE_BRACKET', // [221]
  243. 'QUOTE', // [222]
  244. '', // [223]
  245. 'META', // [224]
  246. 'ALTGR', // [225]
  247. '', // [226]
  248. 'WIN_ICO_HELP', // [227]
  249. 'WIN_ICO_00', // [228]
  250. '', // [229]
  251. 'WIN_ICO_CLEAR', // [230]
  252. '', // [231]
  253. '', // [232]
  254. 'WIN_OEM_RESET', // [233]
  255. 'WIN_OEM_JUMP', // [234]
  256. 'WIN_OEM_PA1', // [235]
  257. 'WIN_OEM_PA2', // [236]
  258. 'WIN_OEM_PA3', // [237]
  259. 'WIN_OEM_WSCTRL', // [238]
  260. 'WIN_OEM_CUSEL', // [239]
  261. 'WIN_OEM_ATTN', // [240]
  262. 'WIN_OEM_FINISH', // [241]
  263. 'WIN_OEM_COPY', // [242]
  264. 'WIN_OEM_AUTO', // [243]
  265. 'WIN_OEM_ENLW', // [244]
  266. 'WIN_OEM_BACKTAB', // [245]
  267. 'ATTN', // [246]
  268. 'CRSEL', // [247]
  269. 'EXSEL', // [248]
  270. 'EREOF', // [249]
  271. 'PLAY', // [250]
  272. 'ZOOM', // [251]
  273. '', // [252]
  274. 'PA1', // [253]
  275. 'WIN_OEM_CLEAR', // [254]
  276. '' // [255]
  277. ],
  278.  
  279. // Don't remove the spaces, they are used as separators! Source: https://emojiterra.com/de/liste/
  280. emojis: '😀 😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😗 ☺️ 😚 😙 😋 😛 😜 😝 😐 😑 😶 😏 😒 😬 😌 😔 😪 😴 😷 😵 😎 😕 😟 😮 😯 😲 😳 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤 😡 😠 😈 👿 💀 💩 👹 👺 👻 👽 👾 😺 😸 😹 😻 😼 😽 🙀 😿 😾 🙈 🙉 🙊 💋 💌 💘 💝 💖 💗 💓 💞 💕 💟 💔 ❤️ 💛 💚 💙 💜 💯 💢 💥 💫 💦 💨 💣 💬 💭 💤 👋 ✋ 👌 ✌️ 👈 👉 👆 👇 ☝️ 👍 👎 ✊ 👊 👏 🙌 👐 🙏 💅 💪 👂 👃 👀 👅 👄 👶 👦 👧 👱 👨 👩 👴 👵 🙍 🙎 🙅 🙆 💁 🙋 🙇 👮 💂 👷 👸 👳 👲 👰 👼 🎅 💆 💇 🚶 🏃 💃 👯 🏇 🏂 🏄 🚣 🏊 🚴 🚵 🛀 👭 👫 👬 💏 💑 👪 👤 👥 👣 🐵 🐒 🐶 🐕 🐩 🐺 🐱 🐈 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇 🐻 🐨 🐼 🐾 🐔 🐓 🐣 🐤 🐥 🐦 🐧 🐸 🐊 🐢 🐍 🐲 🐉 🐳 🐋 🐬 🐟 🐠 🐡 🐙 🐚 🐌 🐛 🐜 🐝 🐞 💐 🌸 💮 🌹 🌺 🌻 🌼 🌷 🌱 🌲 🌳 🌴 🌵 🌾 🌿 🍀 🍁 🍂 🍃 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍅 🍆 🌽 🍄 🌰 🍞 🍖 🍗 🍔 🍟 🍕 🍳 🍲 🍱 🍘 🍙 🍚 🍛 🍜 🍝 🍠 🍢 🍣 🍤 🍥 🍡 🍦 🍧 🍨 🍩 🍪 🎂 🍰 🍫 🍬 🍭 🍮 🍯 🍼 ☕ 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍴 🔪 🌍 🌎 🌏 🌐 🗾 🌋 🗻 🏠 🏡 🏢 🏣 🏤 🏥 🏦 🏨 🏩 🏪 🏫 🏬 🏭 🏯 🏰 💒 🗼 🗽 ⛪ ⛲ ⛺ 🌁 🌃 🌄 🌅 🌆 🌇 🌉 ♨️ 🎠 🎡 🎢 💈 🎪 🚂 🚃 🚄 🚅 🚆 🚇 🚈 🚉 🚊 🚝 🚞 🚋 🚌 🚍 🚎 🚐 🚑 🚒 🚓 🚔 🚕 🚖 🚗 🚘 🚙 🚚 🚛 🚜 🚲 🚏 ⛽ 🚨 🚥 🚦 🚧 ⚓ ⛵ 🚤 🚢 ✈️ 💺 🚁 🚟 🚠 🚡 🚀 ⌛ ⏳ ⌚ ⏰ 🕛 🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 ☀️ 🌝 🌞 ⭐ 🌟 🌠 🌌 ☁️ ⛅ 🌀 🌈 🌂 ☔ ⚡ ❄️ ⛄ 🔥 💧 🌊 🎃 🎄 🎆 🎇 ✨ 🎈 🎉 🎊 🎋 🎍 🎎 🎏 🎐 🎑 🎀 🎁 🎫 🏆 ⚽ ⚾ 🏀 🏈 🏉 🎾 🎳 ⛳ 🎣 🎽 🎿 🎯 🎱 🔮 🎮 🎰 🎲 ♠️ ♥️ ♦️ ♣️ 🃏 🀄 🎴 🎭 🎨 👓 👔 👕 👖 👗 👘 👙 👚 👛 👜 👝 🎒 👞 👟 👠 👡 👢 👑 👒 🎩 🎓 💄 💍 💎 🔇 🔈 🔉 🔊 📢 📣 📯 🔔 🔕 🎼 🎵 🎶 🎤 🎧 📻 🎷 🎸 🎹 🎺 🎻 📱 📲 ☎️ 📞 📟 📠 🔋 🔌 💻 💽 💾 💿 📀 🎥 🎬 📺 📷 📹 📼 🔍 🔎 💡 🔦 🏮 📔 📕 📖 📗 📘 📙 📚 📓 📒 📃 📜 📄 📰 📑 🔖 💰 💴 💵 💶 💷 💸 💳 💹 💱 💲 ✉️ 📧 📨 📩 📤 📥 📦 📫 📪 📬 📭 📮 ✏️ ✒️ 📝 💼 📁 📂 📅 📆 📇 📈 📉 📊 📋 📌 📍 📎 📏 📐 ✂️ 🔒 🔓 🔏 🔐 🔑 🔨 🔫 🔧 🔩 🔗 🔬 🔭 📡 💉 💊 🚪 🚽 🚿 🛁 🚬 🗿 🏧 🚮 🚰 ♿ 🚹 🚺 🚻 🚼 🚾 🛂 🛃 🛄 🛅 ⚠️ 🚸 ⛔ 🚫 🚳 🚭 🚯 🚱 🚷 📵 🔞 ⬆️ ↗️ ➡️ ↘️ ⬇️ ↙️ ⬅️ ↖️ ↕️ ↔️ 🔃 🔄 🔙 🔚 🔛 🔜 🔝 🔯 ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ⛎ 🔀 🔁 🔂 ▶️ ◀️ 🔼 🔽 🎦 📶 📳 📴 ♻️ 🔱 📛 🔰 ⭕ ✅ ☑️ ✖️ ❌ ❎ ➕ ➖ ➗ ➰ ➿ 〽️ ✳️ ✴️ ❇️ ‼️ ⁉️ ❓ ❔ ❕ ❗ 〰️ ©️ ®️ ™️ 🔠 🔡 🔢 🔣 🔤 🅰️ 🆎 🅱️ 🆑 🆒 🆓 🆔 Ⓜ️ 🆕 🆖 🅾️ 🆗 🅿️ 🆘 🆙 🆚 🈁 🈂️ 🈷️ 🈶 🈯 🉐 🈹 🈚 🈲 🉑 🈸 🈴 🈳 ㊗️ ㊙️ 🈺 🈵 🔴 🔵 ⚫ ⚪ ⬛ ⬜ ◼️ ◻️ ◾ ◽ ▪️ ▫️ 🔶 🔷 🔸 🔹 🔺 🔻 💠 🔘 🔳 🔲 🏁 🚩 🎌',
  281.  
  282. init: function() {
  283. this.setupPolyfills();
  284.  
  285. this.config();
  286.  
  287. this.animation();
  288. this.chatLog();
  289. this.dance();
  290. this.favSkins();
  291. this.paste();
  292. this.replacements();
  293. this.fpsPing();
  294. this.timer();
  295. this.skinChanger();
  296. this.lineSplit();
  297. this.nameColor();
  298. this.commands();
  299.  
  300.  
  301. console.log('🌸 Miracle Scripts successfully loaded!');
  302. },
  303.  
  304. config: function() {
  305. var self = this;
  306. var settings;
  307.  
  308. var loadSettings = function (stringifiedSettings) {
  309. var defaultSettings = {
  310. // To get keycodes: https://keycode.info
  311. bindings: {
  312. animation: 17, // CTRL
  313. paste: 33, // PAGE UP
  314. dance: 34, // PAGE DOWN,
  315. chatLog: 76, // L
  316. },
  317. replacements: ":D|:smile:\n:*(|:sob:\n:'D|:sweat_smiley:\nxD|:joy:",
  318. primaryColor: '#FF69B4',
  319. targetLanguage: 'EN',
  320. favSkins: [],
  321. };
  322.  
  323. if (stringifiedSettings == null) {
  324. settings = defaultSettings;
  325. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  326. } else {
  327. settings = JSON.parse(stringifiedSettings);
  328.  
  329. // Update for settings:
  330. if (typeof settings.primaryColor === 'undefined') {
  331. settings.primaryColor = defaultSettings.primaryColor;
  332. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  333. }
  334. if (typeof settings.bindings.chatLog === 'undefined') {
  335. settings.bindings.chatLog = defaultSettings.bindings.chatLog;
  336. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  337. }
  338. if (typeof settings.favSkins === 'undefined') {
  339. settings.favSkins = defaultSettings.favSkins;
  340. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  341. }
  342. if (typeof settings.targetLanguage === 'undefined') {
  343. settings.targetLanguage = defaultSettings.targetLanguage;
  344. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  345. }
  346. if (typeof settings.quickSkins === 'undefined') {
  347. settings.quickSkins = [];
  348. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  349. }
  350. }
  351. };
  352. loadSettings(localStorage.getItem('miracleScripts'));
  353.  
  354. var applyPrimaryColor = function () {
  355. var primaryColorCss = '.miracle-primary-color-font { color: ' + settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + settings.primaryColor + ' !important }; ';
  356. $('body').append('<style>' + primaryColorCss + '</style>');
  357. };
  358. applyPrimaryColor();
  359.  
  360. var download = function (filename, text) {
  361. var element = document.createElement('a');
  362. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  363. element.setAttribute('download', filename);
  364.  
  365. element.style.display = 'none';
  366. document.body.appendChild(element);
  367.  
  368. element.click();
  369.  
  370. document.body.removeChild(element);
  371. };
  372.  
  373. // We need to have a delay, because the menu is not loaded right away
  374. setTimeout(function () {
  375. var $playButton = $('#playBtn');
  376. var $specateButton = $('#spectateBtn');
  377.  
  378. $playButton.get(0).style.width = '40%';
  379. $specateButton.get(0).style.width = '40%';
  380.  
  381. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">📜</button>');
  382. $settingsButton.insertAfter($playButton);
  383.  
  384. var changeKey = function (event) {
  385. var name = this.name.substr(4);
  386. $(this).val(self.keyboardMap[event.keyCode]);
  387. settings.bindings[name] = event.keyCode;
  388. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  389. };
  390.  
  391. var deleteKey = function () {
  392. var action = $(this).attr('data-action');
  393. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  394. settings.bindings[action] = null;
  395. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  396. };
  397.  
  398. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  399. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  400. // focus again (delayed) and go to the end of the text where the linebreak is.
  401. // We can improve this later on...
  402. var addReturn = function (event) {
  403. if (event.keyCode === 13) {
  404. var textarea = this;
  405. $(textarea).text($(this).text() + '\n').focus();
  406. setTimeout(function () {
  407. $(textarea).focus();
  408. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  409. }, 1);
  410. }
  411. };
  412. var changeReplacements = function () {
  413. settings.replacements = $(this).val();
  414. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  415. };
  416. var changePrimaryColor = function () {
  417. settings.primaryColor = $(this).val();
  418. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  419. applyPrimaryColor();
  420. };
  421. var changeTargetLanguage = function () {
  422. settings.targetLanguage = $(this).val();
  423. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  424. };
  425.  
  426. var $modal = $('<div id="miracle-settings" class="miracle-primary-color-font" style="position: fixed; width: 100%; height: 100%; padding: 50px; background-color: rgba(0,0,0,0.95); z-index: 999; display: none"></div>');
  427. $modal.append('<h1>Miracle Scripts Settings</h1>');
  428.  
  429. if (GM_info) {
  430. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  431. }
  432.  
  433. var $element = $('<input name="key_animation" value="' + self.keyboardMap[settings.bindings.animation] + '"/>').keyup(changeKey);
  434. $modal.append('<br><br>Animation-Key:<br>', $element);
  435. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  436. $modal.append($element);
  437.  
  438. $element = $('<input name="key_paste" value="' + self.keyboardMap[settings.bindings.paste] + '"/>').keyup(changeKey);
  439. $modal.append('<br>Paste-Key:<br>', $element);
  440. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  441. $modal.append($element);
  442.  
  443. $element = $('<input name="key_dance" value="' + self.keyboardMap[settings.bindings.dance] + '"/>').keyup(changeKey);
  444. $modal.append('<br>Dance-Key:<br>', $element);
  445. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  446. $modal.append($element);
  447.  
  448. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[settings.bindings.chatLog] + '"/>').keyup(changeKey);
  449. $modal.append('<br>Chat-Log-Key:<br>', $element);
  450. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  451. $modal.append($element);
  452.  
  453. $element = $('<select name="target_language"><option value="en">English</option><option value="de">German</option><option value="fr">French</option><option value="es">Spanish</option><option value="it">Italian</option><option value="nl">Dutch</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ru">Russian</option></select>').change(changeTargetLanguage);
  454. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  455. $element.get(0).value = settings.targetLanguage;
  456.  
  457. $element = $('<input type="color" name="favcolor" value="' + settings.primaryColor + '"/>').change(changePrimaryColor);
  458. $modal.append('<br><br>User interface color:<br>', $element);
  459.  
  460. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(settings.replacements).keydown(addReturn).keyup(changeReplacements);
  461. $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>');
  462.  
  463. $modal.append($('<br><a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-top: 20px; padding: 10px; color: white">Close</a>').click(function () {
  464. $modal.hide();
  465. }));
  466. $modal.append($('<a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-left: 20px; margin-top: 20px; padding: 10px; color: white">Export settings</a>').click(function () {
  467. download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  468. }));
  469. $modal.append($('<a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-left: 20px; margin-top: 20px; padding: 10px; color: white">Import settings</a>').click(function () {
  470. var stringifiedSettings = prompt('Paste the settings here');
  471. if (stringifiedSettings !== null) {
  472. loadSettings(stringifiedSettings);
  473. localStorage.setItem('miracleScripts', stringifiedSettings);
  474. $modal.hide();
  475. self.message('Settings loaded! Reload Agma to refresh. 😄');
  476. }
  477. }));
  478. $modal.append($('<a href="http://agarioforums.net/showthread.php?tid=61388" target="_blank" class="miracle-primary-color-background" style="display: inline-block; margin-left: 20px; margin-top: 20px; padding: 10px; color: white">Support</a>'));
  479.  
  480. $('body').append($modal);
  481.  
  482. $settingsButton.click(function (event) {
  483. $modal.show();
  484.  
  485. event.preventDefault();
  486. });
  487. }, 500);
  488. },
  489.  
  490. animation: function () {
  491. var self = this;
  492.  
  493. var chatAnimate = function () {
  494. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  495. self.message('Cannot send animation commands in private chat. 😢', true);
  496. return;
  497. }
  498.  
  499. // All available commands and combinations
  500. var items = ['wacky',
  501. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  502. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  503. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake', 'wackyshakeshakeshake',
  504. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump',
  505. ];
  506.  
  507. // Super-combinations!!
  508. if (self.getRandomArbitrary(1, 3) === 1) {
  509. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  510. }
  511.  
  512. // Choose randomly an item of the items array
  513. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  514. var item = items[Math.floor(Math.random() * items.length)];
  515.  
  516. // Attempt to avoid triggering spam protection - probably useless :-/
  517. item += String.fromCharCode(8203).repeat(self.getRandomArbitrary(1, 5));
  518.  
  519. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  520. $('#chtbox').val($('#chtbox').val() + item).focus();
  521.  
  522. // Stop the event so that the pressed key won't be written into the chat box!
  523. event.preventDefault();
  524. };
  525.  
  526. window.addEventListener('keydown', function (event) {
  527. // Do nothing if a menu is open
  528. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  529. return;
  530. }
  531.  
  532. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  533.  
  534. if (event.keyCode == settings.bindings.animation) {
  535. chatAnimate();
  536. }
  537. });
  538. },
  539.  
  540. paste: function () {
  541. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  542. var css = '#miracle-emojis .miracle-emoji { display: inline-block; width: 40px; margin: 0 2px 2px 0; padding: 5px; border: 1px solid #333; font-size: ' + emojiFontSize + 'px; }\n' +
  543. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  544.  
  545. var emojis = this.emojis.split(' ');
  546. var emojiCode = '';
  547.  
  548. emojis.forEach(function (emoji) {
  549. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  550. });
  551.  
  552. var addEmoji = function () {
  553. setTimeout(function () {
  554. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  555.  
  556. // Add text into the chatbox and focus it
  557. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  558. }, 200);
  559.  
  560. $modal.hide();
  561. };
  562.  
  563. var $modal = $('<div id="miracle-emojis" class="miracle-primary-color-font" style="position: fixed; width: 100%; height: 100%; padding: 50px; color: #FF69B4; background-color: rgba(0,0,0,0.95); overflow-y: auto; z-index: 999; display: none"></div>');
  564. $modal.append('<style>' + css + '</style>');
  565. $modal.append('<h1>Insert text or emoji</h1>');
  566. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  567. $modal.append('<br><br>Insert:<br>', $pasteInput);
  568. $modal.html($modal.html() + '<br><br>' + emojiCode);
  569. $modal.append($('<br><a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-top: 20px; padding: 10px; color: white">Add</a>').click(addEmoji));
  570. $modal.append($('<a href="#" class="miracle-primary-color-background" style="display: inline-block; float: right; margin-top: 20px; padding: 10px; color: white">Cancel</a>').click(function () {
  571. $modal.hide();
  572. }));
  573.  
  574. $modal.find('input[name=paste]').click(function () {
  575. var text = prompt('Please paste your text here!');
  576.  
  577. if (text !== null) {
  578. var $pasteInput = $modal.find('input[name=paste]');
  579.  
  580. // Add text into the paste input
  581. $pasteInput.val($pasteInput.val() + text);
  582. }
  583. });
  584.  
  585. $modal.click(function (event) {
  586. if (event.target.classList.contains('miracle-emoji')) {
  587. var $target = $(this).find('input[name=paste]');
  588. $target.val($target.val() + $(event.target).text());
  589.  
  590. event.preventDefault();
  591. }
  592. });
  593.  
  594. $modal.dblclick(function (event) {
  595. if (event.target.classList.contains('miracle-emoji')) {
  596. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  597. $(this).hide();
  598.  
  599. event.preventDefault();
  600. }
  601. });
  602.  
  603. $('body').append($modal);
  604.  
  605. window.addEventListener('keydown', function (event) {
  606. // Do nothing if a menu is open
  607. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  608. return;
  609. }
  610.  
  611. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  612.  
  613. if (event.keyCode == settings.bindings.paste) {
  614. $modal.find('input[name=paste]').val('');
  615. $modal.toggle();
  616. }
  617. });
  618. },
  619.  
  620. dance: function () {
  621. var angle = 0;
  622. var angleSpeed = 20;
  623. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  624. var dancing = false;
  625.  
  626. var dance = function () {
  627. angle += angleSpeed;
  628. if (angle > 360) {
  629. angle = 0;
  630. }
  631.  
  632. var x = window.innerWidth / 2 + Math.sin(angle * Math.PI / 180) * distance;
  633. var y = window.innerHeight / 2 + Math.cos(angle * Math.PI / 180) * distance;
  634. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  635.  
  636. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  637. if (document.getElementById('advert').style.display !== 'none') {
  638. dancing = false;
  639. }
  640. if (dancing) {
  641. window.requestAnimationFrame(dance);
  642. }
  643. };
  644.  
  645. window.addEventListener('keyup', function () {
  646. // Do nothing if a menu is open
  647. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  648. return;
  649. }
  650.  
  651. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  652.  
  653. if (event.keyCode == settings.bindings.dance) {
  654. dancing = !dancing;
  655.  
  656. if (dancing) {
  657. window.requestAnimationFrame(dance);
  658. }
  659. }
  660. });
  661. },
  662.  
  663. replacements: function () {
  664. $('#chtbox').keyup(function () {
  665. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  666.  
  667. var lines = settings.replacements.split('\n');
  668.  
  669. var text = $('#chtbox').val();
  670.  
  671. lines.forEach(function (line) {
  672. var replacement = line.split('|');
  673. if (replacement.length === 2) {
  674. text = text.replace(replacement[0], replacement[1]);
  675. $('#chtbox').val(text).focus();
  676. }
  677. });
  678. });
  679. },
  680.  
  681. chatLog: function () {
  682. // We escape the message before we print them, so no one can inject JS code!
  683. var htmlEntities = function (str) {
  684. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  685. };
  686.  
  687. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  688. var lastChatNickname = null;
  689. var lastChatNicknameColor = null;
  690. var chatLogCode = '';
  691. var chatLog = [];
  692. CanvasRenderingContext2D.prototype.fillText = function () {
  693. if (this.canvas.id !== 'leaderboard' && this.canvas.height === 23) {
  694. var text = arguments[0];
  695.  
  696. // Sometimes also numbers (int) are printed so we filter for strings
  697. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  698. // Dirty fix for the missing icon in the initial welcome messages
  699. if (text == '') {
  700. text = '📢';
  701. }
  702. lastChatNickname = text;
  703. lastChatNicknameColor = this.fillStyle;
  704. }
  705. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  706. // Unfortunately chat messages will be printed more than just once and I don't know
  707. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  708. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  709. var found = false;
  710. for (var i = 0; i < chatLog.length; i++) {
  711. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  712. found = true;
  713. break;
  714. }
  715. }
  716.  
  717. if (!found) {
  718. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  719. chatLogCode += '<div><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  720. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  721. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  722. }
  723. }
  724. }
  725.  
  726. return originalFillText.apply(this, arguments);
  727. };
  728.  
  729. var performSearch = function (searchElement) {
  730. var subject = searchElement.value.toLowerCase();
  731.  
  732. $('#miracle-complete-chatlog div').each(function () {
  733. var $entry = $(this);
  734.  
  735. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  736. $entry.hide();
  737. } else {
  738. $entry.show();
  739. }
  740. });
  741. };
  742.  
  743. var $modal = $('<div id="miracle-chatlog" class="miracle-primary-color-font" style="position: fixed; width: 100%; height: 100%; padding: 50px; color: #FF69B4; background-color: rgba(0,0,0,0.95); user-select: text; overflow-y: auto; z-index: 999; display: none"></div>');
  744. $modal.append('<style>#miracle-complete-chatlog div:hover { background-color: rgba(255,255,255,0.1) } #miracle-complete-chatlog .time { padding-right: 10px; color: #666; }</style>');
  745. $modal.append('<h1>Complete chatlog</h1><br>');
  746. $modal.append('<div id="miracle-complete-chatlog"></div>');
  747. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  748. performSearch(this);
  749. }));
  750. $modal.append($('<br><a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-top: 20px; padding: 10px; color: white">Close</a>').click(function () {
  751. $modal.hide();
  752. }));
  753. $('body').append($modal);
  754.  
  755. $('#miracle-complete-chatlog').dblclick(function (event) {
  756. var $clickTarget;
  757.  
  758. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  759. if (event.target.tagName.toLowerCase() === 'span') {
  760. $clickTarget = $(event.target).parent();
  761. } else {
  762. $clickTarget = $(event.target);
  763. }
  764.  
  765. var message = $clickTarget.find('.message').text();
  766.  
  767. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  768. if (message.substr(0, 2) === ': ') {
  769. message = message.substr(2);
  770. }
  771.  
  772. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  773.  
  774. window.open('https://www.deepl.com/translator#en/' + settings.targetLanguage + '/' + message);
  775. });
  776.  
  777. window.addEventListener('keyup', function (event) {
  778. // Ignore text input field so typing in them is possible
  779. if (document.activeElement.type === 'text' || document.activeElement.type === 'password') {
  780. return;
  781. }
  782.  
  783. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  784.  
  785. if (event.keyCode == settings.bindings.chatLog) {
  786. $('#miracle-complete-chatlog').html(chatLogCode);
  787. $modal.toggle();
  788. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  789. }
  790. });
  791. },
  792.  
  793. favSkins: function () {
  794. // We need to have a delay, because the menu is not loaded right away
  795. setTimeout(function () {
  796. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  797.  
  798. var favIconClick = function () {
  799. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  800.  
  801. if (settings.favSkins.includes(id)) {
  802. $(this).addClass('skin-not-fav');
  803. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  804. var index = settings.favSkins.indexOf(id);
  805. settings.favSkins.splice(index, 1);
  806. } else {
  807. $(this).removeClass('skin-not-fav');
  808. settings.favSkins.push(id);
  809. }
  810. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  811. renderFavSkins();
  812. };
  813.  
  814. var renderFavSkins = function () {
  815. var $skins = null;
  816.  
  817. if ($('#fav-skins').length > 0) {
  818. $skins = $('#fav-skins');
  819. $skins.html('');
  820. } else {
  821. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  822. $skins.insertAfter('#publicSkinsHeader');
  823.  
  824. $('#fav-skins').click(function (event) {
  825. if (event.target.tagName.toLowerCase() === 'span') {
  826. favIconClick.apply(event.target);
  827. }
  828. });
  829. }
  830. settings.favSkins.forEach(function (id) {
  831. $skins.append('<div style="float: left; padding: 5px;"><img style="border: 1px solid rgba(0,0,0,.25); border-radius: 50%; box-shadow: 0 0 2px #000;" src="skins/' + id + '_lo.png?u=1575650762" alt=""><h4><span style="cursor: pointer">⭐</span></h4><button class="btn btn-primary skinuse-btn" onclick="toggleSkin(' + id + ');">Use</button></div>');
  832. });
  833. $skins.append('<div style="clear: both"></div>');
  834. };
  835.  
  836. var addFavIcons = function () {
  837. var $skins = $('#publicSkinsPage');
  838. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  839.  
  840. $skins.find('h4').each(function () {
  841. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  842. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  843.  
  844. $favIcon.click(favIconClick);
  845.  
  846. $(this).append($favIcon);
  847.  
  848. if (!settings.favSkins.includes(id)) {
  849. $favIcon.addClass('skin-not-fav');
  850. }
  851. });
  852. };
  853. var initialized = false;
  854. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  855. if (!initialized) {
  856. var checkState = function () {
  857. if ($('#publicSkinsPage').html() !== '') {
  858. addFavIcons();
  859. renderFavSkins();
  860. } else {
  861. setTimeout(checkState, 30);
  862. }
  863. };
  864. checkState();
  865. initialized = true;
  866. }
  867. });
  868. $('#phpSkins').click(function (event) {
  869. if (event.target.classList.contains('publicskins-nav-btn')) {
  870. addFavIcons();
  871. }
  872. });
  873.  
  874. }, 500);
  875. },
  876.  
  877. lineSplit: function() {
  878. var self = this;
  879.  
  880. window.addEventListener('miracleCommand', function(commandEvent) {
  881. if (commandEvent.command === '/linesplit') {
  882. self.lineSplitAt = Date.now();
  883. self.message('Linesplit •••••');
  884.  
  885. var doSplit = function() {
  886. if (Date.now() - self.lineSplitAt < 1000) {
  887. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  888. var x = window.innerWidth / 2;
  889. var y = factor * (window.innerHeight / 2);
  890.  
  891. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  892.  
  893. window.requestAnimationFrame(doSplit);
  894. } else {
  895. if (Date.now() - self.lineSplitAt < 3000) {
  896. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  897. var hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  898. $('body').trigger($.Event('keydown', { keyCode: hotkeys.Space.c}));
  899. $('body').trigger($.Event('keyup', { keyCode: hotkeys.Space.c}));
  900. self.splitAt = Date.now();
  901. }
  902.  
  903. window.requestAnimationFrame(doSplit);
  904. }
  905. }
  906. };
  907. doSplit();
  908. $('#chtbox').val('');
  909. }
  910. });
  911. },
  912.  
  913. fpsPing: function () {
  914. window.addEventListener('miracleCommand', function(commandEvent) {
  915. if (commandEvent.command === 'ping' || commandEvent.command === '/ping') {
  916. window.setFPS(1);
  917. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  918. if (parseInt(ping) > 0) {
  919. if (parseInt(ping) >= 0 && parseInt(ping) < 40) { pingRating = 'Perfect! ✔️'; }
  920. if (parseInt(ping) >= 40 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  921. if (parseInt(ping) >= 70 && parseInt(ping) < 110) { pingRating = 'Acceptable! ✔️'; }
  922. if (parseInt(ping) >= 110 && parseInt(ping) < 150) { pingRating = 'Bad! ❌'; }
  923. if (parseInt(ping) >= 150 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  924. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  925. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  926. } else {
  927. ping = '∞ (infinite) ';
  928. }
  929. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating).focus();
  930. }
  931. if (commandEvent.command === 'fps' || commandEvent.command === '/fps') {
  932. window.setFPS(1);
  933. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  934. if (parseInt(fps) > 0) {
  935. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  936. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  937. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  938. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  939. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  940. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  941. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  942. } else {
  943. fpsRating = '';
  944. }
  945.  
  946. $('#chtbox').val('has ' + fps + ' frames per second (fps). ' + fpsRating).focus();
  947. }
  948. });
  949. },
  950.  
  951. timer: function() {
  952. var self = this;
  953.  
  954. var timerStartedAt = null;
  955. var timerMinutes = null;
  956. var timeoutId = null;
  957. var updateId = null;
  958.  
  959. var $countdownUi = $('<div style="position: fixed; right: 20px; bottom: 225px; z-index: 9999; color: #3e3e3e; pointer-events: none"></div>');
  960. $('body').append($countdownUi);
  961.  
  962. window.addEventListener('miracleCommand', function(commandEvent) {
  963. if (commandEvent.command === 'timer' || commandEvent.command === '/timer') {
  964. var argument1 = commandEvent.argument1;
  965. var argument2 = commandEvent.argument2;
  966.  
  967. if (argument1) {
  968. timerMinutes = parseInt(argument1);
  969. if (argument2 === 'h' || argument2 === 'hour' || argument2 === 'hours') {
  970. timerMinutes *= 60;
  971. }
  972. if (timeoutId !== null) {
  973. clearTimeout(timeoutId);
  974. }
  975.  
  976. if (argument1 === '0' || argument1 === 'reset' || argument1 === 'stop') {
  977. self.message('🗑️ Timer removed');
  978. } else {
  979. timerStartedAt = Date.now();
  980. var updateUi = function () {
  981. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  982. $countdownUi.text('🕒 ' + Math.ceil(remaining) + 'm');
  983. };
  984. updateId = setInterval(updateUi, 10000);
  985. updateUi();
  986. timeoutId = setTimeout(function () {
  987. timeoutId = null;
  988. window.clearInterval(updateId);
  989. $countdownUi.text('');
  990. window.alert('🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.');
  991. }, timerMinutes * 60 * 1000);
  992.  
  993. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  994. }
  995. } else {
  996. if (timeoutId === null) {
  997. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  998. } else {
  999. var remaining = ((timeoutStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1000. self.message('🕒 ' + Math.round(remaining * 10) / 10 + ' minutes remaining.');
  1001. }
  1002. }
  1003. $('#chtbox').val('').focus();
  1004. }
  1005. });
  1006. },
  1007.  
  1008. skinChanger: function() {
  1009. var self = this;
  1010.  
  1011. // When the user changes the skin, display ID of the picked skin
  1012. var originalToggleSkin = window.toggleSkin;
  1013. window.toggleSkin = function () {
  1014. self.message('Picked skin with ID ' + arguments[0]);
  1015.  
  1016. return originalToggleSkin.apply(this, arguments);
  1017. };
  1018.  
  1019. window.addEventListener('miracleCommand', function(commandEvent) {
  1020. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  1021.  
  1022. var useSkin = function (skinSlot, skinId) {
  1023. if (skinId) {
  1024. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  1025. var skinUri = self.getSkinUrl();
  1026. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1027. }
  1028.  
  1029. skinId = parseInt(skinId);
  1030. settings.quickSkins[skinSlot - 1] = skinId;
  1031. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  1032. } else {
  1033. skinId = settings.quickSkins[skinSlot - 1];
  1034. if (!skinId) {
  1035. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  1036. $('#chtbox').val('').focus();
  1037. return;
  1038. }
  1039. }
  1040.  
  1041. window.azad(true);
  1042.  
  1043. setTimeout(function () {
  1044. $('#skinExampleMenu').click();
  1045.  
  1046. var checkLoaded = function () {
  1047. var loaded = ($('#skinsFree tr').length > 1);
  1048. if (loaded) {
  1049. window.toggleSkin(skinId);
  1050.  
  1051. setTimeout(function () {
  1052. $('#shopModalDialog button.close').click();
  1053.  
  1054. setTimeout(function () {
  1055. window.setNick(document.getElementById('nick').value);
  1056. }, 200);
  1057. }, 200);
  1058. } else {
  1059. setTimeout(checkLoaded, 300);
  1060. }
  1061. };
  1062. checkLoaded();
  1063. }, 200);
  1064.  
  1065. $('#chtbox').val('').focus();
  1066. };
  1067.  
  1068. if (commandEvent.command === 'skin1' || commandEvent.command === '/skin1') {
  1069. useSkin(1, commandEvent.argument1);
  1070. }
  1071. if (commandEvent.command === 'skin2' || commandEvent.command === '/skin2') {
  1072. useSkin(2, commandEvent.argument1);
  1073. }
  1074. if (commandEvent.command === 'skin3' || commandEvent.command === '/skin3') {
  1075. useSkin(3, commandEvent.argument1);
  1076. }
  1077. if (commandEvent.command === 'skin4' || commandEvent.command === '/skin4') {
  1078. useSkin(4, commandEvent.argument1);
  1079. }
  1080. if (commandEvent.command === 'skin5' || commandEvent.command === '/skin5') {
  1081. useSkin(5, commandEvent.argument1);
  1082. }
  1083. if (commandEvent.command === 'skin6' || commandEvent.command === '/skin6') {
  1084. useSkin(6, commandEvent.argument1);
  1085. }
  1086. if (commandEvent.command === 'skin7' || commandEvent.command === '/skin7') {
  1087. useSkin(7, commandEvent.argument1);
  1088. }
  1089. if (commandEvent.command === 'skin8' || commandEvent.command === '/skin8') {
  1090. useSkin(8, commandEvent.argument1);
  1091. }
  1092. if (commandEvent.command === 'skin9' || commandEvent.command === '/skin9') {
  1093. useSkin(9, commandEvent.argument1);
  1094. }
  1095. if (commandEvent.command === 'skin10' || commandEvent.command === '/skin10') {
  1096. useSkin(10, commandEvent.argument1);
  1097. }
  1098. if (commandEvent.command === 'skin11' || commandEvent.command === '/skin11') {
  1099. useSkin(11, commandEvent.argument1);
  1100. }
  1101. if (commandEvent.command === 'skin12' || commandEvent.command === '/skin12') {
  1102. useSkin(12, commandEvent.argument1);
  1103. }
  1104. if (commandEvent.command === 'skin13' || commandEvent.command === '/skin13') {
  1105. useSkin(13, commandEvent.argument1);
  1106. }
  1107. if (commandEvent.command === 'skin14' || commandEvent.command === '/skin14') {
  1108. useSkin(14, commandEvent.argument1);
  1109. }
  1110. if (commandEvent.command === 'skin15' || commandEvent.command === '/skin15') {
  1111. useSkin(15, commandEvent.argument1);
  1112. }
  1113. });
  1114. },
  1115.  
  1116. nameColor: function() {
  1117. var self = this;
  1118. var isGoldMember;
  1119. var isActive = false;
  1120. var isNameGolden = $('#cGoldName').is(':checked');
  1121. var intervalId;
  1122.  
  1123. window.addEventListener('miracleCommand', function(commandEvent) {
  1124. if (commandEvent.command === '/namecolor') {
  1125. isGoldMember = $('#dashPanel .memberType p').text() === 'GOLD MEMBER';
  1126. if (! isGoldMember) {
  1127. self.message('💰 You need to be gold member');
  1128. return;
  1129. }
  1130.  
  1131. isActive = ! isActive;
  1132.  
  1133. if (isActive) {
  1134. var changeNameColor = function() {
  1135. isNameGolden = ! isNameGolden;
  1136. window.setGoldNickname(isNameGolden);
  1137. console.log('Nickname color set to: ' + isNameGolden);
  1138. };
  1139. intervalId = setInterval(changeNameColor, 1000);
  1140. } else {
  1141. window.clearInterval(intervalId);
  1142. }
  1143. $('#chtbox').val('');
  1144. }
  1145. });
  1146. },
  1147.  
  1148. commands: function () {
  1149. var self = this;
  1150. var minutes;
  1151.  
  1152. var sessionStartedAt = Date.now();
  1153.  
  1154. $('#chtbox').keydown(function (event) {
  1155. if (event.keyCode === 13) {
  1156. var message = $('#chtbox').val();
  1157. var command = message.split(' ')[0];
  1158. var argument1 = message.split(' ')[1];
  1159. var argument2 = message.split(' ')[2];
  1160.  
  1161. if (message === 'time' || command === '/time') {
  1162. var now = new Date();
  1163. $('#chtbox').val('Local time: ' + now.toLocaleString()).focus();
  1164. }
  1165.  
  1166. if (message === 'minutes' || command === '/minutes' || message === 'online' || command === '/online') {
  1167. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  1168. if (minutes > 60) {
  1169. minutes = '' + minutes;
  1170. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1171. }
  1172. $('#chtbox').val('has played for: ' + minutes + ' Minutes in the current session').focus();
  1173. }
  1174.  
  1175. if (command === '/solo') {
  1176. $('#chtbox').val('⚠️⚠️⚠️ SOLO SERVER ⚠️⚠️⚠️ No teaming!! No hay equipo!! Pas d\'équipe!! Kein Teaming!!').focus();
  1177. }
  1178.  
  1179. if (command === '/miracle') {
  1180. var miracleInfo = 'is using 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴, version ';
  1181.  
  1182. if (window.GM_info) {
  1183. miracleInfo += window.GM_info.script.version;
  1184. } else {
  1185. miracleInfo += 'unknown';
  1186. }
  1187.  
  1188. $('#chtbox').val(miracleInfo).focus();
  1189. }
  1190.  
  1191. if (command === '/miraclehelp') {
  1192.  
  1193. $('#chtbox').val('').focus();
  1194.  
  1195. alert('Available command are: \n\n' +
  1196. '/miraclehelp - show this help\n' +
  1197. '/miracle - show version info\n' +
  1198. '/skin<n> - change to skin <n>\n' +
  1199. '/skin<n> this - store current skin as skin <n>\n' +
  1200. '/skin<n> <id> - store skin with ID <id> as skin <n>\n' +
  1201. '/say <text> - send chat message with fancy font\n' +
  1202. '/say<n> <text> - send chat message with fancy font number <n>\n' +
  1203. '/timer <n> - set time for <n> minutes<n>\n' +
  1204. '/timer <n> h - set time for <n> hours<n>\n' +
  1205. '/timer stop - stop timer\n' +
  1206. '/fps - send chat message with current fps\n' +
  1207. '/ping - send chat messager with current ping\n' +
  1208. '/solo - show solo server message\n' +
  1209. '/namecolor - let your name change its color\n' +
  1210. '/linesplit - let your cell make a linesplit\n'
  1211. );
  1212. }
  1213.  
  1214. if (command.substr(0, 4) === '/say') {
  1215. var fontIndex = command.charAt(4) - 1;
  1216. if (fontIndex === NaN || fontIndex < 0 || fontIndex > Object.getOwnPropertyNames(self.fonts).length - 1) {
  1217. fontIndex = 1;
  1218. }
  1219. $('#chtbox').val(self.useUnicodeFont(message.substr(message.indexOf(' ') + 1), Object.getOwnPropertyNames(self.fonts)[fontIndex])).focus();
  1220. }
  1221.  
  1222. if (command === '/waste') {
  1223. // TODO implement
  1224. }
  1225.  
  1226. var commandEvent = new Event('miracleCommand');
  1227. commandEvent.message = message;
  1228. commandEvent.command = command;
  1229. commandEvent.argument1 = argument1;
  1230. commandEvent.argument2 = argument2;
  1231. window.dispatchEvent(commandEvent);
  1232. }
  1233. });
  1234. },
  1235.  
  1236. /**
  1237. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  1238. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  1239. */
  1240. fonts: {
  1241. doubleStruck : function(charCode) {
  1242. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  1243. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  1244. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  1245. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  1246. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  1247. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  1248. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  1249. if (charCode >= 65 && charCode <= 90) {
  1250. return String.fromCodePoint(0x1D538 + charCode - 65);
  1251. }
  1252. if (charCode >= 97 && charCode <= 122) {
  1253. return String.fromCodePoint(0x1D552 + charCode - 97);
  1254. }
  1255. if (charCode >= 48 && charCode <= 57) {
  1256. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  1257. }
  1258. return String.fromCharCode(charCode);
  1259. },
  1260.  
  1261. monospace : function(charCode) {
  1262. if (charCode >= 65 && charCode <= 90) {
  1263. return String.fromCodePoint(0x1D670 + charCode - 65);
  1264. }
  1265. if (charCode >= 97 && charCode <= 122) {
  1266. return String.fromCodePoint(0x1D68A + charCode - 97);
  1267. }
  1268. if (charCode >= 48 && charCode <= 57) {
  1269. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  1270. }
  1271. return String.fromCharCode(charCode);
  1272. },
  1273.  
  1274. scriptBold : function(charCode) {
  1275. if (charCode >= 65 && charCode <= 90) {
  1276. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  1277. }
  1278. if (charCode >= 97 && charCode <= 122) {
  1279. return String.fromCodePoint(0x1D4EA + charCode - 97);
  1280. }
  1281. if (charCode >= 48 && charCode <= 57) {
  1282. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1283. }
  1284. return String.fromCharCode(charCode);
  1285. },
  1286.  
  1287. frakturBold : function(charCode) {
  1288. if (charCode >= 65 && charCode <= 90) {
  1289. return String.fromCodePoint(0x1D56C + charCode - 65);
  1290. }
  1291. if (charCode >= 97 && charCode <= 122) {
  1292. return String.fromCodePoint(0x1D586 + charCode - 97);
  1293. }
  1294. if (charCode >= 48 && charCode <= 57) {
  1295. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1296. }
  1297. return String.fromCharCode(charCode);
  1298. },
  1299.  
  1300. serifItalic: function(charCode) {
  1301. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  1302. if (charCode >= 65 && charCode <= 90) {
  1303. return String.fromCodePoint(0x1D434 + charCode - 65);
  1304. }
  1305. if (charCode >= 97 && charCode <= 122) {
  1306. return String.fromCodePoint(0x1D44E + charCode - 97);
  1307. }
  1308. return String.fromCharCode(charCode);
  1309. }
  1310. },
  1311.  
  1312. useUnicodeFont: function(text, font) {
  1313. var converted = '';
  1314. for (var i = 0; i < text.length; i++) {
  1315. converted += this.fonts[font](text.charCodeAt(i));
  1316. }
  1317.  
  1318. return converted;
  1319. },
  1320.  
  1321. /**
  1322. * Returns a random number between min (inclusive) and max (exclusive)
  1323. * Source: MDN
  1324. */
  1325. getRandomArbitrary: function (min, max) {
  1326. return Math.random() * (max - min) + min;
  1327. },
  1328.  
  1329. /**
  1330. * Use the curser div to display a message at the top of the screen.
  1331. *
  1332. * @param message
  1333. * @param isError
  1334. */
  1335. message: function (message, isError) {
  1336. var curser = document.querySelector('#curser');
  1337.  
  1338. curser.textContent = message;
  1339. curser.style.display = 'block';
  1340. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  1341.  
  1342. window.setTimeout(function () {
  1343. curser.style.display = 'none';
  1344. }, 5000);
  1345. },
  1346.  
  1347. /**
  1348. * Returns the URI of my skin or null if not skin has been set.
  1349. * Use this.skinUrl() to get it.
  1350. */
  1351. getSkinUrl: function() {
  1352. var skinUrlRaw = $('#skinExampleMenu').css('background-image');
  1353.  
  1354. var parts = skinUrlRaw.split('"');
  1355.  
  1356. if (parts.length !== 3) {
  1357. return null;
  1358. } else {
  1359. return parts[1];
  1360. }
  1361. },
  1362.  
  1363. setupPolyfills: function() {
  1364. // Polyfill for old browser so they have String.fromCodePoint()
  1365. if (!String.fromCodePoint) (function(stringFromCharCode) {
  1366. var fromCodePoint = function(_) {
  1367. var codeUnits = [], codeLen = 0, result = "";
  1368. for (var index=0, len = arguments.length; index !== len; ++index) {
  1369. var codePoint = +arguments[index];
  1370. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  1371. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  1372. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  1373. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  1374. throw RangeError("Invalid code point: " + codePoint);
  1375. if (codePoint <= 0xFFFF) { // BMP code point
  1376. codeLen = codeUnits.push(codePoint);
  1377. } else { // Astral code point; split in surrogate halves
  1378. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  1379. codePoint -= 0x10000;
  1380. codeLen = codeUnits.push(
  1381. (codePoint >> 10) + 0xD800, // highSurrogate
  1382. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  1383. );
  1384. }
  1385. if (codeLen >= 0x3fff) {
  1386. result += stringFromCharCode.apply(null, codeUnits);
  1387. codeUnits.length = 0;
  1388. }
  1389. }
  1390. return result + stringFromCharCode.apply(null, codeUnits);
  1391. };
  1392. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  1393. Object.defineProperty(String, "fromCodePoint", {
  1394. "value": fromCodePoint, "configurable": true, "writable": true
  1395. });
  1396. } catch(e) {
  1397. String.fromCodePoint = fromCodePoint;
  1398. }
  1399. }(String.fromCharCode));
  1400. },
  1401. };
  1402.  
  1403. window.miracleScripts.init();
  1404. })();
  1405.  
  1406. window.addEventListener('keydown', function (event) {
  1407. if (event.key == "------w") {
  1408. event.preventDefault();
  1409. event.stopPropagation();
  1410. event.key ="x";
  1411. event.code = "KeyX";
  1412. event.which = 77;
  1413. event.code = 77;
  1414. }
  1415. });