Miracle Scripts

Best Agma.io script with tons of features

当前为 2020-11-05 提交的版本,查看 最新版本

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