Miracle Scripts

Best Agma.io script with tons of features

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

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 4.2.1
  5. // @description Best Agma.io script with tons of features
  6. // @author Arimas
  7. // @license MIT
  8. // @icon https://abload.de/img/mh3k8o.png
  9. // @match *://agma.io/
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.miracleScripts = {
  17.  
  18. news: '3,000 Miracle Scripts installations, yay! 🥳',
  19.  
  20. // Source: http://stackoverflow.com/questions/1772179/get-character-value-from-keycode-in-javascript-then-trim#answer-23377822
  21. keyboardMap: [
  22. '', // [0]
  23. '', // [1]
  24. '', // [2]
  25. 'CANCEL', // [3]
  26. '', // [4]
  27. '', // [5]
  28. 'HELP', // [6]
  29. '', // [7]
  30. 'BACK_SPACE', // [8]
  31. 'TAB', // [9]
  32. '', // [10]
  33. '', // [11]
  34. 'CLEAR', // [12]
  35. 'ENTER', // [13]
  36. 'ENTER_SPECIAL', // [14]
  37. '', // [15]
  38. 'SHIFT', // [16]
  39. 'CONTROL', // [17]
  40. 'ALT', // [18]
  41. 'PAUSE', // [19]
  42. 'CAPS_LOCK', // [20]
  43. 'KANA', // [21]
  44. 'EISU', // [22]
  45. 'JUNJA', // [23]
  46. 'FINAL', // [24]
  47. 'HANJA', // [25]
  48. '', // [26]
  49. 'ESCAPE', // [27]
  50. 'CONVERT', // [28]
  51. 'NONCONVERT', // [29]
  52. 'ACCEPT', // [30]
  53. 'MODECHANGE', // [31]
  54. 'SPACE', // [32]
  55. 'PAGE_UP', // [33]
  56. 'PAGE_DOWN', // [34]
  57. 'END', // [35]
  58. 'HOME', // [36]
  59. 'LEFT', // [37]
  60. 'UP', // [38]
  61. 'RIGHT', // [39]
  62. 'DOWN', // [40]
  63. 'SELECT', // [41]
  64. 'PRINT', // [42]
  65. 'EXECUTE', // [43]
  66. 'PRINTSCREEN', // [44]
  67. 'INSERT', // [45]
  68. 'DELETE', // [46]
  69. '', // [47]
  70. '0', // [48]
  71. '1', // [49]
  72. '2', // [50]
  73. '3', // [51]
  74. '4', // [52]
  75. '5', // [53]
  76. '6', // [54]
  77. '7', // [55]
  78. '8', // [56]
  79. '9', // [57]
  80. 'COLON', // [58]
  81. 'SEMICOLON', // [59]
  82. 'LESS_THAN', // [60]
  83. 'EQUALS', // [61]
  84. 'GREATER_THAN', // [62]
  85. 'QUESTION_MARK', // [63]
  86. 'AT', // [64]
  87. 'A', // [65]
  88. 'B', // [66]
  89. 'C', // [67]
  90. 'D', // [68]
  91. 'E', // [69]
  92. 'F', // [70]
  93. 'G', // [71]
  94. 'H', // [72]
  95. 'I', // [73]
  96. 'J', // [74]
  97. 'K', // [75]
  98. 'L', // [76]
  99. 'M', // [77]
  100. 'N', // [78]
  101. 'O', // [79]
  102. 'P', // [80]
  103. 'Q', // [81]
  104. 'R', // [82]
  105. 'S', // [83]
  106. 'T', // [84]
  107. 'U', // [85]
  108. 'V', // [86]
  109. 'W', // [87]
  110. 'X', // [88]
  111. 'Y', // [89]
  112. 'Z', // [90]
  113. 'OS_KEY', // [91] Windows Key (Windows) or Command Key (Mac)
  114. '', // [92]
  115. 'CONTEXT_MENU', // [93]
  116. '', // [94]
  117. 'SLEEP', // [95]
  118. 'NUMPAD0', // [96]
  119. 'NUMPAD1', // [97]
  120. 'NUMPAD2', // [98]
  121. 'NUMPAD3', // [99]
  122. 'NUMPAD4', // [100]
  123. 'NUMPAD5', // [101]
  124. 'NUMPAD6', // [102]
  125. 'NUMPAD7', // [103]
  126. 'NUMPAD8', // [104]
  127. 'NUMPAD9', // [105]
  128. 'MULTIPLY', // [106]
  129. 'ADD', // [107]
  130. 'SEPARATOR', // [108]
  131. 'SUBTRACT', // [109]
  132. 'DECIMAL', // [110]
  133. 'DIVIDE', // [111]
  134. 'F1', // [112]
  135. 'F2', // [113]
  136. 'F3', // [114]
  137. 'F4', // [115]
  138. 'F5', // [116]
  139. 'F6', // [117]
  140. 'F7', // [118]
  141. 'F8', // [119]
  142. 'F9', // [120]
  143. 'F10', // [121]
  144. 'F11', // [122]
  145. 'F12', // [123]
  146. 'F13', // [124]
  147. 'F14', // [125]
  148. 'F15', // [126]
  149. 'F16', // [127]
  150. 'F17', // [128]
  151. 'F18', // [129]
  152. 'F19', // [130]
  153. 'F20', // [131]
  154. 'F21', // [132]
  155. 'F22', // [133]
  156. 'F23', // [134]
  157. 'F24', // [135]
  158. '', // [136]
  159. '', // [137]
  160. '', // [138]
  161. '', // [139]
  162. '', // [140]
  163. '', // [141]
  164. '', // [142]
  165. '', // [143]
  166. 'NUM_LOCK', // [144]
  167. 'SCROLL_LOCK', // [145]
  168. 'WIN_OEM_FJ_JISHO', // [146]
  169. 'WIN_OEM_FJ_MASSHOU', // [147]
  170. 'WIN_OEM_FJ_TOUROKU', // [148]
  171. 'WIN_OEM_FJ_LOYA', // [149]
  172. 'WIN_OEM_FJ_ROYA', // [150]
  173. '', // [151]
  174. '', // [152]
  175. '', // [153]
  176. '', // [154]
  177. '', // [155]
  178. '', // [156]
  179. '', // [157]
  180. '', // [158]
  181. '', // [159]
  182. 'CIRCUMFLEX', // [160]
  183. 'EXCLAMATION', // [161]
  184. 'DOUBLE_QUOTE', // [162]
  185. 'HASH', // [163]
  186. 'DOLLAR', // [164]
  187. 'PERCENT', // [165]
  188. 'AMPERSAND', // [166]
  189. 'UNDERSCORE', // [167]
  190. 'OPEN_PAREN', // [168]
  191. 'CLOSE_PAREN', // [169]
  192. 'ASTERISK', // [170]
  193. 'PLUS', // [171]
  194. 'PIPE', // [172]
  195. 'HYPHEN_MINUS', // [173]
  196. 'OPEN_CURLY_BRACKET', // [174]
  197. 'CLOSE_CURLY_BRACKET', // [175]
  198. 'TILDE', // [176]
  199. '', // [177]
  200. '', // [178]
  201. '', // [179]
  202. '', // [180]
  203. 'VOLUME_MUTE', // [181]
  204. 'VOLUME_DOWN', // [182]
  205. 'VOLUME_UP', // [183]
  206. '', // [184]
  207. '', // [185]
  208. 'SEMICOLON', // [186]
  209. 'EQUALS', // [187]
  210. 'COMMA', // [188]
  211. 'MINUS', // [189]
  212. 'PERIOD', // [190]
  213. 'SLASH', // [191]
  214. 'BACK_QUOTE', // [192]
  215. '', // [193]
  216. '', // [194]
  217. '', // [195]
  218. '', // [196]
  219. '', // [197]
  220. '', // [198]
  221. '', // [199]
  222. '', // [200]
  223. '', // [201]
  224. '', // [202]
  225. '', // [203]
  226. '', // [204]
  227. '', // [205]
  228. '', // [206]
  229. '', // [207]
  230. '', // [208]
  231. '', // [209]
  232. '', // [210]
  233. '', // [211]
  234. '', // [212]
  235. '', // [213]
  236. '', // [214]
  237. '', // [215]
  238. '', // [216]
  239. '', // [217]
  240. '', // [218]
  241. 'OPEN_BRACKET', // [219]
  242. 'BACK_SLASH', // [220]
  243. 'CLOSE_BRACKET', // [221]
  244. 'QUOTE', // [222]
  245. '', // [223]
  246. 'META', // [224]
  247. 'ALTGR', // [225]
  248. '', // [226]
  249. 'WIN_ICO_HELP', // [227]
  250. 'WIN_ICO_00', // [228]
  251. '', // [229]
  252. 'WIN_ICO_CLEAR', // [230]
  253. '', // [231]
  254. '', // [232]
  255. 'WIN_OEM_RESET', // [233]
  256. 'WIN_OEM_JUMP', // [234]
  257. 'WIN_OEM_PA1', // [235]
  258. 'WIN_OEM_PA2', // [236]
  259. 'WIN_OEM_PA3', // [237]
  260. 'WIN_OEM_WSCTRL', // [238]
  261. 'WIN_OEM_CUSEL', // [239]
  262. 'WIN_OEM_ATTN', // [240]
  263. 'WIN_OEM_FINISH', // [241]
  264. 'WIN_OEM_COPY', // [242]
  265. 'WIN_OEM_AUTO', // [243]
  266. 'WIN_OEM_ENLW', // [244]
  267. 'WIN_OEM_BACKTAB', // [245]
  268. 'ATTN', // [246]
  269. 'CRSEL', // [247]
  270. 'EXSEL', // [248]
  271. 'EREOF', // [249]
  272. 'PLAY', // [250]
  273. 'ZOOM', // [251]
  274. '', // [252]
  275. 'PA1', // [253]
  276. 'WIN_OEM_CLEAR', // [254]
  277. '' // [255]
  278. ],
  279.  
  280. banned: [],
  281.  
  282. watermark: ' ',
  283.  
  284. // Don't remove the spaces, they are used as separators! Source: https://emojiterra.com/de/liste/
  285. emojis: '😀 😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😗 ☺️ 😚 😙 😋 😛 😜 😝 😐 😑 😶 😏 😒 😬 😌 😔 😪 😴 😷 😵 😎 😕 😟 😮 😯 😲 😳 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤 😡 😠 😈 👿 💀 💩 👹 👺 👻 👽 👾 😺 😸 😹 😻 😼 😽 🙀 😿 😾 🙈 🙉 🙊 💋 💌 💘 💝 💖 💗 💓 💞 💕 💟 💔 ❤️ 💛 💚 💙 💜 💯 💢 💥 💫 💦 💨 💣 💬 💭 💤 👋 ✋ 👌 ✌️ 👈 👉 👆 👇 ☝️ 👍 👎 ✊ 👊 👏 🙌 👐 🙏 💅 💪 👂 👃 👀 👅 👄 👶 👦 👧 👱 👨 👩 👴 👵 🙍 🙎 🙅 🙆 💁 🙋 🙇 👮 💂 👷 👸 👳 👲 👰 👼 🎅 💆 💇 🚶 🏃 💃 👯 🏇 🏂 🏄 🚣 🏊 🚴 🚵 🛀 👭 👫 👬 💏 💑 👪 👤 👥 👣 🐵 🐒 🐶 🐕 🐩 🐺 🐱 🐈 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇 🐻 🐨 🐼 🐾 🐔 🐓 🐣 🐤 🐥 🐦 🐧 🐸 🐊 🐢 🐍 🐲 🐉 🐳 🐋 🐬 🐟 🐠 🐡 🐙 🐚 🐌 🐛 🐜 🐝 🐞 💐 🌸 💮 🌹 🌺 🌻 🌼 🌷 🌱 🌲 🌳 🌴 🌵 🌾 🌿 🍀 🍁 🍂 🍃 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍅 🍆 🌽 🍄 🌰 🍞 🍖 🍗 🍔 🍟 🍕 🍳 🍲 🍱 🍘 🍙 🍚 🍛 🍜 🍝 🍠 🍢 🍣 🍤 🍥 🍡 🍦 🍧 🍨 🍩 🍪 🎂 🍰 🍫 🍬 🍭 🍮 🍯 🍼 ☕ 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍴 🔪 🌍 🌎 🌏 🌐 🗾 🌋 🗻 🏠 🏡 🏢 🏣 🏤 🏥 🏦 🏨 🏩 🏪 🏫 🏬 🏭 🏯 🏰 💒 🗼 🗽 ⛪ ⛲ ⛺ 🌁 🌃 🌄 🌅 🌆 🌇 🌉 ♨️ 🎠 🎡 🎢 💈 🎪 🚂 🚃 🚄 🚅 🚆 🚇 🚈 🚉 🚊 🚝 🚞 🚋 🚌 🚍 🚎 🚐 🚑 🚒 🚓 🚔 🚕 🚖 🚗 🚘 🚙 🚚 🚛 🚜 🚲 🚏 ⛽ 🚨 🚥 🚦 🚧 ⚓ ⛵ 🚤 🚢 ✈️ 💺 🚁 🚟 🚠 🚡 🚀 ⌛ ⏳ ⌚ ⏰ 🕛 🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 ☀️ 🌝 🌞 ⭐ 🌟 🌠 🌌 ☁️ ⛅ 🌀 🌈 🌂 ☔ ⚡ ❄️ ⛄ 🔥 💧 🌊 🎃 🎄 🎆 🎇 ✨ 🎈 🎉 🎊 🎋 🎍 🎎 🎏 🎐 🎑 🎀 🎁 🎫 🏆 ⚽ ⚾ 🏀 🏈 🏉 🎾 🎳 ⛳ 🎣 🎽 🎿 🎯 🎱 🔮 🎮 🎰 🎲 ♠️ ♥️ ♦️ ♣️ 🃏 🀄 🎴 🎭 🎨 👓 👔 👕 👖 👗 👘 👙 👚 👛 👜 👝 🎒 👞 👟 👠 👡 👢 👑 👒 🎩 🎓 💄 💍 💎 🔇 🔈 🔉 🔊 📢 📣 📯 🔔 🔕 🎼 🎵 🎶 🎤 🎧 📻 🎷 🎸 🎹 🎺 🎻 📱 📲 ☎️ 📞 📟 📠 🔋 🔌 💻 💽 💾 💿 📀 🎥 🎬 📺 📷 📹 📼 🔍 🔎 💡 🔦 🏮 📔 📕 📖 📗 📘 📙 📚 📓 📒 📃 📜 📄 📰 📑 🔖 💰 💴 💵 💶 💷 💸 💳 💹 💱 💲 ✉️ 📧 📨 📩 📤 📥 📦 📫 📪 📬 📭 📮 ✏️ ✒️ 📝 💼 📁 📂 📅 📆 📇 📈 📉 📊 📋 📌 📍 📎 📏 📐 ✂️ 🔒 🔓 🔏 🔐 🔑 🔨 🔫 🔧 🔩 🔗 🔬 🔭 📡 💉 💊 🚪 🚽 🚿 🛁 🚬 🗿 🏧 🚮 🚰 ♿ 🚹 🚺 🚻 🚼 🚾 🛂 🛃 🛄 🛅 ⚠️ 🚸 ⛔ 🚫 🚳 🚭 🚯 🚱 🚷 📵 🔞 ⬆️ ↗️ ➡️ ↘️ ⬇️ ↙️ ⬅️ ↖️ ↕️ ↔️ 🔃 🔄 🔙 🔚 🔛 🔜 🔝 🔯 ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ⛎ 🔀 🔁 🔂 ▶️ ◀️ 🔼 🔽 🎦 📶 📳 📴 ♻️ 🔱 📛 🔰 ⭕ ✅ ☑️ ✖️ ❌ ❎ ➕ ➖ ➗ ➰ ➿ 〽️ ✳️ ✴️ ❇️ ‼️ ⁉️ ❓ ❔ ❕ ❗ 〰️ ©️ ®️ ™️ 🔠 🔡 🔢 🔣 🔤 🅰️ 🆎 🅱️ 🆑 🆒 🆓 🆔 Ⓜ️ 🆕 🆖 🅾️ 🆗 🅿️ 🆘 🆙 🆚 🈁 🈂️ 🈷️ 🈶 🈯 🉐 🈹 🈚 🈲 🉑 🈸 🈴 🈳 ㊗️ ㊙️ 🈺 🈵 🔴 🔵 ⚫ ⚪ ⬛ ⬜ ◼️ ◻️ ◾ ◽ ▪️ ▫️ 🔶 🔷 🔸 🔹 🔺 🔻 💠 🔘 🔳 🔲 🏁 🚩 🎌',
  286.  
  287. settings: null,
  288.  
  289. hotkeys: null,
  290.  
  291. init: function() {
  292. this.setupPolyfills();
  293.  
  294. this.hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  295.  
  296. this.auth();
  297.  
  298. this.config();
  299.  
  300. this.moveRespawnBtn();
  301. this.players();
  302. this.animation();
  303. this.chatLog();
  304. this.dance();
  305. this.favSkins();
  306. this.paste();
  307. this.replacements();
  308. this.fpsPing();
  309. this.timer();
  310. this.alive();
  311. this.skinChanger();
  312. this.skinApplier();
  313. this.ultraSplit();
  314. this.lineSplit();
  315. this.waste();
  316. this.guessing();
  317. this.nameColor();
  318. this.wearablesToggle();
  319. this.keyboardLayout();
  320. this.help();
  321. this.commands();
  322.  
  323. console.log('🌸 Miracle Scripts successfully loaded!');
  324. },
  325.  
  326. config: function() {
  327. var self = this;
  328. var settings = null;
  329.  
  330. var loadSettings = function (stringifiedSettings) {
  331. var defaultSettings = {
  332. // To get keycodes: https://keycode.info
  333. bindings: {
  334. ultraSplit: 85, // U
  335. wearables: 36, // POS1
  336. animation: 17, // CTRL
  337. paste: 33, // PAGE UP
  338. dance: 34, // PAGE DOWN,
  339. chatLog: 76, // L
  340. skin1: 49, // 1
  341. skin2: 50, // 2
  342. skin3: 51, // 3
  343. skin4: 52, // 4
  344. skin5: 53, // 5
  345. skin6: 54, // 6
  346. skin7: 55, // 7
  347. skin8: 56, // 8
  348. skin9: 57, // 9
  349. },
  350. replacements: ":D|:smile:\n:*(|:sob:\n:'D|:sweat_smile:\nxD|:joy:",
  351. primaryColor: '#f9138b',
  352. targetLanguage: 'en',
  353. favSkins: [],
  354. quickSkins: [],
  355. players: [],
  356. showClock: true,
  357. changeKeyboardLayout: false,
  358. };
  359.  
  360. if (stringifiedSettings == null || stringifiedSettings == undefined || stringifiedSettings === '') {
  361. settings = defaultSettings;
  362. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  363. } else {
  364. settings = JSON.parse(stringifiedSettings);
  365. if (settings === null || Object.getOwnPropertyNames(settings).length == 0) {
  366. settings = defaultSettings;
  367. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  368. }
  369.  
  370. // Update for settings:
  371. if (typeof settings.primaryColor === 'undefined') {
  372. settings.primaryColor = defaultSettings.primaryColor;
  373. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  374. }
  375. if (typeof settings.bindings.chatLog === 'undefined') {
  376. settings.bindings.chatLog = defaultSettings.bindings.chatLog;
  377. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  378. }
  379. if (typeof settings.favSkins === 'undefined') {
  380. settings.favSkins = defaultSettings.favSkins;
  381. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  382. }
  383. if (typeof settings.targetLanguage === 'undefined') {
  384. settings.targetLanguage = defaultSettings.targetLanguage;
  385. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  386. }
  387. if (typeof settings.quickSkins === 'undefined') {
  388. settings.quickSkins = [];
  389. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  390. }
  391. if (typeof settings.installedVersion === 'undefined') {
  392. settings.installedVersion = 1;
  393. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  394. }
  395. if (typeof settings.players === 'undefined') {
  396. settings.players = [];
  397. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  398. }
  399. if (typeof settings.bindings.skin1 === 'undefined') {
  400. settings.bindings.skin1 = defaultSettings.bindings.skin1;
  401. settings.bindings.skin2 = defaultSettings.bindings.skin2;
  402. settings.bindings.skin3 = defaultSettings.bindings.skin3;
  403. settings.bindings.skin4 = defaultSettings.bindings.skin4;
  404. settings.bindings.skin5 = defaultSettings.bindings.skin6;
  405. settings.bindings.skin6 = defaultSettings.bindings.skin6;
  406. settings.bindings.skin7 = defaultSettings.bindings.skin7;
  407. settings.bindings.skin8 = defaultSettings.bindings.skin8;
  408. settings.bindings.skin9 = defaultSettings.bindings.skin9;
  409. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  410. }
  411. if (typeof settings.showClock === 'undefined') {
  412. settings.showClock = false;
  413. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  414. }
  415. if (typeof settings.showKeyboardLayout === 'undefined') {
  416. settings.showKeyboardLayout = false;
  417. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  418. }
  419. if (typeof settings.bindings.ultraSplit === 'undefined') {
  420. settings.bindings.ultraSplit = 85;
  421. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  422. }
  423. if (typeof settings.bindings.wearables === 'undefined') {
  424. settings.bindings.wearables = 36;
  425. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  426. }
  427.  
  428. }
  429.  
  430. self.settings = settings;
  431. };
  432. loadSettings(localStorage.getItem('miracleScripts'));
  433.  
  434. if (settings.installedVersion < this.getVersionAsInt()) {
  435. if (settings.installedVersion > 1) { // We do not want to inform new scripts user of past updates
  436. if (settings.installedVersion < this.getVersionAsInt('2.4.3')) {
  437. window.alert('📢 Miracle Scripts Update: \n\n' +
  438. 'As of version 2.4.3 the nickname color change feature has been removed ' +
  439. 'according to an official decision of the Agma team.\n\n' +
  440. 'To avoid trouble for its users Miracle Scripts respects this decision. ' +
  441. 'Therefore Miracle Scripts is a legit extension for Agma and using it is safe.'
  442. );
  443. }
  444. if (settings.installedVersion < this.getVersionAsInt('2.5.6')) {
  445. self.swal(
  446. 'Miracle Scripts Update',
  447. 'You may now use 20 slots for skins (previously: 15). Type <i>/skin16</i> - <i>/skin20</i> in the chat box!');
  448. }
  449. if (settings.installedVersion < this.getVersionAsInt('2.5.8')) {
  450. self.swal(
  451. 'Miracle Scripts Update',
  452. 'New: You may now assign aliases and notes to players. The alias will be displayed in the friends list. To add an alias right click on a player\'s name in the chat or a cell and then click on "Show profile".');
  453. }
  454. if (settings.installedVersion < this.getVersionAsInt('2.6.0')) {
  455. self.swal(
  456. 'Miracle Scripts Update',
  457. 'New: You may now bind keys to skin slots. Per default the keys 1 - 9 are bound to <i>/skin1</i> - <i>/skin9</i>.');
  458. }
  459. if (settings.installedVersion < this.getVersionAsInt('2.6.1')) {
  460. self.swal(
  461. 'Miracle Scripts Update',
  462. 'New: Right click on a cell. Then click on <i>Use Player\'s Wearables</i> to use the same wearables as that player. (Of course you have to own the wearables.)');
  463. }
  464. if (settings.installedVersion < this.getVersionAsInt('2.6.4')) {
  465. self.swal(
  466. 'Miracle Scripts Update',
  467. 'New: Want to see how late it is? Activate the clock in the settings!');
  468. }
  469. if (settings.installedVersion < this.getVersionAsInt('3.0.0')) {
  470. self.swal(
  471. 'Miracle Scripts Update',
  472. '<b>ATTENTION!</b> This script won\'t get any new features! The Agma staff keeps making new restrictions to this script, so there is no point to continue development. With this update, the <i>/say</i> command has been removed, as the Agma staff enforced this.');
  473. }
  474. if (settings.installedVersion < this.getVersionAsInt('3.1.3')) {
  475. self.swal(
  476. 'Miracle Scripts Update',
  477. 'Just a friendly hint: Agma has a new powerup! It\'s called "Tactical Nuke" and can be found in the shop. Attention: It\'s the first of April 😜');
  478. }
  479. if (settings.installedVersion < this.getVersionAsInt('3.1.6')) {
  480. self.swal(
  481. 'Miracle Scripts Update',
  482. 'New: Type <span style="font-style: italic">/players</span> in the chat to see how many players are online in Agma!');
  483. }
  484. if (settings.installedVersion < this.getVersionAsInt('3.3.0')) {
  485. self.swal(
  486. 'Miracle Scripts Update',
  487. 'New: You may now see your keyboard layout as an overlay! Go to the settings to activate it.');
  488. }
  489. if (settings.installedVersion < this.getVersionAsInt('3.4.0')) {
  490. self.swal(
  491. 'Miracle Scripts Update',
  492. 'New: ULTRA split! Press U to make an ultra split, which can split 1 cell to 64!! (The server has to support that!)');
  493. }
  494. if (settings.installedVersion < this.getVersionAsInt('3.6.0')) {
  495. self.swal(
  496. 'Miracle Scripts Update',
  497. 'New: Toggle "wearables on/off" with a key! Default is POS1!');
  498. }
  499. if (settings.installedVersion < this.getVersionAsInt('4.0.0')) {
  500. self.swal(
  501. 'Miracle Scripts Update',
  502. 'New: Type /guess to start a little guessing game in the chat!<br><br>💡 Note that it only works with browsers that can display emojis.');
  503. }
  504. }
  505.  
  506. settings.installedVersion = this.getVersionAsInt();
  507. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  508. self.settings = settings;
  509. }
  510.  
  511. var defaultNews = 'Agma Updates 01 May 2020';
  512. var $newsElement = $('#cnt_panel .navbar p.text-center');
  513. if ($newsElement.text().trim() === defaultNews) {
  514. $newsElement.css('margin-bottom', '20px');
  515. $newsElement.css('padding', '10px');
  516. $newsElement.css('background-color', 'rgba(0, 0, 0, 0.5)');
  517. $newsElement.html(self.news);
  518.  
  519. var $metaElement = $('<div title="Powered by Miracle Script">AGMA News</div>');
  520. $newsElement.parent().prepend($metaElement);
  521. $metaElement.css('background-color', '#B5B9C0');
  522. $metaElement.css('color', 'black');
  523. }
  524.  
  525. var applyPrimaryColor = function () {
  526. var primaryColorCss = '.miracle-primary-color-font { color: ' + self.settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + self.settings.primaryColor + ' !important }; ';
  527. $('body').append('<style>' + primaryColorCss + '</style>');
  528. };
  529. applyPrimaryColor();
  530.  
  531. // We need to have a delay, because the menu is not loaded right away
  532. setTimeout(function () {
  533. var $playButton = $('#playBtn');
  534. var $specateButton = $('#spectateBtn');
  535.  
  536. $playButton.get(0).style.width = '40%';
  537. $specateButton.get(0).style.width = '40%';
  538.  
  539. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">📜</button>');
  540. $settingsButton.insertAfter($playButton);
  541.  
  542. var changeKey = function (event) {
  543. var name = this.name.substr(4);
  544. $(this).val(self.keyboardMap[event.keyCode]);
  545. self.settings.bindings[name] = event.keyCode;
  546. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  547. };
  548.  
  549. var deleteKey = function () {
  550. var action = $(this).attr('data-action');
  551. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  552. self.settings.bindings[action] = null;
  553. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  554. };
  555.  
  556. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  557. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  558. // focus again (delayed) and go to the end of the text where the linebreak is.
  559. // We can improve this later on...
  560. var addReturn = function (event) {
  561. if (event.keyCode === 13) {
  562. var textarea = this;
  563. $(textarea).text($(this).text() + '\n').focus();
  564. setTimeout(function () {
  565. $(textarea).focus();
  566. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  567. }, 1);
  568. }
  569. };
  570. var changeReplacements = function () {
  571. self.settings.replacements = $(this).val();
  572. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  573. };
  574. var changePrimaryColor = function () {
  575. self.settings.primaryColor = $(this).val();
  576. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  577. applyPrimaryColor();
  578. };
  579. var changeTargetLanguage = function () {
  580. self.settings.targetLanguage = $(this).val();
  581. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  582. };
  583. var changeClock = function() {
  584. self.settings.showClock = $(this).is(':checked');
  585. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  586. };
  587. var changeKeyboardLayout = function() {
  588. self.settings.showKeyboardLayout = $(this).is(':checked');
  589. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  590. };
  591.  
  592. var $modal = $('<div id="miracle-settings" class="miracle-primary-color-font" style="position: fixed; width: 100%; height: 100%; overflow-y: auto; padding: 50px; background-color: rgba(0,0,0,0.95); z-index: 999; display: none"></div>');
  593. $modal.append('<h1>Miracle Scripts Settings</h1>');
  594.  
  595. if (GM_info) {
  596. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  597. }
  598.  
  599. var $firstRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  600. var $secRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  601. var $thirdRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  602.  
  603.  
  604. var $element = $('<input name="key_ultraSplit" value="' + self.keyboardMap[self.settings.bindings.ultraSplit] + '"/>').keyup(changeKey);
  605. $firstRow.append('<br><br>Ultra-Split-Key:<br>', $element);
  606. $element = $('<a href="#" data-action="ultraSplit" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  607. $firstRow.append($element);
  608.  
  609. $element = $('<input name="key_animation" value="' + self.keyboardMap[self.settings.bindings.animation] + '"/>').keyup(changeKey);
  610. $firstRow.append('<br><br>Animation-Key:<br>', $element);
  611. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  612. $firstRow.append($element);
  613.  
  614. $element = $('<input name="key_paste" value="' + self.keyboardMap[self.settings.bindings.paste] + '"/>').keyup(changeKey);
  615. $firstRow.append('<br><br>Paste-Key:<br>', $element);
  616. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  617. $firstRow.append($element);
  618.  
  619. $element = $('<input name="key_dance" value="' + self.keyboardMap[self.settings.bindings.dance] + '"/>').keyup(changeKey);
  620. $firstRow.append('<br><br>Dance-Key:<br>', $element);
  621. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  622. $firstRow.append($element);
  623.  
  624. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[self.settings.bindings.chatLog] + '"/>').keyup(changeKey);
  625. $firstRow.append('<br><br>Chat-Log-Key:<br>', $element);
  626. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  627. $firstRow.append($element);
  628.  
  629.  
  630. $element = $('<input name="key_skin1" value="' + self.keyboardMap[self.settings.bindings.skin1] + '"/>').keyup(changeKey);
  631. $secRow.append('<br><br>Use-First-Skin-Key:<br>', $element);
  632. $element = $('<a href="#" data-action="skin1" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  633. $secRow.append($element);
  634.  
  635. $element = $('<input name="key_skin2" value="' + self.keyboardMap[self.settings.bindings.skin2] + '"/>').keyup(changeKey);
  636. $secRow.append('<br><br>Use-Second-Skin-Key:<br>', $element);
  637. $element = $('<a href="#" data-action="skin2" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  638. $secRow.append($element);
  639.  
  640. $element = $('<input name="key_skin3" value="' + self.keyboardMap[self.settings.bindings.skin3] + '"/>').keyup(changeKey);
  641. $secRow.append('<br><br>Use-Third-Skin-Key:<br>', $element);
  642. $element = $('<a href="#" data-action="skin3" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  643. $secRow.append($element);
  644.  
  645. $element = $('<input name="key_skin4" value="' + self.keyboardMap[self.settings.bindings.skin4] + '"/>').keyup(changeKey);
  646. $secRow.append('<br><br>Use-Fourth-Skin-Key:<br>', $element);
  647. $element = $('<a href="#" data-action="skin4" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  648. $secRow.append($element);
  649.  
  650. $element = $('<input name="key_skin5" value="' + self.keyboardMap[self.settings.bindings.skin5] + '"/>').keyup(changeKey);
  651. $secRow.append('<br><br>Use-Fifth-Skin-Key:<br>', $element);
  652. $element = $('<a href="#" data-action="skin5" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  653. $secRow.append($element);
  654.  
  655.  
  656. $element = $('<input name="key_skin6" value="' + self.keyboardMap[self.settings.bindings.skin6] + '"/>').keyup(changeKey);
  657. $thirdRow.append('<br><br>Use-Sixth-Skin-Key:<br>', $element);
  658. $element = $('<a href="#" data-action="skin6" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  659. $thirdRow.append($element);
  660.  
  661. $element = $('<input name="key_skin7" value="' + self.keyboardMap[self.settings.bindings.skin7] + '"/>').keyup(changeKey);
  662. $thirdRow.append('<br><br>Use-Seventh-Skin-Key:<br>', $element);
  663. $element = $('<a href="#" data-action="skin7" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  664. $thirdRow.append($element);
  665.  
  666. $element = $('<input name="key_skin8" value="' + self.keyboardMap[self.settings.bindings.skin8] + '"/>').keyup(changeKey);
  667. $thirdRow.append('<br><br>Use-Eighth-Skin-Key:<br>', $element);
  668. $element = $('<a href="#" data-action="skin8" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  669. $thirdRow.append($element);
  670.  
  671. $element = $('<input name="key_skin9" value="' + self.keyboardMap[self.settings.bindings.skin9] + '"/>').keyup(changeKey);
  672. $thirdRow.append('<br><br>Use-Ninth-Skin-Key:<br>', $element);
  673. $element = $('<a href="#" data-action="skin9" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  674. $thirdRow.append($element);
  675.  
  676. $element = $('<input name="key_wearables" value="' + self.keyboardMap[self.settings.bindings.wearables] + '"/>').keyup(changeKey);
  677. $thirdRow.append('<br><br>Toggle-Wearables-Key:<br>', $element);
  678. $element = $('<a href="#" data-action="wearables" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  679. $thirdRow.append($element);
  680.  
  681.  
  682.  
  683. var $table = $('<table>').append($('<tbody>').append($('<tr>').append($firstRow).append($secRow).append($thirdRow)));
  684. $modal.append($table)
  685.  
  686. $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><option value="ja">Japanese</option><option value="zh">Chinese</option></select>').change(changeTargetLanguage);
  687. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  688. $element.get(0).value = self.settings.targetLanguage;
  689.  
  690. $element = $('<input type="color" name="favcolor" value="' + self.settings.primaryColor + '"/>').change(changePrimaryColor);
  691. $modal.append('<br><br>User interface color:<br>', $element);
  692.  
  693. $element = $('<input type="checkbox" name="checkBox" value="1" ' + (self.settings.showClock ? 'checked' : '') + '/>').change(changeClock);
  694. $modal.append('<br><br>Show clock:<br>', $element);
  695.  
  696. $element = $('<input type="checkbox" name="checkBox" value="1" ' + (self.settings.showKeyboardLayout ? 'checked' : '') + '/>').change(changeKeyboardLayout);
  697. $modal.append('<br><br>Show Keyboard Layout (reload website to update):<br>', $element);
  698.  
  699. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(self.settings.replacements).keydown(addReturn).keyup(changeReplacements);
  700. $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>');
  701.  
  702. $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 () {
  703. $modal.hide();
  704. }));
  705. $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 () {
  706. self.download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  707. }));
  708. $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 () {
  709. var stringifiedSettings = window.prompt('Paste the settings here');
  710. if (stringifiedSettings !== null) {
  711. loadSettings(stringifiedSettings);
  712. localStorage.setItem('miracleScripts', stringifiedSettings);
  713. $modal.hide();
  714. self.message('Settings loaded! Reload Agma to refresh. 😄');
  715. }
  716. }));
  717. //$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>'));
  718. $modal.append($('<a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-left: 20px; margin-top: 20px; padding: 10px; color: white">Help</a>').click(function () {
  719. $modal.hide();
  720. self.$helpModal.show();
  721. }));
  722.  
  723. $('body').append($modal);
  724.  
  725. $settingsButton.click(function (event) {
  726. $modal.show();
  727.  
  728. event.preventDefault();
  729. });
  730.  
  731. window.addEventListener('miracleCommand', function(commandEvent) {
  732. if (commandEvent.command === '/miraclesettings' || commandEvent.command === '/miracleconfig') {
  733. $modal.show();
  734. $('#chtbox').val('');
  735. }
  736. });
  737. }, 500);
  738. },
  739.  
  740. moveRespawnBtn: function() {
  741. $('#advBox > div:last-child').css('position', 'absolute');
  742. $('#advBox > div:last-child').css('left', '48%');
  743. $('#advBox > div:last-child').css('marginTop', '5px');
  744. $('#advBox > div:nth-child(2)').css('marginLeft', '10%');
  745. },
  746.  
  747. players: function() {
  748. var self = this;
  749.  
  750. $('body').append('<style>#friendList .name { text-decoration: underline; cursor: pointer; }</style>');
  751.  
  752. $('#phpFriendlist').click(function(event) {
  753. if (event.target.classList.contains('name')) { // TODO check: what happens if player is online?
  754. insertPMText($(event.target).text());
  755. }
  756. });
  757.  
  758. $('#btnFriends').click(function() {
  759. var updater = function() {
  760. if ($('#friendDialogMessage').length > 0) {
  761. window.setTimeout(updater, 200);
  762. return;
  763. }
  764.  
  765. $('#phpFriendlist span.name, #requestList span.name').each(function() {
  766. var $nameElement = $(this);
  767. var name = $nameElement.text();
  768. self.settings.players.forEach(function(player) {
  769. if (player.name === name && player.alias) {
  770. $nameElement.attr('title', 'Accountname: ' + name);
  771. $nameElement.css('fontStyle', 'italic');
  772. $nameElement.text(player.alias);
  773. }
  774. });
  775. });
  776. };
  777. window.setTimeout(updater, 200);
  778. });
  779.  
  780. $('#contextUserProfile').click(function() {
  781. $('#miracle-player-settings').remove();
  782.  
  783. window.setTimeout(function() {
  784. if ($('.sweet-alert .sa-error').css('display') === 'block') {
  785. return; // No (public) profile available
  786. }
  787.  
  788. var player = null;
  789. var accountName = $('.sweet-alert h2 span:first()').text();
  790.  
  791. self.settings.players.some(function(candidate) {
  792. if (candidate.name === accountName) {
  793. player = candidate;
  794. return true;
  795. }
  796. });
  797.  
  798. var $editArea = $('<div id="miracle-player-settings">');
  799. var $aliasField = $('<input type="text" maxlength="30" placeholder="Alias" title="Alias" style="display: block; color: #333">').blur(function() {
  800. var alias = $(this).val();
  801. if (player) {
  802. player.alias = alias;
  803. } else {
  804. player = {name: accountName, alias: alias};
  805. self.settings.players.push(player);
  806. }
  807. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  808. });
  809. if (player) {
  810. $aliasField.val(player.alias);
  811. }
  812. $editArea.append($aliasField);
  813. var $noteField = $('<textarea maxlength="250" placeholder="Notes" title="Notes" rows="4" style="width: 100%; padding: 10px; color: #333"></textarea>').blur(function() {
  814. var note = $(this).val();
  815. if (player) {
  816. player.note = note;
  817. } else {
  818. player = {name: accountName, note: note};
  819. self.settings.players.push(player);
  820. }
  821. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  822. });
  823. if (player) {
  824. $noteField.val(player.note);
  825. }
  826. $editArea.append($noteField);
  827.  
  828. $editArea.insertBefore('.sweet-alert .sa-button-container');
  829.  
  830. if ($('.sweet-overlay').attr('data-listening') != 1) {
  831. $('.sweet-overlay').attr('data-listening', 1);
  832.  
  833. $('.sweet-overlay').click(function() {
  834. console.log('sweet bg clicked');
  835. $('#miracle-player-settings').remove();
  836. });
  837. $('.sweet-alert .sa-button-container button').click(function() {
  838. console.log('sweet btn clicked');
  839. $('#miracle-player-settings').remove();
  840. });
  841. }
  842. }, 300);
  843. });
  844. },
  845.  
  846. auth: function() {
  847. var self = this;
  848.  
  849. var value = localStorage.getItem('330145eb94127d7d99dd28af3ee8599d');
  850.  
  851. if (value) {
  852. throw 'Exception: Authentication failed. Code: 1000001';
  853. }
  854.  
  855. var check = function () {
  856. var accountName = self.getAccountName();
  857. if (self.banned.indexOf(accountName) > -1) {
  858. console.log('Exception: Authentication failed. Code: 1000001');
  859. localStorage.setItem('330145eb94127d7d99dd28af3ee8599d', '90f62eda082944015b3c794c65b7c0f0');
  860. window.location.reload();
  861. return;
  862. };
  863. }
  864.  
  865. setInterval(check, 10000);
  866. },
  867.  
  868. animation: function () {
  869. var self = this;
  870.  
  871. var chatAnimate = function () {
  872. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  873. $('#chtbox').val('');
  874. }
  875.  
  876. // All available commands and combinations
  877. var items = ['wacky',
  878. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin',
  879. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip',
  880. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake',
  881. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump',
  882. ];
  883.  
  884. // Super-combinations!!
  885. if (self.getRandomInt(1, 3) === 1) {
  886. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  887. }
  888.  
  889. // Choose randomly an item of the items array
  890. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  891. var item = items[Math.floor(Math.random() * items.length)];
  892.  
  893. // Attempt to avoid triggering spam protection - probably useless :-/
  894. item += String.fromCharCode(8203).repeat(self.getRandomInt(1, 5));
  895.  
  896. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  897. $('#chtbox').val($('#chtbox').val() + item).focus();
  898.  
  899. // Stop the event so that the pressed key won't be written into the chat box!
  900. event.preventDefault();
  901. };
  902.  
  903. window.addEventListener('keydown', function (event) {
  904. // Do nothing if a menu is open
  905. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  906. return;
  907. }
  908.  
  909. if (event.keyCode == self.settings.bindings.animation) {
  910. chatAnimate();
  911. }
  912. });
  913. },
  914.  
  915. paste: function () {
  916. var self = this;
  917. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  918. 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' +
  919. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  920.  
  921. var emojis = this.emojis.split(' ');
  922. var emojiCode = '';
  923.  
  924. emojis.forEach(function (emoji) {
  925. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  926. });
  927.  
  928. var addEmoji = function () {
  929. setTimeout(function () {
  930. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  931.  
  932. // Add text into the chatbox and focus it
  933. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  934. }, 200);
  935.  
  936. $modal.hide();
  937. };
  938.  
  939. 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>');
  940. $modal.append('<style>' + css + '</style>');
  941. $modal.append('<h1>Insert text or emoji</h1>');
  942. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  943. $modal.append('<br><br>Insert:<br>', $pasteInput);
  944. $modal.html($modal.html() + '<br><br>' + emojiCode);
  945. $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));
  946. $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 () {
  947. $modal.hide();
  948. }));
  949.  
  950. $modal.find('input[name=paste]').click(function () {
  951. var text = window.prompt('Please paste your text here!');
  952.  
  953. if (text !== null) {
  954. var $pasteInput = $modal.find('input[name=paste]');
  955.  
  956. // Add text into the paste input
  957. $pasteInput.val($pasteInput.val() + text);
  958. }
  959. });
  960.  
  961. $modal.click(function (event) {
  962. if (event.target.classList.contains('miracle-emoji')) {
  963. var $target = $(this).find('input[name=paste]');
  964. $target.val($target.val() + $(event.target).text());
  965.  
  966. event.preventDefault();
  967. }
  968. });
  969.  
  970. $modal.dblclick(function (event) {
  971. if (event.target.classList.contains('miracle-emoji')) {
  972. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  973. $(this).hide();
  974.  
  975. event.preventDefault();
  976. }
  977. });
  978.  
  979. $('body').append($modal);
  980.  
  981. window.addEventListener('keydown', function (event) {
  982. // Do nothing if a menu is open
  983. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  984. return;
  985. }
  986.  
  987. if (event.keyCode == self.settings.bindings.paste) {
  988. $modal.find('input[name=paste]').val('');
  989. $modal.toggle();
  990. }
  991. });
  992.  
  993. window.addEventListener('miracleCommand', function(commandEvent) {
  994. if (commandEvent.command === '/paste') {
  995. $modal.find('input[name=paste]').val('');
  996. $modal.toggle();
  997. $('#chtbox').val('');
  998. }
  999. });
  1000. },
  1001.  
  1002. replacements: function () {
  1003. var self = this;
  1004.  
  1005. $('#chtbox').keyup(function () {
  1006. var lines = self.settings.replacements.split('\n');
  1007.  
  1008. var text = $('#chtbox').val();
  1009.  
  1010. lines.forEach(function (line) {
  1011. var replacement = line.split('|');
  1012. if (replacement.length === 2) {
  1013. text = text.replace(replacement[0], replacement[1]);
  1014. $('#chtbox').val(text).focus();
  1015. }
  1016. });
  1017. });
  1018. },
  1019.  
  1020. chatLog: function () {
  1021. var self = this;
  1022.  
  1023. // We escape the message before we print them, so no one can inject JS code!
  1024. var htmlEntities = function (str) {
  1025. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  1026. };
  1027.  
  1028. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  1029. var lastChatNickname = null;
  1030. var lastChatNicknameColor = null;
  1031. var chatLogCode = '';
  1032. var chatLog = [];
  1033. CanvasRenderingContext2D.prototype.fillText = function () {
  1034. if (this.canvas.id !== 'leaderboard' && this.canvas.height === 23) {
  1035. var text = arguments[0];
  1036. var xPos = arguments[1]; // Usually 3 for nicknames but bigger when a crown, donator icon etc. are displayed
  1037. var lineSize = this.canvas.width; // ATTENTION: Not sure if that really is the total size (icons + nickname + message)
  1038.  
  1039. // Sometimes also numbers (int) are printed (probably masses on cells) so we filter for strings
  1040. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  1041. // Dirty fix for the missing icon in the initial welcome messages
  1042. if (text == '') {
  1043. text = '📢';
  1044. }
  1045. lastChatNickname = text;
  1046. lastChatNicknameColor = this.fillStyle;
  1047. }
  1048. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  1049. // Unfortunately chat messages will be printed more than just once and I don't know
  1050. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  1051. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  1052. var found = false;
  1053. for (var i = 0; i < chatLog.length; i++) {
  1054. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  1055. found = true;
  1056. break;
  1057. }
  1058. }
  1059.  
  1060. if (!found) {
  1061. var legit = text.indexOf(self.watermark) > -1 ? 'class="legit" title="🛡️ This seems to be a legit Miracle Scripts message"' : '';
  1062. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  1063. chatLogCode += '<div ' + legit + '><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  1064. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  1065. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  1066.  
  1067. var messageEvent = new Event('miracleChatMessage');
  1068. messageEvent.nickname = lastChatNickname;
  1069. messageEvent.nicknameColor = lastChatNicknameColor;
  1070. messageEvent.message = text;
  1071. window.dispatchEvent(messageEvent);
  1072. }
  1073. }
  1074. }
  1075.  
  1076. return originalFillText.apply(this, arguments);
  1077. };
  1078.  
  1079. var performSearch = function (searchElement) {
  1080. var subject = searchElement.value.toLowerCase();
  1081.  
  1082. $('#miracle-complete-chatlog div').each(function () {
  1083. var $entry = $(this);
  1084.  
  1085. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  1086. $entry.hide();
  1087. } else {
  1088. $entry.show();
  1089. }
  1090. });
  1091. };
  1092.  
  1093. 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>');
  1094. $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; } #miracle-complete-chatlog div.legit { font-style: italic }</style>');
  1095. $modal.append('<h1>Complete Chat Log</h1><br>');
  1096. $modal.append('<div id="miracle-complete-chatlog"></div>');
  1097. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  1098. performSearch(this);
  1099. }));
  1100. $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 () {
  1101. $modal.hide();
  1102. }));
  1103. $('body').append($modal);
  1104.  
  1105. $('#miracle-complete-chatlog').dblclick(function (event) {
  1106. var $clickTarget;
  1107.  
  1108. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  1109. if (event.target.tagName.toLowerCase() === 'span') {
  1110. $clickTarget = $(event.target).parent();
  1111. } else {
  1112. $clickTarget = $(event.target);
  1113. }
  1114.  
  1115. var message = $clickTarget.find('.message').text();
  1116.  
  1117. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  1118. if (message.substr(0, 2) === ': ') {
  1119. message = message.substr(2);
  1120. }
  1121.  
  1122. window.open('https://www.deepl.com/translator#en/' + self.settings.targetLanguage + '/' + message);
  1123. });
  1124.  
  1125. var showChatlog = function() {
  1126. $('#miracle-complete-chatlog').html(chatLogCode);
  1127. $modal.toggle();
  1128. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  1129. };
  1130.  
  1131. window.addEventListener('keyup', function (event) {
  1132. // Ignore text input field so typing in them is possible
  1133. if (self.isWritingText()) {
  1134. return;
  1135. }
  1136.  
  1137. if (event.keyCode == self.settings.bindings.chatLog) {
  1138. showChatlog();
  1139. }
  1140. });
  1141.  
  1142. window.addEventListener('miracleCommand', function(commandEvent) {
  1143. if (commandEvent.command === '/chatlog') {
  1144. showChatlog();
  1145. $('#chtbox').val('');
  1146. }
  1147. });
  1148. },
  1149.  
  1150. favSkins: function () {
  1151. var self = this;
  1152.  
  1153. // We need to have a delay, because the menu is not loaded right away
  1154. setTimeout(function () {
  1155. var favIconClick = function () {
  1156. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  1157.  
  1158. if (self.settings.favSkins.includes(id)) {
  1159. $(this).addClass('skin-not-fav');
  1160. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  1161. var index = self.settings.favSkins.indexOf(id);
  1162. self.settings.favSkins.splice(index, 1);
  1163. } else {
  1164. $(this).removeClass('skin-not-fav');
  1165. self.settings.favSkins.push(id);
  1166. }
  1167. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  1168. renderFavSkins();
  1169. };
  1170.  
  1171. var renderFavSkins = function () {
  1172. var $skins = null;
  1173.  
  1174. if ($('#fav-skins').length > 0) {
  1175. $skins = $('#fav-skins');
  1176. $skins.html('');
  1177. } else {
  1178. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  1179. $skins.insertAfter('#publicSkinsHeader');
  1180.  
  1181. $('#fav-skins').click(function (event) {
  1182. if (event.target.tagName.toLowerCase() === 'span') {
  1183. favIconClick.apply(event.target);
  1184. }
  1185. });
  1186. }
  1187. self.settings.favSkins.forEach(function (id) {
  1188. $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>');
  1189. });
  1190. $skins.append('<div style="clear: both"></div>');
  1191. };
  1192.  
  1193. var addFavIcons = function () {
  1194. var $skins = $('#publicSkinsPage');
  1195. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  1196.  
  1197. $skins.find('h4').each(function () {
  1198. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  1199. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  1200.  
  1201. $favIcon.click(favIconClick);
  1202.  
  1203. $(this).append($favIcon);
  1204.  
  1205. if (! self.settings.favSkins.includes(id)) {
  1206. $favIcon.addClass('skin-not-fav');
  1207. }
  1208. });
  1209. };
  1210. var initialized = false;
  1211. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  1212. if (!initialized) {
  1213. var checkState = function () {
  1214. if ($('#publicSkinsPage').html() !== '') {
  1215. addFavIcons();
  1216. renderFavSkins();
  1217. } else {
  1218. setTimeout(checkState, 30);
  1219. }
  1220. };
  1221. checkState();
  1222. initialized = true;
  1223. }
  1224. });
  1225. $('#phpSkins').click(function (event) {
  1226. if (event.target.classList.contains('publicskins-nav-btn')) {
  1227. addFavIcons();
  1228. }
  1229. });
  1230.  
  1231. }, 500);
  1232. },
  1233.  
  1234. skinChanger: function() {
  1235. var self = this;
  1236.  
  1237. // When the user changes the skin, display ID of the picked skin
  1238. var originalToggleSkin = window.toggleSkin;
  1239. window.toggleSkin = function () {
  1240. self.message('Picked skin with ID ' + arguments[0]);
  1241.  
  1242. return originalToggleSkin.apply(this, arguments);
  1243. };
  1244.  
  1245. var useSkinFromSlot = function (skinSlot, skinId) {
  1246. var skinUri = null;
  1247.  
  1248. if (skinId) {
  1249. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  1250. skinUri = self.getSkinUrl();
  1251. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1252.  
  1253. self.message('Skin ' + skinId + ' saved in slot ' + skinSlot + ' ✔️');
  1254. }
  1255.  
  1256. skinId = parseInt(skinId);
  1257. self.settings.quickSkins[skinSlot - 1] = skinId;
  1258. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  1259. } else {
  1260. skinId = self.settings.quickSkins[skinSlot - 1];
  1261. if (!skinId) {
  1262. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  1263. $('#chtbox').val('');
  1264. return;
  1265. }
  1266. }
  1267.  
  1268. if (skinUri === null) {
  1269. self.useSkin(skinId);
  1270. }
  1271.  
  1272. $('#chtbox').val('');
  1273. };
  1274.  
  1275. window.addEventListener('miracleCommand', function(commandEvent) {
  1276.  
  1277. if (commandEvent.command === 'skin1' || commandEvent.command === '/skin1') {
  1278. useSkinFromSlot(1, commandEvent.argument1);
  1279. }
  1280. if (commandEvent.command === 'skin2' || commandEvent.command === '/skin2') {
  1281. useSkinFromSlot(2, commandEvent.argument1);
  1282. }
  1283. if (commandEvent.command === 'skin3' || commandEvent.command === '/skin3') {
  1284. useSkinFromSlot(3, commandEvent.argument1);
  1285. }
  1286. if (commandEvent.command === 'skin4' || commandEvent.command === '/skin4') {
  1287. useSkinFromSlot(4, commandEvent.argument1);
  1288. }
  1289. if (commandEvent.command === 'skin5' || commandEvent.command === '/skin5') {
  1290. useSkinFromSlot(5, commandEvent.argument1);
  1291. }
  1292. if (commandEvent.command === 'skin6' || commandEvent.command === '/skin6') {
  1293. useSkinFromSlot(6, commandEvent.argument1);
  1294. }
  1295. if (commandEvent.command === 'skin7' || commandEvent.command === '/skin7') {
  1296. useSkinFromSlot(7, commandEvent.argument1);
  1297. }
  1298. if (commandEvent.command === 'skin8' || commandEvent.command === '/skin8') {
  1299. useSkinFromSlot(8, commandEvent.argument1);
  1300. }
  1301. if (commandEvent.command === 'skin9' || commandEvent.command === '/skin9') {
  1302. useSkinFromSlot(9, commandEvent.argument1);
  1303. }
  1304. if (commandEvent.command === 'skin10' || commandEvent.command === '/skin10') {
  1305. useSkinFromSlot(10, commandEvent.argument1);
  1306. }
  1307. if (commandEvent.command === 'skin11' || commandEvent.command === '/skin11') {
  1308. useSkinFromSlot(11, commandEvent.argument1);
  1309. }
  1310. if (commandEvent.command === 'skin12' || commandEvent.command === '/skin12') {
  1311. useSkinFromSlot(12, commandEvent.argument1);
  1312. }
  1313. if (commandEvent.command === 'skin13' || commandEvent.command === '/skin13') {
  1314. useSkinFromSlot(13, commandEvent.argument1);
  1315. }
  1316. if (commandEvent.command === 'skin14' || commandEvent.command === '/skin14') {
  1317. useSkinFromSlot(14, commandEvent.argument1);
  1318. }
  1319. if (commandEvent.command === 'skin15' || commandEvent.command === '/skin15') {
  1320. useSkinFromSlot(15, commandEvent.argument1);
  1321. }
  1322. if (commandEvent.command === 'skin16' || commandEvent.command === '/skin16') {
  1323. useSkinFromSlot(16, commandEvent.argument1);
  1324. }
  1325. if (commandEvent.command === 'skin17' || commandEvent.command === '/skin17') {
  1326. useSkinFromSlot(17, commandEvent.argument1);
  1327. }
  1328. if (commandEvent.command === 'skin18' || commandEvent.command === '/skin18') {
  1329. useSkinFromSlot(18, commandEvent.argument1);
  1330. }
  1331. if (commandEvent.command === 'skin19' || commandEvent.command === '/skin19') {
  1332. useSkinFromSlot(19, commandEvent.argument1);
  1333. }
  1334. if (commandEvent.command === 'skin20' || commandEvent.command === '/skin20') {
  1335. useSkinFromSlot(20, commandEvent.argument1);
  1336. }
  1337. if (commandEvent.command === 'skin21' || commandEvent.command === '/skin21') {
  1338. self.message('Only 20 skin slots are available ❌', true);
  1339. $('#chtbox').val('').focus();
  1340. }
  1341. });
  1342.  
  1343. window.addEventListener('keyup', function (event) {
  1344. // Ignore text input field so typing in them is possible
  1345. if (self.isWritingText()) {
  1346. return;
  1347. }
  1348.  
  1349. if (event.keyCode == self.settings.bindings.skin1) {
  1350. useSkinFromSlot(1);
  1351. }
  1352. if (event.keyCode == self.settings.bindings.skin2) {
  1353. useSkinFromSlot(2);
  1354. }
  1355. if (event.keyCode == self.settings.bindings.skin3) {
  1356. useSkinFromSlot(3);
  1357. }
  1358. if (event.keyCode == self.settings.bindings.skin4) {
  1359. useSkinFromSlot(4);
  1360. }
  1361. if (event.keyCode == self.settings.bindings.skin5) {
  1362. useSkinFromSlot(5);
  1363. }
  1364. if (event.keyCode == self.settings.bindings.skin6) {
  1365. useSkinFromSlot(6);
  1366. }
  1367. if (event.keyCode == self.settings.bindings.skin7) {
  1368. useSkinFromSlot(7);
  1369. }
  1370. if (event.keyCode == self.settings.bindings.skin8) {
  1371. useSkinFromSlot(8);
  1372. }
  1373. if (event.keyCode == self.settings.bindings.skin9) {
  1374. useSkinFromSlot(9);
  1375. }
  1376. });
  1377. },
  1378.  
  1379. ultraSplit: function() {
  1380. var self = this;
  1381.  
  1382. window.addEventListener('keyup', function () {
  1383. if (event.keyCode == self.settings.bindings.ultraSplit) {
  1384. var tripleSplit = function() {
  1385. window.onkeydown({keyCode: self.hotkeys.T.c});
  1386. window.onkeyup({keyCode: self.hotkeys.T.c});
  1387. }
  1388.  
  1389. tripleSplit();
  1390. window.setTimeout(function() {
  1391. tripleSplit();
  1392. window.setTimeout(function() {
  1393. tripleSplit();
  1394. }, 150);
  1395. }, 150);
  1396. }
  1397. });
  1398. },
  1399.  
  1400. lineSplit: function() {
  1401. var self = this;
  1402.  
  1403. window.addEventListener('miracleCommand', function(commandEvent) {
  1404. if (commandEvent.command === '/linesplit') {
  1405. self.lineSplitAt = Date.now();
  1406. self.message('Linesplit •••••');
  1407.  
  1408. var doSplit = function() {
  1409. if (Date.now() - self.lineSplitAt < 1000) {
  1410. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  1411. var x = window.innerWidth / 2;
  1412. var y = factor * (window.innerHeight / 2);
  1413.  
  1414. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1415.  
  1416. window.requestAnimationFrame(doSplit);
  1417. } else {
  1418. if (Date.now() - self.lineSplitAt < 3000) {
  1419. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  1420. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.Space.c}));
  1421. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.Space.c}));
  1422. self.splitAt = Date.now();
  1423. }
  1424.  
  1425. window.requestAnimationFrame(doSplit);
  1426. }
  1427. }
  1428. };
  1429. doSplit();
  1430. $('#chtbox').val('');
  1431. }
  1432. });
  1433. },
  1434.  
  1435. dance: function () {
  1436. var self = this;
  1437.  
  1438. // Stop dancing on respawn
  1439. window.addEventListener('keydown', function (event) {
  1440. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1441. self.dancing = false;
  1442. }
  1443. });
  1444.  
  1445. var initDance = function() {
  1446. // Do nothing if a menu is open
  1447. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1448. return;
  1449. }
  1450.  
  1451. self.dancing = ! self.dancing;
  1452.  
  1453. if (self.dancing) {
  1454. self.performDance.apply(self);
  1455. }
  1456. };
  1457.  
  1458. window.addEventListener('keyup', function () {
  1459. if (event.keyCode == self.settings.bindings.dance) {
  1460. initDance();
  1461. }
  1462. });
  1463.  
  1464. window.addEventListener('miracleCommand', function(commandEvent) {
  1465. if (commandEvent.command === '/dance') {
  1466. initDance();
  1467. $('#chtbox').val('');
  1468. }
  1469. });
  1470. },
  1471.  
  1472. performDance: function () {
  1473. var self = this ? this : window.miracleScripts;
  1474.  
  1475. if (self.danceAngle === undefined) {
  1476. self.danceAngle = 0;
  1477. }
  1478.  
  1479. self.danceAngle += 20;
  1480.  
  1481. if (self.danceAngle > 360) {
  1482. self.danceAngle = 0;
  1483. }
  1484.  
  1485. var distance = 1000000; //Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  1486. var x = window.innerWidth / 2 + Math.sin(self.danceAngle * Math.PI / 180) * distance;
  1487. var y = window.innerHeight / 2 + Math.cos(self.danceAngle * Math.PI / 180) * distance;
  1488. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1489.  
  1490. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  1491. if (document.getElementById('advert').style.display !== 'none') {
  1492. self.dancing = false;
  1493. }
  1494. if (self.dancing) {
  1495. window.requestAnimationFrame(self.performDance);
  1496. }
  1497. },
  1498.  
  1499. waste: function() {
  1500. var self = this;
  1501.  
  1502. window.addEventListener('keydown', function (event) {
  1503. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1504. self.wasting = false;
  1505. }
  1506. });
  1507.  
  1508. window.addEventListener('miracleCommand', function(commandEvent) {
  1509. if (commandEvent.command === '/waste') {
  1510. if (self.wasting) {
  1511. self.wasting = false;
  1512. self.message('Stopped wasting all mass.');
  1513. self.dancing = false;
  1514. } else {
  1515. self.wasting = true;
  1516. self.message('Wasting all mass... 💥');
  1517. if (! self.dancing) {
  1518. self.dancing = true;
  1519. self.performDance.apply(self);
  1520. }
  1521. $('#chtbox').val('spinshakeflip').focus();
  1522. }
  1523.  
  1524. var doWaste = function() {
  1525. // Stop wasting mass if dead ... to avoid continuing wasting after next respawn
  1526. if (document.getElementById('advert').style.display !== 'none') {
  1527. self.wasting = false;
  1528. }
  1529. if (! self.wasting) {
  1530. return;
  1531. }
  1532. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.W.c}));
  1533. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.W.c}));
  1534. window.requestAnimationFrame(doWaste);
  1535. };
  1536. doWaste();
  1537. }
  1538. });
  1539. },
  1540.  
  1541. fpsPing: function () {
  1542. var self = this;
  1543.  
  1544. window.addEventListener('miracleCommand', function(commandEvent) {
  1545. if (commandEvent.command === 'ping' || commandEvent.command === '/ping' || commandEvent.command === '/lag') {
  1546. window.setFPS(1);
  1547. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  1548. if (parseInt(ping) > 0) {
  1549. if (parseInt(ping) >= 0 && parseInt(ping) < 35) { pingRating = 'Perfect! ✔️'; }
  1550. if (parseInt(ping) >= 35 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  1551. if (parseInt(ping) >= 70 && parseInt(ping) < 120) { pingRating = 'Acceptable! ✔️'; }
  1552. if (parseInt(ping) >= 120 && parseInt(ping) < 200) { pingRating = 'Bad! ❌'; }
  1553. if (parseInt(ping) >= 200 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  1554. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  1555. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  1556. } else {
  1557. ping = '∞ (infinite) ';
  1558. }
  1559. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating + self.watermark).focus();
  1560. }
  1561. if (commandEvent.command === 'fps' || commandEvent.command === '/fps') {
  1562. window.setFPS(1);
  1563. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  1564. if (parseInt(fps) > 0) {
  1565. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  1566. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  1567. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  1568. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  1569. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  1570. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  1571. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  1572. } else {
  1573. fpsRating = '';
  1574. }
  1575.  
  1576. $('#chtbox').val('has ' + fps + 'fps. ' + fpsRating + self.watermark).focus();
  1577. }
  1578. });
  1579. },
  1580.  
  1581. timer: function() {
  1582. var self = this;
  1583.  
  1584. var timerStartedAt = null;
  1585. var timerMinutes = null;
  1586. var timeoutId = null;
  1587. var updateId = null;
  1588.  
  1589. // Note: The "settings" item is missing in the local storage until settings have been changed
  1590. var agmaSettings = localStorage.getItem('settings') ? JSON.parse(localStorage.getItem('settings')) : { sDark : false };
  1591. var color = (agmaSettings.sDark) ? '#999' : '#3e3e3e';
  1592. var $timeUi = $('<div style="position: fixed; right: 20px; bottom: 230px; z-index: 998; color: ' + color + '; pointer-events: none"></div>');
  1593. $('body').append($timeUi);
  1594.  
  1595.  
  1596. var updateUi = function () {
  1597.  
  1598. var time = '';
  1599. if (self.settings.showClock) {
  1600. var hours = (new Date).getHours();
  1601. var minutes = (new Date).getMinutes();
  1602. time = (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
  1603. if (timeoutId) {
  1604. time = ' - ' + time;
  1605. }
  1606. }
  1607.  
  1608. var remaining = '';
  1609. if (timeoutId) {
  1610. remaining = Math.ceil(((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60) + 'm';
  1611. }
  1612.  
  1613. if (time || remaining) {
  1614. $timeUi.text('🕒 ' + remaining + time);
  1615. } else {
  1616. $timeUi.text('');
  1617. }
  1618. };
  1619. updateUi();
  1620. updateId = setInterval(updateUi, 2000);
  1621.  
  1622. window.addEventListener('miracleCommand', function(commandEvent) {
  1623. if (commandEvent.command === 'timer' || commandEvent.command === '/timer') {
  1624. var argument1 = commandEvent.argument1;
  1625. var argument2 = commandEvent.argument2;
  1626.  
  1627. if (argument1) {
  1628. timerMinutes = parseInt(argument1);
  1629. if (argument2 === 'h' || argument2 === 'hour' || argument2 === 'hours') {
  1630. timerMinutes *= 60;
  1631. }
  1632. if (timeoutId !== null) {
  1633. clearTimeout(timeoutId);
  1634. }
  1635.  
  1636. if (argument1 === '0' || argument1 === 'reset' || argument1 === 'stop' || argument1 === 'clear' || argument1 === 'remove') {
  1637. self.message('🗑️ Timer removed');
  1638. } else {
  1639. timerStartedAt = Date.now();
  1640. timeoutId = setTimeout(function () {
  1641. timeoutId = null;
  1642. updateUi()
  1643. var message = '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.';
  1644. self.message(message);
  1645. self.swal('Time has expired', '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.');
  1646. }, timerMinutes * 60 * 1000);
  1647. updateUi();
  1648.  
  1649. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  1650. }
  1651. } else {
  1652. if (timeoutId === null) {
  1653. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  1654. } else {
  1655. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1656. self.message('🕒 ' + Math.round(remaining * 10) / 10 + ' minutes remaining.');
  1657. }
  1658. }
  1659. $('#chtbox').val('').focus();
  1660. }
  1661. });
  1662. },
  1663.  
  1664. alive: function() {
  1665. var self = this;
  1666.  
  1667. var element = document.getElementById('playBtn');
  1668. element.addEventListener('click', function() {
  1669. if (! self.isAlive) {
  1670. self.spawnedAt = Date.now();
  1671. self.isAlive = true;
  1672. }
  1673. });
  1674. element = document.querySelector('.bottom-dashboard-box img[title=Respawn]');
  1675. element.addEventListener('click', function() {
  1676. self.spawnedAt = Date.now();
  1677. self.isAlive = true;
  1678. });
  1679. element = document.getElementById('advertContinue');
  1680. element.addEventListener('click', function() {
  1681. self.isAlive = false;
  1682. });
  1683.  
  1684. window.addEventListener('keydown', function (event) {
  1685. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1686. self.spawnedAt = Date.now();
  1687. self.isAlive = true;
  1688. }
  1689. });
  1690.  
  1691. window.addEventListener('miracleCommand', function(commandEvent) {
  1692. if (commandEvent.command === '/alive' || commandEvent.command === 'alive') {
  1693. var minutes = parseInt((Date.now() - self.spawnedAt) / 1000 / 60);
  1694. if (minutes < 1) {
  1695. minutes = parseInt((Date.now() - self.spawnedAt) / 1000) + ' Seconds & 0';
  1696. }
  1697. if (minutes > 60) {
  1698. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1699. }
  1700.  
  1701. if (! self.isAlive || document.getElementById('advert').style.display !== 'none') {
  1702. if (isNaN(minutes)) {
  1703. $('#chtbox').val('is not alive ☠️');
  1704. } else {
  1705. $('#chtbox').val('is not alive but spawned ' + minutes + ' Minutes ago' + self.watermark);
  1706. }
  1707. } else {
  1708. $('#chtbox').val('has been alive for ' + minutes + ' Minutes' + self.watermark);
  1709. }
  1710. }
  1711. });
  1712.  
  1713. },
  1714.  
  1715. guessing: function() {
  1716. var self = this;
  1717.  
  1718. var guessItem = null;
  1719. var startedAt = null;
  1720. var timeout = null;
  1721. var roundLength = 60 * 1000;
  1722. var library = [ // LMAO.... go away, no cheating please! 🙄
  1723. ['🌞🌼', 'Sunflower', 1],
  1724. ['🌧️🏹', 'Rainbow', 1],
  1725. ['🌧️📅', 'Rainy day', 3],
  1726. ['❄️👑', 'Ice Queen', 3],
  1727. ['🦶⚽', 'Football', 1],
  1728. ['🌙💡', 'Moonlight', 2],
  1729. ['🌞💡', 'Sunlight', 2],
  1730. ['😱🎥', 'Horror movie', 3],
  1731. ['👨🐺', 'Werewolf', 2],
  1732. ['🐮👦', 'Cowboy', 1],
  1733. ['🌌🚢', 'Spaceship', 2],
  1734. ['🔥👨', 'Fireman', 2],
  1735. ['🔥⚔️', 'Firefighter', 2],
  1736. ['🔵🍓', 'Blueberry', 3],
  1737. ['🔥🐶', 'Hotdog', 2],
  1738. ['📹🎮', 'Video game', 4],
  1739. ['⭕💺', 'Wheelchair', 3],
  1740. ['🌚🚶', 'Moonwalk', 3],
  1741. ['🔒🏠', 'Secret room', 4],
  1742. ['🔴🦠', 'Mothercell', 5],
  1743. ['📺👨', 'YouTuber', 3],
  1744. ['🚶💀', 'Walking Dead', 3],
  1745. ['🔥🚧', 'Fireworks', 4],
  1746. ['🧺⚽', 'Basketball', 2],
  1747. ['🍯🌙', 'Honeymoon', 2],
  1748. ['🤗🚢', 'Friendship', 3],
  1749. ['👪💼', 'Teamwork', 4],
  1750. ['🧀🍔', 'Cheeseburger', 2],
  1751. ['❄️⚽', 'Snowball', 1],
  1752. ['🔴🔴🔴🔴🔴', 'Line split', 2],
  1753. ];
  1754.  
  1755. window.addEventListener('miracleCommand', function(commandEvent) {
  1756. if (commandEvent.command === '/guess') {
  1757. if (startedAt !== null && Date.now() - startedAt < roundLength) {
  1758. self.message('🚫 Wait a little longer (' + Math.ceil((roundLength - (Date.now() - startedAt)) / 1000) + ' seconds)', true);
  1759. $('#chtbox').val('');
  1760. return;
  1761. }
  1762.  
  1763. guessItem = library[self.getRandomInt(0, library.length - 1)];
  1764.  
  1765. var hint = '';
  1766. if (guessItem[2] !== null) {
  1767. hint = guessItem[1];
  1768. hint = self.fonts['monospace'](hint.charCodeAt(0)) + hint.substr(1);
  1769. for (var i = 1; i < guessItem[2]; i++) {
  1770. var pos = self.getRandomInt(0, hint.length);
  1771. hint = hint.substr(0, pos) +
  1772. self.fonts['monospace'](hint.charCodeAt(pos)) +
  1773. hint.substr(pos + 1);
  1774. }
  1775. hint = hint.replace(/(\w)/gi, '_ ');
  1776. hint = ' → ' + hint;
  1777. }
  1778.  
  1779. $('#chtbox').val('𝘎𝘶𝘦𝘴𝘴 𝘸𝘩𝘢𝘵 𝘵𝘩𝘪𝘴 𝘪𝘴: ' + guessItem[0] + hint);
  1780.  
  1781. startedAt = Date.now();
  1782. timeout = setTimeout(function() {
  1783. self.message('Guessing game ended without a winner. The word was: "' + guessItem[1] + '"');
  1784. self.swal('Miracle Guessing Game', 'Guessing game ended without a winner. The word was: "<span style="color: silver">' + guessItem[1] + '</span>"');
  1785. }, roundLength);
  1786. }
  1787. });
  1788.  
  1789. window.addEventListener('miracleChatMessage', function(messageEvent) {
  1790. if (startedAt !== null && Date.now() - startedAt <= roundLength) {
  1791. if (messageEvent.message.toLowerCase().trim().replace(/\s/g, '') === ':' + guessItem[1].toLowerCase()) {
  1792. $('#chtbox').val('𝘎𝘶𝘦𝘴𝘴𝘪𝘯𝘨 𝘨𝘢𝘮𝘦 𝘸𝘰𝘯 𝘣𝘺 𝘱𝘭𝘢𝘺𝘦𝘳 ' + messageEvent.nickname);
  1793. self.message('Guessing game won by player "' + messageEvent.nickname + '"!');
  1794. self.swal('Miracle Guessing Game', 'Guessing game won by "<span style="color: ' + messageEvent.nicknameColor + '">' + messageEvent.nickname + '</span>"!');
  1795. startedAt = null;
  1796. clearTimeout(timeout);
  1797. }
  1798. }
  1799. });
  1800. },
  1801.  
  1802. nameColor: function() {
  1803. var self = this;
  1804.  
  1805. window.addEventListener('miracleCommand', function(commandEvent) {
  1806. if (commandEvent.command === '/namecolor' || commandEvent.command === '/colorname' || commandEvent.command === '/colorchange') {
  1807. self.message('🚫 Changing the name color is no longer possible as there is a server-side fix', true);
  1808. $('#chtbox').val('');
  1809. }
  1810. });
  1811. },
  1812.  
  1813. wearablesToggle: function() {
  1814. var self = this;
  1815.  
  1816. // Note: Doesn't get updated, so we can only use it to init
  1817. var checked = document.getElementById('cWearables').checked;
  1818.  
  1819. window.addEventListener('keydown', function () {
  1820.  
  1821. if (event.keyCode == self.settings.bindings.wearables) {
  1822. checked = ! checked;
  1823. window.setWearables(checked);
  1824. }
  1825. });
  1826. },
  1827.  
  1828. keyboardLayout: function() {
  1829. if (this.settings.showKeyboardLayout && this.hotkeys) {
  1830. var $element = $('<table id="keyboard-layout" style="position: fixed; right: 10px; top: 345px; border-collapse: separate; border-spacing: 10px 0; text-align: right">' +
  1831. '<tr><td>Split: </td><td>&nbsp;&nbsp;' + this.hotkeys.Space.d + '</td></tr>' +
  1832. '<tr><td>Double Split: </td><td>' + this.hotkeys.D.d + '</td></tr>' +
  1833. '<tr><td>Triple Split: </td><td>' + this.hotkeys.T.d + '</td></tr>' +
  1834. '<tr><td>Macro Split: </td><td>' + this.hotkeys.Z.d + '</td></tr>' +
  1835. '<tr><td>Ultra Split: </td><td>' + this.keyboardMap[this.settings.bindings.ultraSplit] + '</td></tr>' +
  1836. '<tr><td>Feed: </td><td>' + this.hotkeys.W360.d + '</td></tr>' +
  1837. '<tr><td>Respawn: </td><td>' + this.hotkeys.M.d + '</td></tr>' +
  1838. '<tr><td>Recombine: </td><td>' + this.hotkeys.E.d + '</td></tr>' +
  1839. '<tr><td>2x Speed: </td><td>' + this.hotkeys.S.d + '</td></tr>' +
  1840. '<tr><td>Freeze Self: </td><td>' + this.hotkeys.F.d + '</td></tr>' +
  1841. '<tr><td>Invisibility: </td><td>' + this.hotkeys.I.d + '</td></tr>' +
  1842. '<tr><td>Toogle Camera: </td><td>' + this.hotkeys.Q.d + '</td></tr>' +
  1843. '</table>');
  1844.  
  1845.  
  1846. $element.insertAfter($('#leaderboard'));
  1847. }
  1848. },
  1849.  
  1850. skinApplier: function() {
  1851. var self = this;
  1852.  
  1853. var $useWearablesItem = $('<li class="contextmenu-item enabled"><div class="context-icon"><i class="fa fa-graduation-cap"></i></div><p>Use Player\'s Wearables</p></li>');
  1854. $useWearablesItem.insertAfter('#contextPlayer');
  1855. var $useSkinItem = $('<li class="contextmenu-item enabled"><div class="context-icon"><i class="fa fa-eye"></i></div><p>Use Player\'s Skin</p></li>');
  1856. $useSkinItem.insertAfter('#contextPlayer');
  1857.  
  1858. $useSkinItem.click(function() {
  1859. var skinUrl = self.getSkinUrl('#contextPlayerSkin');
  1860. if (skinUrl === null) {
  1861. self.message('This player does not use a skin or no player selected 🚫', true);
  1862. } else {
  1863. var skinId = parseInt(skinUrl.substr(22)); // Cut off "https://agma.io/skins/"
  1864. self.useSkin(skinId);
  1865. }
  1866. });
  1867.  
  1868. $useWearablesItem.click(function() {
  1869. var extractWearableId = function(style) {
  1870. var pos = style.indexOf('background-image: url("wearables/');
  1871. if (pos === -1) {
  1872. return null;
  1873. }
  1874. return parseInt(style.substr(pos + 33));
  1875. }
  1876.  
  1877. var wearables = [
  1878. extractWearableId($('#contextPlayerWear1').attr('style')),
  1879. extractWearableId($('#contextPlayerWear2').attr('style')),
  1880. extractWearableId($('#contextPlayerWear3').attr('style')),
  1881. extractWearableId($('#contextPlayerWear4').attr('style')),
  1882. extractWearableId($('#contextPlayerWear5').attr('style')),
  1883. ];
  1884.  
  1885. var useWearables = function(wearables) {
  1886. window.azad(true);
  1887.  
  1888. setTimeout(function () {
  1889. $('#skinExampleMenu').click();
  1890.  
  1891.  
  1892. setTimeout(function () {
  1893.  
  1894. $('#wearablesTab a').click()
  1895.  
  1896. setTimeout(function () {
  1897. // First remove all current wearables
  1898. var oldWearables = [
  1899. extractWearableId($('#wearExampleShop1').attr('style')),
  1900. extractWearableId($('#wearExampleShop2').attr('style')),
  1901. extractWearableId($('#wearExampleShop3').attr('style')),
  1902. extractWearableId($('#wearExampleShop4').attr('style')),
  1903. extractWearableId($('#wearExampleShop5').attr('style')),
  1904. ]
  1905. oldWearables.forEach(function(id) {
  1906. //toggleWearable(id, 0, 0, 0, false);
  1907. $('#wearableUseBtn' + id).click();
  1908. });
  1909.  
  1910.  
  1911. wearables.forEach(function(id) {
  1912. $('#wearableUseBtn' + id).click();
  1913. });
  1914.  
  1915. setTimeout(function () {
  1916. $('#shopModalDialog button.close').click();
  1917.  
  1918. setTimeout(function () {
  1919. window.setNick(document.getElementById('nick').value);
  1920. }, 200);
  1921. }, 200);
  1922. }, 1000);
  1923.  
  1924. }, 200);
  1925. }, 200);
  1926. }
  1927. useWearables(wearables);
  1928. });
  1929. },
  1930.  
  1931. help: function() {
  1932. $('body').append('<style>#miracle-help-table tr { cursor: pointer } #miracle-help-table table tr:hover { background-color: rgba(255,255,255,0.1) } #miracle-help-button:hover { background: rgba(68,68,68,.8); color: #ffdd67; cursor: pointer } #miracle-help-button { position: absolute; z-index: 10; bottom: 10px; left: 480px; height: 30px; width: 30px; background: rgba(68,68,68,.5); color: #cbb059; }</style>');
  1933. var $modal = $('<div class="miracle-primary-color-font" style="position: fixed; overflow-y: scroll; width: 100%; height: 100%; padding: 50px; background-color: rgba(0,0,0,0.95); z-index: 999; display: none"></div>');
  1934. $modal.append('<h1>Miracle Scripts Help</h1>');
  1935.  
  1936. var helpText = '<br><span style="color: #717171">These chat commands are available. Click on a command to use it!</span><br><br><table id="miracle-help-table"><tr><td><table>' +
  1937. '<tr><th style="padding-right: 70px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  1938. '<tr><td><code>/help</code></td><td>Show this help</td></tr>' +
  1939. '<tr><td><code>/miracle</code></td><td>Show version info</td></tr>' +
  1940. '<tr><td><code>/miraclesettings</code></td><td>Show the miracle settings page</td></tr>' +
  1941. '<tr><td><code>/players</code></td><td>Display how many players are online</td></tr>' +
  1942. '<tr><td><code>/skin&lt;n></code></td><td>Change to skin &lt;n> (1-20)</td></tr>' +
  1943. '<tr><td><code>/skin&lt;n> this</code></td><td>Store current skin as skin <n></td></tr>' +
  1944. '<tr><td><code>/skin&lt;n> &lt;id></code></td><td>Store skin with ID &lt;id> as skin &lt;n> (1-20)</td></tr>' +
  1945. '<tr><td><code>/skinid</code></td><td>Send a chat message with your skin ID</td></tr>' +
  1946. '<tr><td><code>/useskin &lt;id></code></td><td>Use skin with the given ID</td></tr>' +
  1947. '<tr><td><code>/chatlog</code></td><td>Show the extended chat log</td></tr>' +
  1948. '<tr><td><code>/shout &lt;text></code></td><td>Purchase a megaphone shout for 20000 coins></td></tr>' +
  1949. '<tr><td><code>/paste</code></td><td>Show the emojis and text paste page</td></tr>' +
  1950. '<tr><td><code>/timer &lt;n></code></td><td>Set timer for &lt;n> minutes</td></tr>' +
  1951. '<tr><td><code>/timer &lt;n> h</code></td><td>Set timer for &lt;n> hours</td></tr>' +
  1952. '<tr><td><code>/timer stop</code></td><td>Stop the timer</td></tr>' +
  1953. '<tr><td><code>/xp</code></td><td>Send a chat message with your level and next level\'s progress</td></tr>' +
  1954. '<tr><td><code>/powerups</code></td><td>Send a chat message with your powerup amounts</td></tr>' +
  1955. '<tr><td><code>/fps</code></td><td>Send a chat message with current fps</td></tr>' +
  1956. '<tr><td><code>/ping</code></td><td>Send a chat message with current ping</td></tr>' +
  1957. '<tr><td><code>/online</code></td><td>For how long are you online in the current session?</td></tr>' +
  1958. '<tr><td><code>/alive</code></td><td>For how long are you alive?</td></tr>' +
  1959. '<tr><td><code>/solo</code></td><td>Show the solo server message</td></tr>' +
  1960. '<tr><td><code>/dice</code></td><td>Roll a dice with 6 sides</td></tr>' +
  1961. '<tr><td><code>/dice &lt;n></code></td><td>Roll a dice with &lt;n> sides</td></tr>' +
  1962. '<tr><td><code>/guess</code></td><td>Start a guessing chat game</td></tr>' +
  1963. '<tr><td><code>/linesplit</code></td><td>Let your cell make a linesplit</td></tr>' +
  1964. '<tr><td><code>/waste</code></td><td>Waste all your mass</td></tr>' +
  1965. '<tr><td><code>/dance</code></td><td>Let your cell dance</td></tr>' +
  1966.  
  1967.  
  1968. '</table></td><td style="vertical-align: top"><table>' +
  1969. '<tr><th style="padding-right: 70px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  1970. '<tr><td><code>/coins</code></td><td>Send a chat message with your coins</td></tr>' +
  1971. '<tr><td><code>/level</code></td><td>Send a chat message with your account level</td></tr>' +
  1972. '<tr><td><code>/rank</code></td><td>Send a chat message with your account rank</td></tr>' +
  1973. '<tr><td><code>/shake</code></td><td>Let your cells shake!</td></tr>' +
  1974. '<tr><td><code>/flip</code></td><td>Let your cells flip!</td></tr>' +
  1975. '<tr><td><code>/spin</code></td><td>Let your cells spin!</td></tr>' +
  1976. '<tr><td><code>/jump</code></td><td>Let your cells jump!</td></tr>' +
  1977. '<tr><td><code>/wacky</code></td><td>Your cells will be laughing faces!</td></tr>' +
  1978. '<tr><td><code>/stats</code></td><td>Show your battle royale stats</td></tr>' +
  1979. '<tr><td><code>/party &lt;message></code></td><td>Write a message to your party</td></tr>' +
  1980. '<tr><td><code>/pm &lt;account></code></td><td>Write a message to a given account</td></tr>' +
  1981. '</table></td></tr></table>';
  1982.  
  1983. $modal.append(helpText);
  1984.  
  1985. $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 () {
  1986. $modal.hide();
  1987. }));
  1988.  
  1989. $('body').append($modal);
  1990.  
  1991. this.$helpModal = $modal;
  1992.  
  1993. $('#miracle-help-table table tr').click(function() {
  1994. var cmd = $(this).find('code').text();
  1995. $('#chtbox').val($('#chtbox').val() + cmd).focus();
  1996. $modal.hide();
  1997. });
  1998.  
  1999. var $helpButton = $('<div id="miracle-help-button" title="Help" class="unselectable"><i class="fa fa-question-circle" style="position: absolute; top: 4px; left: 5px; font-size: 22px;"></i></div>').click(function() {
  2000. $modal.show();
  2001. });
  2002. $helpButton.insertAfter('#emojiBtn');
  2003.  
  2004. window.addEventListener('miracleCommand', function(commandEvent) {
  2005. if (commandEvent.command === '/help' || commandEvent.command === '/miraclehelp') {
  2006. $('#chtbox').val('').focus();
  2007. $modal.show();
  2008. }
  2009. });
  2010. },
  2011.  
  2012. commands: function () {
  2013. var self = this;
  2014. var minutes, skinId;
  2015.  
  2016. var sessionStartedAt = Date.now();
  2017.  
  2018. $('#chtbox').keydown(function (event) {
  2019. if (event.keyCode === 13) {
  2020. var message = $('#chtbox').val();
  2021. var command = message.split(' ')[0];
  2022. var argument1 = message.split(' ')[1];
  2023. var argument2 = message.split(' ')[2];
  2024.  
  2025. if (message === 'time' || command === '/time' || command === '/localtime') {
  2026. var now = new Date();
  2027. $('#chtbox').val('Local time: ' + now.toLocaleString() + self.watermark).focus();
  2028. }
  2029.  
  2030. if (message === 'minutes' || command === '/minutes' || message === 'online' || command === '/online' || command === '/session') {
  2031. if (message === 'minutes' || command === '/minutes') {
  2032. self.message('⛔ The /minutes command is deprecated, please use /online instead.', true);
  2033. }
  2034.  
  2035. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  2036. if (minutes < 1) {
  2037. minutes = parseInt((Date.now() - sessionStartedAt) / 1000) + ' Seconds & 0';
  2038. }
  2039. if (minutes > 60) {
  2040. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  2041. }
  2042. $('#chtbox').val('is online for: ' + minutes + ' Minutes in the current session' + self.watermark).focus();
  2043. }
  2044.  
  2045. if (command === '/solo' || command === '/noteam') {
  2046. $('#chtbox').val('⚠️⚠️⚠️ SOLO SERVER ⚠️⚠️⚠️ No teaming!! No hay equipo!! Pas d\'équipe!! Kein Teaming!! لا فريق').focus();
  2047. }
  2048.  
  2049. if (command === '/miracle') {
  2050. var miracleInfo = 'uses 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴';
  2051.  
  2052. if (GM_info) {
  2053. miracleInfo += ' ' + GM_info.script.version;
  2054. }
  2055.  
  2056. $('#chtbox').val(miracleInfo + '. Install for free from 𝘎𝘳𝘦𝘢𝘴𝘺𝘧𝘰𝘳𝘬.𝘰𝘳𝘨!' + self.watermark).focus();
  2057. }
  2058.  
  2059. if (command === '/skinid' || command === '/sayskin') {
  2060. var skinUri = self.getSkinUrl();
  2061. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  2062. $('#chtbox').val('uses the skin with the ID ' + skinId + self.watermark);
  2063. return;
  2064. }
  2065.  
  2066. if (command === '/useskin') {
  2067. skinId = parseInt(argument1);
  2068. if (! (skinId > 0)) {
  2069. self.message('Invalid skin ID given. Example usage of command: /useskin 123', true);
  2070. } else {
  2071. self.useSkin(skinId);
  2072. }
  2073.  
  2074. $('#chtbox').val('');
  2075. }
  2076.  
  2077. if (command.substr(0, 4) === '/say' || (command === '/party' && argument1.substr(0, 4) === '/say') || (command === '/pm' && argument2.substr(0, 4) === '/say')) {
  2078. self.message('🚫 This feature has been removed since the Agma staff does not allow it', true);
  2079. $('#chtbox').val('');
  2080. }
  2081.  
  2082. if (command === '/dice') {
  2083. var max = (argument1 > 0) ? parseInt(argument1) : 6;
  2084. var number = self.getRandomInt(1, max);
  2085. $('#chtbox').val('rolled a dice with ' + max + ' sides. Result: ' + number + self.watermark);
  2086. }
  2087.  
  2088. if (command === '/powerups' || command === '/powers') {
  2089. var map = {
  2090. invRecombine: 'rec',
  2091. invSpeed: 'speed',
  2092. invGrowth: 'growth',
  2093. invSpawnVirus: 'virus',
  2094. invSpawnMothercell: 'red virus',
  2095. invSpawnPortal: 'portal',
  2096. invSpawnGoldOre: 'block',
  2097. invFreeze: 'freeze',
  2098. inv360Shot: 'push',
  2099. invWall: 'wall',
  2100. }
  2101. var ids = Object.keys(map); var amount; var powerups = '';
  2102. for (var i = 0; i < ids.length; i++) {
  2103. // Note: If the amount of a powerup is 1, no number will be displayed.
  2104. amount = $('#' + ids[i] + ' p').text() || ($('#' + ids[i]).css('display') === 'none' ? 0 : 1);
  2105. if (amount > 0) {
  2106. if (powerups != '') {
  2107. powerups += ', ';
  2108. }
  2109. powerups += amount + ' ' + map[ids[i]];
  2110. }
  2111. }
  2112. if (powerups === '') {
  2113. powerups = 'no';
  2114. }
  2115. $('#chtbox').val(self.watermark + 'has ' + powerups);
  2116. }
  2117.  
  2118. if (command === '/xp' || command === '/progress') {
  2119. var xp = parseInt($('.xpBarTop span').text());
  2120. var text = '█'.repeat(xp / 10) + '▒'.repeat(10 - parseInt(xp / 10)) + ' ' + xp + '%';
  2121. $('#chtbox').val('is currently level ' + $('#level2').text() + ' with ' + text + ' of the next level completed' + self.watermark);
  2122. }
  2123.  
  2124. if (command === '/megaphone' || command === '/megashout' || command === '/shout') {
  2125. // Notes: 1-7 = colors. The shout message can have max 130 chars, but chat messages can be only 100(?) chars long so np
  2126. self.warnBeforeMegaShout(message.substr(message.indexOf(' ') + 1), self.getRandomInt(1, 7));
  2127. $('#chtbox').val('');
  2128. }
  2129.  
  2130. if (command === '/players') {
  2131. var gameservers = JSON.parse(localStorage.getItem('gameservers'));
  2132. var players = 0;
  2133. var current = null;
  2134.  
  2135. gameservers.forEach(function(gameserver) {
  2136. players += gameserver.players;
  2137. if (gameserver.isCurrent) {
  2138. current = gameserver.players + '/' + gameserver.maxPlayers;
  2139. }
  2140. });
  2141.  
  2142. $('#chtbox').val('Players online in Agma: ' + players);
  2143.  
  2144. if (current !== null) {
  2145. $('#chtbox').val($('#chtbox').val() + ' - current server: ' + current);
  2146. }
  2147. }
  2148.  
  2149. if (command === '/roll') {
  2150. self.message('🚫 This feature has been removed from Agma', true);
  2151. }
  2152.  
  2153. var commandEvent = new Event('miracleCommand');
  2154. commandEvent.message = message;
  2155. commandEvent.command = command;
  2156. commandEvent.argument1 = argument1;
  2157. commandEvent.argument2 = argument2;
  2158. window.dispatchEvent(commandEvent);
  2159. }
  2160. });
  2161. },
  2162.  
  2163. /**
  2164. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  2165. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  2166. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumerics
  2167. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumeric_Supplement
  2168. */
  2169. fonts: {
  2170. doubleStruck : function(charCode) {
  2171. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  2172. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  2173. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  2174. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  2175. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  2176. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  2177. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  2178. if (charCode >= 65 && charCode <= 90) {
  2179. return String.fromCodePoint(0x1D538 + charCode - 65);
  2180. }
  2181. if (charCode >= 97 && charCode <= 122) {
  2182. return String.fromCodePoint(0x1D552 + charCode - 97);
  2183. }
  2184. if (charCode >= 48 && charCode <= 57) {
  2185. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  2186. }
  2187. return String.fromCharCode(charCode);
  2188. },
  2189.  
  2190. monospace : function(charCode) {
  2191. if (charCode >= 65 && charCode <= 90) {
  2192. return String.fromCodePoint(0x1D670 + charCode - 65);
  2193. }
  2194. if (charCode >= 97 && charCode <= 122) {
  2195. return String.fromCodePoint(0x1D68A + charCode - 97);
  2196. }
  2197. if (charCode >= 48 && charCode <= 57) {
  2198. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  2199. }
  2200. return String.fromCharCode(charCode);
  2201. },
  2202.  
  2203. scriptBold : function(charCode) {
  2204. if (charCode >= 65 && charCode <= 90) {
  2205. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  2206. }
  2207. if (charCode >= 97 && charCode <= 122) {
  2208. return String.fromCodePoint(0x1D4EA + charCode - 97);
  2209. }
  2210. if (charCode >= 48 && charCode <= 57) {
  2211. return String.fromCodePoint(0x1D7CE + charCode - 48);
  2212. }
  2213. return String.fromCharCode(charCode);
  2214. },
  2215.  
  2216. frakturBold : function(charCode) {
  2217. if (charCode === 121) { return '𝐲'; } // y
  2218. if (charCode >= 65 && charCode <= 90) {
  2219. return String.fromCodePoint(0x1D56C + charCode - 65);
  2220. }
  2221. if (charCode >= 97 && charCode <= 122) {
  2222. return String.fromCodePoint(0x1D586 + charCode - 97);
  2223. }
  2224. if (charCode >= 48 && charCode <= 57) {
  2225. return String.fromCodePoint(0x1D7CE + charCode - 48);
  2226. }
  2227. return String.fromCharCode(charCode);
  2228. },
  2229.  
  2230. serifItalic: function(charCode) {
  2231. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  2232. if (charCode >= 65 && charCode <= 90) {
  2233. return String.fromCodePoint(0x1D434 + charCode - 65);
  2234. }
  2235. if (charCode >= 97 && charCode <= 122) {
  2236. return String.fromCodePoint(0x1D44E + charCode - 97);
  2237. }
  2238. return String.fromCharCode(charCode);
  2239. },
  2240.  
  2241. circled: function(charCode) {
  2242. if (charCode >= 65 && charCode <= 90) {
  2243. return String.fromCodePoint(0x24B6 + charCode - 65);
  2244. }
  2245. if (charCode >= 97 && charCode <= 122) {
  2246. return String.fromCodePoint(0x24D0 + charCode - 97);
  2247. }
  2248. if (charCode >= 49 && charCode <= 57) {
  2249. return String.fromCodePoint(0x2460 + charCode - 49);
  2250. }
  2251. return String.fromCharCode(charCode);
  2252. },
  2253.  
  2254. boxed: function(charCode) {
  2255. if (charCode >= 65 && charCode <= 90) {
  2256. return String.fromCodePoint(0x1F130 + charCode - 65);
  2257. }
  2258. if (charCode >= 97 && charCode <= 122) {
  2259. return String.fromCodePoint(0x1F130 + charCode - 97);
  2260. }
  2261. if (charCode >= 49 && charCode <= 57) {
  2262. return String.fromCodePoint(0x2460 + charCode - 49);
  2263. }
  2264. return String.fromCharCode(charCode);
  2265. }
  2266. },
  2267.  
  2268. /**
  2269. * True if currently a HTML text element is focused
  2270. */
  2271. isWritingText: function() {
  2272. return document.activeElement.type === 'text' || document.activeElement.type === 'password' || document.activeElement.type === 'textarea';
  2273. },
  2274.  
  2275. /**
  2276. * Let the browser download string data as a text file with a given filename.
  2277. */
  2278. download: function (filename, text) {
  2279. var element = document.createElement('a');
  2280. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  2281. element.setAttribute('download', filename);
  2282.  
  2283. element.style.display = 'none';
  2284. document.body.appendChild(element);
  2285.  
  2286. element.click();
  2287.  
  2288. document.body.removeChild(element);
  2289. },
  2290.  
  2291. /**
  2292. * Converts a version string (for example "1.5.7") to an integer (for example 1005007)
  2293. * If no string version is given, the current version of the script will be used.
  2294. */
  2295. getVersionAsInt: function(stringVersion) {
  2296. if (stringVersion === undefined) {
  2297. stringVersion = typeof GM_info !== 'undefined' ? GM_info.script.version : '0';
  2298. }
  2299.  
  2300. var parts = stringVersion.split('.');
  2301. if (parts.length === 1) {
  2302. parts.push('0');
  2303. }
  2304. if (parts.length === 2) {
  2305. parts.push('0');
  2306. }
  2307.  
  2308. return parseInt(parts[0]) * 1000000 + parseInt(parts[1]) * 1000 + parseInt(parts[2]);
  2309. },
  2310.  
  2311. /**
  2312. * Returns a random number between min and max (both inclusive)
  2313. * Source: MDN
  2314. */
  2315. getRandomInt: function (min, max) {
  2316. return Math.round(Math.random() * (max - min) + min);
  2317. },
  2318.  
  2319. /**
  2320. * Use the curser div to display a message at the top of the screen.
  2321. *
  2322. * @param message
  2323. * @param isError
  2324. */
  2325. message: function (message, isError) {
  2326. var curser = document.querySelector('#curser');
  2327.  
  2328. curser.textContent = message;
  2329. curser.style.display = 'block';
  2330. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  2331.  
  2332. window.setTimeout(function () {
  2333. curser.style.display = 'none';
  2334. }, 5000);
  2335. },
  2336.  
  2337. /**
  2338. * Show a sweet alert (modal/popup) with a given title and message.
  2339. */
  2340. swal: function (title, message, html) {
  2341. if (html === undefined) {
  2342. html = true;
  2343. }
  2344. window.swal({
  2345. title: '📢 <span class="miracle-primary-color-font">' + title + '</span>',
  2346. text: message,
  2347. html: html
  2348. });
  2349. },
  2350.  
  2351. /**
  2352. * Returns the URI of my skin or null if not skin has been set.
  2353. * Use this.skinUrl() to get it.
  2354. */
  2355. getSkinUrl: function(sourceSelector) {
  2356. if (sourceSelector === undefined) {
  2357. sourceSelector = '#skinExampleMenu';
  2358. }
  2359. var skinUrlRaw = $(sourceSelector).css('background-image');
  2360.  
  2361. var parts = skinUrlRaw.split('"');
  2362.  
  2363. if (parts.length !== 3) {
  2364. return null;
  2365. } else {
  2366. return parts[1];
  2367. }
  2368. },
  2369.  
  2370. getAccountName: function() {
  2371. return document.querySelector('#dashPanel .username').innerText;
  2372. },
  2373.  
  2374. /**
  2375. * Tries to pick a skin that is identified by its skin ID.
  2376. * Opens the skin menu, chooses the skin, and closes the menu again.
  2377. * The skin must be available for the current player (e.g. because it's a public one).
  2378. */
  2379. useSkin: function(skinId) {
  2380. window.azad(true);
  2381.  
  2382. setTimeout(function () {
  2383. $('#skinExampleMenu').click();
  2384.  
  2385. var checkLoaded = function () {
  2386. var loaded = ($('#skinsFree tr').length > 1);
  2387. if (loaded) {
  2388. window.toggleSkin(skinId);
  2389.  
  2390. setTimeout(function () {
  2391. $('#shopModalDialog button.close').click();
  2392.  
  2393. setTimeout(function () {
  2394. window.setNick(document.getElementById('nick').value);
  2395. }, 200);
  2396. }, 200);
  2397. } else {
  2398. setTimeout(checkLoaded, 300);
  2399. }
  2400. };
  2401. checkLoaded();
  2402. }, 200);
  2403. },
  2404.  
  2405. /**
  2406. * This is an original Agma function but the original is not accessible - so this is a copy.
  2407. */
  2408. warnBeforeMegaShout: function(msg, color) {
  2409. swal({
  2410. title: "Confirm",
  2411. text: 'If you click "Buy", you will purchase the megaphone shout.',
  2412. type: "warning",
  2413. showCancelButton: true,
  2414. confirmButtonColor: "#4CAF50",
  2415. confirmButtonText: "Yes, confirm purchase",
  2416. cancelButtonText: "No, cancel purchase"
  2417. }, function() {
  2418. //Confirm purchase
  2419. //console.log('purchased megaphone');
  2420. purchaseMega(msg,color);
  2421. //window.location.href = linkURL;
  2422. });
  2423. },
  2424.  
  2425. setupPolyfills: function() {
  2426. // Polyfill for old browser so they have String.fromCodePoint()
  2427. if (!String.fromCodePoint) (function(stringFromCharCode) {
  2428. var fromCodePoint = function(_) {
  2429. var codeUnits = [], codeLen = 0, result = "";
  2430. for (var index=0, len = arguments.length; index !== len; ++index) {
  2431. var codePoint = +arguments[index];
  2432. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  2433. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  2434. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  2435. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  2436. throw RangeError("Invalid code point: " + codePoint);
  2437. if (codePoint <= 0xFFFF) { // BMP code point
  2438. codeLen = codeUnits.push(codePoint);
  2439. } else { // Astral code point; split in surrogate halves
  2440. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  2441. codePoint -= 0x10000;
  2442. codeLen = codeUnits.push(
  2443. (codePoint >> 10) + 0xD800, // highSurrogate
  2444. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  2445. );
  2446. }
  2447. if (codeLen >= 0x3fff) {
  2448. result += stringFromCharCode.apply(null, codeUnits);
  2449. codeUnits.length = 0;
  2450. }
  2451. }
  2452. return result + stringFromCharCode.apply(null, codeUnits);
  2453. };
  2454. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  2455. Object.defineProperty(String, "fromCodePoint", {
  2456. "value": fromCodePoint, "configurable": true, "writable": true
  2457. });
  2458. } catch(e) {
  2459. String.fromCodePoint = fromCodePoint;
  2460. }
  2461. }(String.fromCharCode));
  2462. },
  2463. };
  2464.  
  2465. window.miracleScripts.init();
  2466. })();