Miracle Scripts

Best Agma.io script with tons of features

目前為 2020-10-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 5.0.1
  5. // @description Best Agma.io script with tons of features
  6. // @author Arimas
  7. // @license MIT
  8. // @icon https://abload.de/img/mh3k8o.png
  9. // @match *://agma.io/
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.miracleScripts = {
  17.  
  18. // News 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.1')) {
  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. // We need to have a delay, because the menu is not loaded right away
  573. setTimeout(function () {
  574. var $playButton = $('#playBtn');
  575. var $specateButton = $('#spectateBtn');
  576.  
  577. $playButton.get(0).style.width = '40%';
  578. $specateButton.get(0).style.width = '40%';
  579.  
  580. var $settingsButton = $('<button class="playgame2" style="width: 44px; margin-left: 3px; text-align: center" title="Miracle Scripts Settings">📜</button>');
  581. $settingsButton.insertAfter($specateButton);
  582.  
  583. var changeKey = function (event) {
  584. var name = this.name.substr(4);
  585. $(this).val(self.keyboardMap[event.keyCode]);
  586. self.settings.bindings[name] = event.keyCode;
  587. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  588. };
  589.  
  590. var deleteKey = function () {
  591. var action = $(this).attr('data-action');
  592. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  593. self.settings.bindings[action] = null;
  594. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  595. };
  596.  
  597. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  598. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  599. // focus again (delayed) and go to the end of the text where the linebreak is.
  600. // We can improve this later on...
  601. var addReturn = function (event) {
  602. if (event.keyCode === 13) {
  603. var textarea = this;
  604. $(textarea).text($(this).text() + '\n').focus();
  605. setTimeout(function () {
  606. $(textarea).focus();
  607. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  608. }, 1);
  609. }
  610. };
  611. var changeReplacements = function () {
  612. self.settings.replacements = $(this).val();
  613. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  614. };
  615. var changePrimaryColor = function () {
  616. self.settings.primaryColor = $(this).val();
  617. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  618. applyPrimaryColor();
  619. };
  620. var changeTargetLanguage = function () {
  621. self.settings.targetLanguage = $(this).val();
  622. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  623. };
  624. var changeClock = function() {
  625. self.settings.showClock = $(this).is(':checked');
  626. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  627. };
  628. var changeKeyboardLayout = function() {
  629. self.settings.showKeyboardLayout = $(this).is(':checked');
  630. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  631. };
  632.  
  633. 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>');
  634. $modal.append('<h1>Miracle Scripts Settings</h1>');
  635.  
  636. if (GM_info) {
  637. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  638. }
  639.  
  640. var $firstRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  641. var $secRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  642. var $thirdRow = $('<td style="vertical-align: top; padding-right: 19px;">');
  643.  
  644.  
  645. var $element = $('<input name="key_ultraSplit" value="' + self.keyboardMap[self.settings.bindings.ultraSplit] + '"/>').keyup(changeKey);
  646. $firstRow.append('<br><br>Ultra-Split-Key:<br>', $element);
  647. $element = $('<a href="#" data-action="ultraSplit" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  648. $firstRow.append($element);
  649.  
  650. $element = $('<input name="key_animation" value="' + self.keyboardMap[self.settings.bindings.animation] + '"/>').keyup(changeKey);
  651. $firstRow.append('<br><br>Animation-Key:<br>', $element);
  652. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  653. $firstRow.append($element);
  654.  
  655. $element = $('<input name="key_paste" value="' + self.keyboardMap[self.settings.bindings.paste] + '"/>').keyup(changeKey);
  656. $firstRow.append('<br><br>Paste-Key:<br>', $element);
  657. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  658. $firstRow.append($element);
  659.  
  660. $element = $('<input name="key_dance" value="' + self.keyboardMap[self.settings.bindings.dance] + '"/>').keyup(changeKey);
  661. $firstRow.append('<br><br>Dance-Key:<br>', $element);
  662. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  663. $firstRow.append($element);
  664.  
  665. $element = $('<input name="key_halt" value="' + self.keyboardMap[self.settings.bindings.halt] + '"/>').keyup(changeKey);
  666. $firstRow.append('<br><br>Halt-Key:<br>', $element);
  667. $element = $('<a href="#" data-action="halt" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  668. $firstRow.append($element);
  669.  
  670. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[self.settings.bindings.chatLog] + '"/>').keyup(changeKey);
  671. $firstRow.append('<br><br>Chat-Log-Key:<br>', $element);
  672. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  673. $firstRow.append($element);
  674.  
  675.  
  676. $element = $('<input name="key_skin1" value="' + self.keyboardMap[self.settings.bindings.skin1] + '"/>').keyup(changeKey);
  677. $secRow.append('<br><br>Use-First-Skin-Key:<br>', $element);
  678. $element = $('<a href="#" data-action="skin1" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  679. $secRow.append($element);
  680.  
  681. $element = $('<input name="key_skin2" value="' + self.keyboardMap[self.settings.bindings.skin2] + '"/>').keyup(changeKey);
  682. $secRow.append('<br><br>Use-Second-Skin-Key:<br>', $element);
  683. $element = $('<a href="#" data-action="skin2" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  684. $secRow.append($element);
  685.  
  686. $element = $('<input name="key_skin3" value="' + self.keyboardMap[self.settings.bindings.skin3] + '"/>').keyup(changeKey);
  687. $secRow.append('<br><br>Use-Third-Skin-Key:<br>', $element);
  688. $element = $('<a href="#" data-action="skin3" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  689. $secRow.append($element);
  690.  
  691. $element = $('<input name="key_skin4" value="' + self.keyboardMap[self.settings.bindings.skin4] + '"/>').keyup(changeKey);
  692. $secRow.append('<br><br>Use-Fourth-Skin-Key:<br>', $element);
  693. $element = $('<a href="#" data-action="skin4" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  694. $secRow.append($element);
  695.  
  696. $element = $('<input name="key_skin5" value="' + self.keyboardMap[self.settings.bindings.skin5] + '"/>').keyup(changeKey);
  697. $secRow.append('<br><br>Use-Fifth-Skin-Key:<br>', $element);
  698. $element = $('<a href="#" data-action="skin5" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  699. $secRow.append($element);
  700.  
  701.  
  702. $element = $('<input name="key_skin6" value="' + self.keyboardMap[self.settings.bindings.skin6] + '"/>').keyup(changeKey);
  703. $thirdRow.append('<br><br>Use-Sixth-Skin-Key:<br>', $element);
  704. $element = $('<a href="#" data-action="skin6" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  705. $thirdRow.append($element);
  706.  
  707. $element = $('<input name="key_skin7" value="' + self.keyboardMap[self.settings.bindings.skin7] + '"/>').keyup(changeKey);
  708. $thirdRow.append('<br><br>Use-Seventh-Skin-Key:<br>', $element);
  709. $element = $('<a href="#" data-action="skin7" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  710. $thirdRow.append($element);
  711.  
  712. $element = $('<input name="key_skin8" value="' + self.keyboardMap[self.settings.bindings.skin8] + '"/>').keyup(changeKey);
  713. $thirdRow.append('<br><br>Use-Eighth-Skin-Key:<br>', $element);
  714. $element = $('<a href="#" data-action="skin8" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  715. $thirdRow.append($element);
  716.  
  717. $element = $('<input name="key_skin9" value="' + self.keyboardMap[self.settings.bindings.skin9] + '"/>').keyup(changeKey);
  718. $thirdRow.append('<br><br>Use-Ninth-Skin-Key:<br>', $element);
  719. $element = $('<a href="#" data-action="skin9" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  720. $thirdRow.append($element);
  721.  
  722. $element = $('<input name="key_wearables" value="' + self.keyboardMap[self.settings.bindings.wearables] + '"/>').keyup(changeKey);
  723. $thirdRow.append('<br><br>Toggle-Wearables-Key:<br>', $element);
  724. $element = $('<a href="#" data-action="wearables" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✕</a>').click(deleteKey);
  725. $thirdRow.append($element);
  726.  
  727.  
  728.  
  729. var $table = $('<table>').append($('<tbody>').append($('<tr>').append($firstRow).append($secRow).append($thirdRow)));
  730. $modal.append($table)
  731.  
  732. $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);
  733. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  734. $element.get(0).value = self.settings.targetLanguage;
  735.  
  736. $element = $('<input type="color" name="favcolor" value="' + self.settings.primaryColor + '"/>').change(changePrimaryColor);
  737. $modal.append('<br><br>User interface color:<br>', $element);
  738.  
  739. $element = $('<input type="checkbox" name="checkBox" value="1" ' + (self.settings.showClock ? 'checked' : '') + '/>').change(changeClock);
  740. $modal.append('<br><br>Show clock:<br>', $element);
  741.  
  742. $element = $('<input type="checkbox" name="checkBox" value="1" ' + (self.settings.showKeyboardLayout ? 'checked' : '') + '/>').change(changeKeyboardLayout);
  743. $modal.append('<br><br>Show Keyboard Layout (reload website to update):<br>', $element);
  744.  
  745. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(self.settings.replacements).keydown(addReturn).keyup(changeReplacements);
  746. $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>');
  747.  
  748. $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 () {
  749. $modal.hide();
  750. }));
  751. $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 () {
  752. self.download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  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">Import settings</a>').click(function () {
  755. var stringifiedSettings = window.prompt('Paste the settings here');
  756. if (stringifiedSettings !== null) {
  757. loadSettings(stringifiedSettings);
  758. localStorage.setItem('miracleScripts', stringifiedSettings);
  759. $modal.hide();
  760. self.message('Settings loaded! Reload Agma to refresh. 😄');
  761. }
  762. }));
  763. //$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>'));
  764. $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 () {
  765. $modal.hide();
  766. self.$helpModal.show();
  767. }));
  768.  
  769. $('body').append($modal);
  770.  
  771. $settingsButton.click(function (event) {
  772. $modal.show();
  773.  
  774. event.preventDefault();
  775. });
  776.  
  777. window.addEventListener('miracleCommand', function(commandEvent) {
  778. if (commandEvent.command === '/miraclesettings' || commandEvent.command === '/miracleconfig') {
  779. $modal.show();
  780. $('#chtbox').val('');
  781. }
  782. });
  783. }, 500);
  784. },
  785.  
  786. /**
  787. * This overwrites the original drawImage function. This allows us to get all the drawImage() calls,
  788. * with coordinates of the images, so we can get the position of things on the map, for instance of cells.
  789. */
  790. drawImage: function (image, sourceX, sourceY, sourceWidth, sourceHeight, targetX, targetY, targetWidth, targetHeight) {
  791. var self = window.miracleScripts;
  792. var unifiedSkinUrl = image.src ? image.src.replace('_lo.', '.') : '';
  793. var pos = unifiedSkinUrl.indexOf('?');
  794. if (pos > -1) {
  795. unifiedSkinUrl = unifiedSkinUrl.substring(0, pos);
  796. }
  797.  
  798. // 'https://agma.io/skins/5642.png'
  799. if (unifiedSkinUrl === 'https://agma.io/skins/4889.png') {
  800. if (self.skinReplacementImg === undefined) {
  801. self.skinReplacementImg = document.createElement('img');
  802. self.skinReplacementImg.src = 'https://i.imgur.com/xOC7bqC.png';
  803. } else {
  804. arguments[0] = self.skinReplacementImg;
  805. var x = 123;
  806. }
  807. }
  808.  
  809. return self.originalDrawImage.apply(this, arguments);
  810. },
  811.  
  812. moveRespawnBtn: function() {
  813. $('#advBox > div:last-child').css('position', 'absolute');
  814. $('#advBox > div:last-child').css('left', '48%');
  815. $('#advBox > div:last-child').css('marginTop', '5px');
  816. $('#advBox > div:nth-child(2)').css('marginLeft', '10%');
  817. },
  818.  
  819. players: function() {
  820. var self = this;
  821.  
  822. $('body').append('<style>#friendList .name { text-decoration: underline; cursor: pointer; }</style>');
  823.  
  824. $('#phpFriendlist').click(function(event) {
  825. if (event.target.classList.contains('name')) { // TODO check: what happens if player is online?
  826. insertPMText($(event.target).text());
  827. }
  828. });
  829.  
  830. $('#btnFriends').click(function() {
  831. var updater = function() {
  832. if ($('#friendDialogMessage').length > 0) {
  833. window.setTimeout(updater, 200);
  834. return;
  835. }
  836.  
  837. $('#phpFriendlist span.name, #requestList span.name').each(function() {
  838. var $nameElement = $(this);
  839. var name = $nameElement.text();
  840. self.settings.players.forEach(function(player) {
  841. if (player.name === name && player.alias) {
  842. $nameElement.attr('title', 'Accountname: ' + name);
  843. $nameElement.css('fontStyle', 'italic');
  844. $nameElement.text(player.alias);
  845. }
  846. });
  847. });
  848. };
  849. window.setTimeout(updater, 200);
  850. });
  851.  
  852. $('#contextUserProfile').click(function() {
  853. $('#miracle-player-settings').remove();
  854.  
  855. window.setTimeout(function() {
  856. if ($('.sweet-alert .sa-error').css('display') === 'block') {
  857. return; // No (public) profile available
  858. }
  859.  
  860. var player = null;
  861. var accountName = $('.sweet-alert h2 span:first()').text();
  862.  
  863. self.settings.players.some(function(candidate) {
  864. if (candidate.name === accountName) {
  865. player = candidate;
  866. return true;
  867. }
  868. });
  869.  
  870. var $editArea = $('<div id="miracle-player-settings">');
  871. var $aliasField = $('<input type="text" maxlength="30" placeholder="Alias" title="Alias" style="display: block; color: #333">').blur(function() {
  872. var alias = $(this).val();
  873. if (player) {
  874. player.alias = alias;
  875. } else {
  876. player = {name: accountName, alias: alias};
  877. self.settings.players.push(player);
  878. }
  879. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  880. });
  881. if (player) {
  882. $aliasField.val(player.alias);
  883. }
  884. $editArea.append($aliasField);
  885. var $noteField = $('<textarea maxlength="250" placeholder="Notes" title="Notes" rows="4" style="width: 100%; padding: 10px; color: #333"></textarea>').blur(function() {
  886. var note = $(this).val();
  887. if (player) {
  888. player.note = note;
  889. } else {
  890. player = {name: accountName, note: note};
  891. self.settings.players.push(player);
  892. }
  893. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  894. });
  895. if (player) {
  896. $noteField.val(player.note);
  897. }
  898. $editArea.append($noteField);
  899.  
  900. $editArea.insertBefore('.sweet-alert .sa-button-container');
  901.  
  902. if ($('.sweet-overlay').attr('data-listening') != 1) {
  903. $('.sweet-overlay').attr('data-listening', 1);
  904.  
  905. $('.sweet-overlay').click(function() {
  906. console.log('sweet bg clicked');
  907. $('#miracle-player-settings').remove();
  908. });
  909. $('.sweet-alert .sa-button-container button').click(function() {
  910. console.log('sweet btn clicked');
  911. $('#miracle-player-settings').remove();
  912. });
  913. }
  914. }, 300);
  915. });
  916. },
  917.  
  918. auth: function() {
  919. var self = this;
  920.  
  921. var value = localStorage.getItem('330145eb94127d7d99dd28af3ee8599d');
  922.  
  923. if (value) {
  924. throw 'Exception: Authentication failed. Code: 1000001';
  925. }
  926.  
  927. var check = function () {
  928. var accountName = self.getAccountName();
  929. if (self.banned.indexOf(accountName) > -1) {
  930. console.log('Exception: Authentication failed. Code: 1000001');
  931. localStorage.setItem('330145eb94127d7d99dd28af3ee8599d', '90f62eda082944015b3c794c65b7c0f0');
  932. window.location.reload();
  933. return;
  934. };
  935. }
  936.  
  937. setInterval(check, 10000);
  938. },
  939.  
  940. animation: function () {
  941. var self = this;
  942.  
  943. var chatAnimate = function () {
  944. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  945. $('#chtbox').val('');
  946. }
  947.  
  948. // All available commands and combinations
  949. var items = ['wacky',
  950. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin',
  951. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip',
  952. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake',
  953. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump',
  954. ];
  955.  
  956. // Super-combinations!!
  957. if (self.getRandomInt(1, 3) === 1) {
  958. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  959. }
  960.  
  961. // Choose randomly an item of the items array
  962. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  963. var item = items[Math.floor(Math.random() * items.length)];
  964.  
  965. // Attempt to avoid triggering spam protection - probably useless :-/
  966. item += String.fromCharCode(8203).repeat(self.getRandomInt(1, 5));
  967.  
  968. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  969. $('#chtbox').val($('#chtbox').val() + item).focus();
  970.  
  971. // Stop the event so that the pressed key won't be written into the chat box!
  972. event.preventDefault();
  973. };
  974.  
  975. window.addEventListener('keydown', function (event) {
  976. // Do nothing if a menu is open
  977. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  978. return;
  979. }
  980.  
  981. if (event.keyCode == self.settings.bindings.animation) {
  982. chatAnimate();
  983. }
  984. });
  985. },
  986.  
  987. paste: function () {
  988. var self = this;
  989. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  990. 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' +
  991. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  992.  
  993. var emojis = this.emojis.split(' ');
  994. var emojiCode = '';
  995.  
  996. emojis.forEach(function (emoji) {
  997. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  998. });
  999.  
  1000. var addEmoji = function () {
  1001. setTimeout(function () {
  1002. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  1003.  
  1004. // Add text into the chatbox and focus it
  1005. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  1006. }, 200);
  1007.  
  1008. $modal.hide();
  1009. };
  1010.  
  1011. 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>');
  1012. $modal.append('<style>' + css + '</style>');
  1013. $modal.append('<h1>Insert text or emoji</h1>');
  1014. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  1015. $modal.append('<br><br>Insert:<br>', $pasteInput);
  1016. $modal.html($modal.html() + '<br><br>' + emojiCode);
  1017. $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));
  1018. $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 () {
  1019. $modal.hide();
  1020. }));
  1021.  
  1022. $modal.find('input[name=paste]').click(function () {
  1023. var text = window.prompt('Please paste your text here!');
  1024.  
  1025. if (text !== null) {
  1026. var $pasteInput = $modal.find('input[name=paste]');
  1027.  
  1028. // Add text into the paste input
  1029. $pasteInput.val($pasteInput.val() + text);
  1030. }
  1031. });
  1032.  
  1033. $modal.click(function (event) {
  1034. if (event.target.classList.contains('miracle-emoji')) {
  1035. var $target = $(this).find('input[name=paste]');
  1036. $target.val($target.val() + $(event.target).text());
  1037.  
  1038. event.preventDefault();
  1039. }
  1040. });
  1041.  
  1042. $modal.dblclick(function (event) {
  1043. if (event.target.classList.contains('miracle-emoji')) {
  1044. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  1045. $(this).hide();
  1046.  
  1047. event.preventDefault();
  1048. }
  1049. });
  1050.  
  1051. $('body').append($modal);
  1052.  
  1053. window.addEventListener('keydown', function (event) {
  1054. // Do nothing if a menu is open
  1055. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1056. return;
  1057. }
  1058.  
  1059. if (event.keyCode == self.settings.bindings.paste) {
  1060. $modal.find('input[name=paste]').val('');
  1061. $modal.toggle();
  1062. }
  1063. });
  1064.  
  1065. window.addEventListener('miracleCommand', function(commandEvent) {
  1066. if (commandEvent.command === '/paste') {
  1067. $modal.find('input[name=paste]').val('');
  1068. $modal.toggle();
  1069. $('#chtbox').val('');
  1070. }
  1071. });
  1072. },
  1073.  
  1074. replacements: function () {
  1075. var self = this;
  1076.  
  1077. $('#chtbox').keyup(function () {
  1078. var lines = self.settings.replacements.split('\n');
  1079.  
  1080. var text = $('#chtbox').val();
  1081.  
  1082. lines.forEach(function (line) {
  1083. var replacement = line.split('|');
  1084. if (replacement.length === 2) {
  1085. text = text.replace(replacement[0], replacement[1]);
  1086. $('#chtbox').val(text).focus();
  1087. }
  1088. });
  1089. });
  1090. },
  1091.  
  1092. chatLog: function () {
  1093. var self = this;
  1094.  
  1095. // We escape the message before we print them, so no one can inject JS code!
  1096. var htmlEntities = function (str) {
  1097. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  1098. };
  1099.  
  1100. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  1101. var lastChatNickname = null;
  1102. var lastChatNicknameColor = null;
  1103. var chatLogCode = '';
  1104. var chatLog = [];
  1105. CanvasRenderingContext2D.prototype.fillText = function () {
  1106. if (this.canvas.id !== 'leaderboard' && this.canvas.height === 23) {
  1107. var text = arguments[0];
  1108. var xPos = arguments[1]; // Usually 3 for nicknames but bigger when a crown, donator icon etc. are displayed
  1109. var lineSize = this.canvas.width; // ATTENTION: Not sure if that really is the total size (icons + nickname + message)
  1110.  
  1111. // Sometimes also numbers (int) are printed (probably masses on cells) so we filter for strings
  1112. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  1113. // Dirty fix for the missing icon in the initial welcome messages
  1114. if (text == '') {
  1115. text = '📢';
  1116. }
  1117. lastChatNickname = text;
  1118. lastChatNicknameColor = this.fillStyle;
  1119. }
  1120. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  1121. // Unfortunately chat messages will be printed more than just once and I don't know
  1122. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  1123. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  1124. var found = false;
  1125. for (var i = 0; i < chatLog.length; i++) {
  1126. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  1127. found = true;
  1128. break;
  1129. }
  1130. }
  1131.  
  1132. if (!found) {
  1133. var legit = text.indexOf(self.watermark) > -1 ? 'class="legit" title="🛡️ This seems to be a legit Miracle Scripts message"' : '';
  1134. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  1135. chatLogCode += '<div ' + legit + '><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  1136. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  1137. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  1138.  
  1139. var messageEvent = new Event('miracleChatMessage');
  1140. messageEvent.nickname = lastChatNickname;
  1141. messageEvent.nicknameColor = lastChatNicknameColor;
  1142. messageEvent.message = text;
  1143. window.dispatchEvent(messageEvent);
  1144. }
  1145. }
  1146. }
  1147.  
  1148. return originalFillText.apply(this, arguments);
  1149. };
  1150.  
  1151. var performSearch = function (searchElement) {
  1152. var subject = searchElement.value.toLowerCase();
  1153.  
  1154. $('#miracle-complete-chatlog div').each(function () {
  1155. var $entry = $(this);
  1156.  
  1157. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  1158. $entry.hide();
  1159. } else {
  1160. $entry.show();
  1161. }
  1162. });
  1163. };
  1164.  
  1165. 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>');
  1166. $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>');
  1167. $modal.append('<h1>Complete Chat Log</h1><br>');
  1168. $modal.append('<div id="miracle-complete-chatlog"></div>');
  1169. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  1170. performSearch(this);
  1171. }));
  1172. $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 () {
  1173. $modal.hide();
  1174. }));
  1175. $('body').append($modal);
  1176.  
  1177. $('#miracle-complete-chatlog').dblclick(function (event) {
  1178. var $clickTarget;
  1179.  
  1180. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  1181. if (event.target.tagName.toLowerCase() === 'span') {
  1182. $clickTarget = $(event.target).parent();
  1183. } else {
  1184. $clickTarget = $(event.target);
  1185. }
  1186.  
  1187. var message = $clickTarget.find('.message').text();
  1188.  
  1189. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  1190. if (message.substr(0, 2) === ': ') {
  1191. message = message.substr(2);
  1192. }
  1193.  
  1194. window.open('https://www.deepl.com/translator#en/' + self.settings.targetLanguage + '/' + message);
  1195. });
  1196.  
  1197. var showChatlog = function() {
  1198. $('#miracle-complete-chatlog').html(chatLogCode);
  1199. $modal.toggle();
  1200. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  1201. };
  1202.  
  1203. window.addEventListener('keyup', function (event) {
  1204. // Ignore text input field so typing in them is possible
  1205. if (self.isWritingText()) {
  1206. return;
  1207. }
  1208.  
  1209. if (event.keyCode == self.settings.bindings.chatLog) {
  1210. showChatlog();
  1211. }
  1212. });
  1213.  
  1214. window.addEventListener('miracleCommand', function(commandEvent) {
  1215. if (commandEvent.command === '/chatlog') {
  1216. showChatlog();
  1217. $('#chtbox').val('');
  1218. }
  1219. });
  1220. },
  1221.  
  1222. favSkins: function () {
  1223. var self = this;
  1224.  
  1225. // We need to have a delay, because the menu is not loaded right away
  1226. setTimeout(function () {
  1227. var favIconClick = function () {
  1228. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  1229.  
  1230. if (self.settings.favSkins.includes(id)) {
  1231. $(this).addClass('skin-not-fav');
  1232. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  1233. var index = self.settings.favSkins.indexOf(id);
  1234. self.settings.favSkins.splice(index, 1);
  1235. } else {
  1236. $(this).removeClass('skin-not-fav');
  1237. self.settings.favSkins.push(id);
  1238. }
  1239. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  1240. renderFavSkins();
  1241. };
  1242.  
  1243. var renderFavSkins = function () {
  1244. var $skins = null;
  1245.  
  1246. if ($('#fav-skins').length > 0) {
  1247. $skins = $('#fav-skins');
  1248. $skins.html('');
  1249. } else {
  1250. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  1251. $skins.insertAfter('#publicSkinsHeader');
  1252.  
  1253. $('#fav-skins').click(function (event) {
  1254. if (event.target.tagName.toLowerCase() === 'span') {
  1255. favIconClick.apply(event.target);
  1256. }
  1257. });
  1258. }
  1259. self.settings.favSkins.forEach(function (id) {
  1260. $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>');
  1261. });
  1262. $skins.append('<div style="clear: both"></div>');
  1263. };
  1264.  
  1265. var addFavIcons = function () {
  1266. var $skins = $('#publicSkinsPage');
  1267. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  1268.  
  1269. $skins.find('h4').each(function () {
  1270. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  1271. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  1272.  
  1273. $favIcon.click(favIconClick);
  1274.  
  1275. $(this).append($favIcon);
  1276.  
  1277. if (! self.settings.favSkins.includes(id)) {
  1278. $favIcon.addClass('skin-not-fav');
  1279. }
  1280. });
  1281. };
  1282. var initialized = false;
  1283. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  1284. if (!initialized) {
  1285. var checkState = function () {
  1286. if ($('#publicSkinsPage').html() !== '') {
  1287. addFavIcons();
  1288. renderFavSkins();
  1289. } else {
  1290. setTimeout(checkState, 30);
  1291. }
  1292. };
  1293. checkState();
  1294. initialized = true;
  1295. }
  1296. });
  1297. $('#phpSkins').click(function (event) {
  1298. if (event.target.classList.contains('publicskins-nav-btn')) {
  1299. addFavIcons();
  1300. }
  1301. });
  1302.  
  1303. }, 500);
  1304. },
  1305.  
  1306. skinChanger: function() {
  1307. var self = this;
  1308.  
  1309. // When the user changes the skin, display ID of the picked skin
  1310. var originalToggleSkin = window.toggleSkin;
  1311. window.toggleSkin = function () {
  1312. self.message('Picked skin with ID ' + arguments[0]);
  1313.  
  1314. return originalToggleSkin.apply(this, arguments);
  1315. };
  1316.  
  1317. var useSkinFromSlot = function (skinSlot, skinId) {
  1318. var skinUri = null;
  1319.  
  1320. if (skinId) {
  1321. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  1322. skinUri = self.getSkinUrl();
  1323. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1324.  
  1325. self.message('Skin ' + skinId + ' saved in slot ' + skinSlot + ' ✔️');
  1326. }
  1327.  
  1328. skinId = parseInt(skinId);
  1329. self.settings.quickSkins[skinSlot - 1] = skinId;
  1330. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  1331. } else {
  1332. skinId = self.settings.quickSkins[skinSlot - 1];
  1333. if (!skinId) {
  1334. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  1335. $('#chtbox').val('');
  1336. return;
  1337. }
  1338. }
  1339.  
  1340. if (skinUri === null) {
  1341. self.useSkin(skinId);
  1342. }
  1343.  
  1344. $('#chtbox').val('');
  1345. };
  1346.  
  1347. window.addEventListener('miracleCommand', function(commandEvent) {
  1348.  
  1349. if (commandEvent.command === 'skin1' || commandEvent.command === '/skin1') {
  1350. useSkinFromSlot(1, commandEvent.argument1);
  1351. }
  1352. if (commandEvent.command === 'skin2' || commandEvent.command === '/skin2') {
  1353. useSkinFromSlot(2, commandEvent.argument1);
  1354. }
  1355. if (commandEvent.command === 'skin3' || commandEvent.command === '/skin3') {
  1356. useSkinFromSlot(3, commandEvent.argument1);
  1357. }
  1358. if (commandEvent.command === 'skin4' || commandEvent.command === '/skin4') {
  1359. useSkinFromSlot(4, commandEvent.argument1);
  1360. }
  1361. if (commandEvent.command === 'skin5' || commandEvent.command === '/skin5') {
  1362. useSkinFromSlot(5, commandEvent.argument1);
  1363. }
  1364. if (commandEvent.command === 'skin6' || commandEvent.command === '/skin6') {
  1365. useSkinFromSlot(6, commandEvent.argument1);
  1366. }
  1367. if (commandEvent.command === 'skin7' || commandEvent.command === '/skin7') {
  1368. useSkinFromSlot(7, commandEvent.argument1);
  1369. }
  1370. if (commandEvent.command === 'skin8' || commandEvent.command === '/skin8') {
  1371. useSkinFromSlot(8, commandEvent.argument1);
  1372. }
  1373. if (commandEvent.command === 'skin9' || commandEvent.command === '/skin9') {
  1374. useSkinFromSlot(9, commandEvent.argument1);
  1375. }
  1376. if (commandEvent.command === 'skin10' || commandEvent.command === '/skin10') {
  1377. useSkinFromSlot(10, commandEvent.argument1);
  1378. }
  1379. if (commandEvent.command === 'skin11' || commandEvent.command === '/skin11') {
  1380. useSkinFromSlot(11, commandEvent.argument1);
  1381. }
  1382. if (commandEvent.command === 'skin12' || commandEvent.command === '/skin12') {
  1383. useSkinFromSlot(12, commandEvent.argument1);
  1384. }
  1385. if (commandEvent.command === 'skin13' || commandEvent.command === '/skin13') {
  1386. useSkinFromSlot(13, commandEvent.argument1);
  1387. }
  1388. if (commandEvent.command === 'skin14' || commandEvent.command === '/skin14') {
  1389. useSkinFromSlot(14, commandEvent.argument1);
  1390. }
  1391. if (commandEvent.command === 'skin15' || commandEvent.command === '/skin15') {
  1392. useSkinFromSlot(15, commandEvent.argument1);
  1393. }
  1394. if (commandEvent.command === 'skin16' || commandEvent.command === '/skin16') {
  1395. useSkinFromSlot(16, commandEvent.argument1);
  1396. }
  1397. if (commandEvent.command === 'skin17' || commandEvent.command === '/skin17') {
  1398. useSkinFromSlot(17, commandEvent.argument1);
  1399. }
  1400. if (commandEvent.command === 'skin18' || commandEvent.command === '/skin18') {
  1401. useSkinFromSlot(18, commandEvent.argument1);
  1402. }
  1403. if (commandEvent.command === 'skin19' || commandEvent.command === '/skin19') {
  1404. useSkinFromSlot(19, commandEvent.argument1);
  1405. }
  1406. if (commandEvent.command === 'skin20' || commandEvent.command === '/skin20') {
  1407. useSkinFromSlot(20, commandEvent.argument1);
  1408. }
  1409. if (commandEvent.command === 'skin21' || commandEvent.command === '/skin21') {
  1410. self.message('Only 20 skin slots are available ❌', true);
  1411. $('#chtbox').val('').focus();
  1412. }
  1413. });
  1414.  
  1415. window.addEventListener('keyup', function (event) {
  1416. // Ignore text input field so typing in them is possible
  1417. if (self.isWritingText()) {
  1418. return;
  1419. }
  1420.  
  1421. if (event.keyCode == self.settings.bindings.skin1) {
  1422. useSkinFromSlot(1);
  1423. }
  1424. if (event.keyCode == self.settings.bindings.skin2) {
  1425. useSkinFromSlot(2);
  1426. }
  1427. if (event.keyCode == self.settings.bindings.skin3) {
  1428. useSkinFromSlot(3);
  1429. }
  1430. if (event.keyCode == self.settings.bindings.skin4) {
  1431. useSkinFromSlot(4);
  1432. }
  1433. if (event.keyCode == self.settings.bindings.skin5) {
  1434. useSkinFromSlot(5);
  1435. }
  1436. if (event.keyCode == self.settings.bindings.skin6) {
  1437. useSkinFromSlot(6);
  1438. }
  1439. if (event.keyCode == self.settings.bindings.skin7) {
  1440. useSkinFromSlot(7);
  1441. }
  1442. if (event.keyCode == self.settings.bindings.skin8) {
  1443. useSkinFromSlot(8);
  1444. }
  1445. if (event.keyCode == self.settings.bindings.skin9) {
  1446. useSkinFromSlot(9);
  1447. }
  1448. });
  1449. },
  1450.  
  1451. ultraSplit: function() {
  1452. var self = this;
  1453.  
  1454. window.addEventListener('keyup', function () {
  1455. if (event.keyCode == self.settings.bindings.ultraSplit) {
  1456. var tripleSplit = function() {
  1457. window.onkeydown({keyCode: self.hotkeys.T.c});
  1458. window.onkeyup({keyCode: self.hotkeys.T.c});
  1459. }
  1460.  
  1461. tripleSplit();
  1462. window.setTimeout(function() {
  1463. tripleSplit();
  1464. window.setTimeout(function() {
  1465. tripleSplit();
  1466. }, 150);
  1467. }, 150);
  1468. }
  1469. });
  1470. },
  1471.  
  1472. lineSplit: function() {
  1473. var self = this;
  1474.  
  1475. window.addEventListener('miracleCommand', function(commandEvent) {
  1476. if (commandEvent.command === '/linesplit') {
  1477. self.lineSplitAt = Date.now();
  1478. self.message('Linesplit •••••');
  1479.  
  1480. var doSplit = function() {
  1481. if (Date.now() - self.lineSplitAt < 1000) {
  1482. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  1483. var x = window.innerWidth / 2;
  1484. var y = factor * (window.innerHeight / 2);
  1485.  
  1486. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1487.  
  1488. window.requestAnimationFrame(doSplit);
  1489. } else {
  1490. if (Date.now() - self.lineSplitAt < 3000) {
  1491. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  1492. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.Space.c}));
  1493. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.Space.c}));
  1494. self.splitAt = Date.now();
  1495. }
  1496.  
  1497. window.requestAnimationFrame(doSplit);
  1498. }
  1499. }
  1500. };
  1501. doSplit();
  1502. $('#chtbox').val('');
  1503. }
  1504. });
  1505. },
  1506.  
  1507. halt: function() {
  1508. var self = this;
  1509.  
  1510. // Stop halt on respawn
  1511. window.addEventListener('keydown', function (event) {
  1512. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1513. self.onHalt = false;
  1514. }
  1515. });
  1516.  
  1517. var initHalt = function() {
  1518. // Do nothing if a menu is open
  1519. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1520. return;
  1521. }
  1522.  
  1523. self.onHalt = ! self.onHalt;
  1524.  
  1525. if (self.onHalt) {
  1526. self.performHalt.apply(self);
  1527. }
  1528. };
  1529.  
  1530. window.addEventListener('keyup', function () {
  1531. if (event.keyCode == self.settings.bindings.halt) {
  1532. if (self.isWritingText()) {
  1533. return;
  1534. }
  1535. initHalt();
  1536. }
  1537. });
  1538.  
  1539. window.addEventListener('miracleCommand', function(commandEvent) {
  1540. if (commandEvent.command === '/halt') {
  1541. initHalt();
  1542. $('#chtbox').val('');
  1543. }
  1544. });
  1545. },
  1546.  
  1547. performHalt: function () {
  1548. var self = this ? this : window.miracleScripts;
  1549.  
  1550. if (self.haltMoveDirection === undefined) {
  1551. self.haltMoveDirection = 1;
  1552. }
  1553. self.haltMoveDirection = -self.haltMoveDirection;
  1554.  
  1555. var centerX = window.innerWidth / 2;
  1556. var centerY = window.innerHeight / 2;
  1557. var angle = self.getAngle(centerX, centerY, self.mouse.x, self.mouse.y);
  1558. if (self.haltMoveDirection === 1) {
  1559. angle = self.addAngle(angle, 180); // Invert angle
  1560. }
  1561. angle = self.addAngle(angle, 270);
  1562. var distance = 1000000;
  1563. var x = centerX + Math.cos(angle * Math.PI / 180) * distance;
  1564. var y = centerY + Math.sin(angle * Math.PI / 180) * distance;
  1565. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1566.  
  1567. // Stop halt if dead ... to avoid continuing halt after next respawn
  1568. if (document.getElementById('advert').style.display !== 'none') {
  1569. self.onHalt = false;
  1570. }
  1571. if (self.onHalt) {
  1572. window.requestAnimationFrame(self.performHalt);
  1573. }
  1574. },
  1575.  
  1576. dance: function () {
  1577. var self = this;
  1578.  
  1579. // Stop dancing on respawn
  1580. window.addEventListener('keydown', function (event) {
  1581. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1582. self.dancing = false;
  1583. }
  1584. });
  1585.  
  1586. var initDance = function() {
  1587. // Do nothing if a menu is open
  1588. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1589. return;
  1590. }
  1591.  
  1592. self.dancing = ! self.dancing;
  1593.  
  1594. if (self.dancing) {
  1595. self.performDance.apply(self);
  1596. }
  1597. };
  1598.  
  1599. window.addEventListener('keyup', function () {
  1600. if (event.keyCode == self.settings.bindings.dance) {
  1601. initDance();
  1602. }
  1603. });
  1604.  
  1605. window.addEventListener('miracleCommand', function(commandEvent) {
  1606. if (commandEvent.command === '/dance') {
  1607. initDance();
  1608. $('#chtbox').val('');
  1609. }
  1610. });
  1611. },
  1612.  
  1613. performDance: function () {
  1614. var self = this ? this : window.miracleScripts;
  1615.  
  1616. if (self.danceAngle === undefined) {
  1617. self.danceAngle = 0;
  1618. }
  1619.  
  1620. self.danceAngle += 20;
  1621.  
  1622. if (self.danceAngle > 360) {
  1623. self.danceAngle = 0;
  1624. }
  1625.  
  1626. var distance = 1000000;
  1627. var x = window.innerWidth / 2 + Math.sin(self.danceAngle * Math.PI / 180) * distance;
  1628. var y = window.innerHeight / 2 + Math.cos(self.danceAngle * Math.PI / 180) * distance;
  1629. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1630.  
  1631. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  1632. if (document.getElementById('advert').style.display !== 'none') {
  1633. self.dancing = false;
  1634. }
  1635. if (self.dancing) {
  1636. window.requestAnimationFrame(self.performDance);
  1637. }
  1638. },
  1639.  
  1640. waste: function() {
  1641. var self = this;
  1642.  
  1643. window.addEventListener('keydown', function (event) {
  1644. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1645. self.wasting = false;
  1646. }
  1647. });
  1648.  
  1649. window.addEventListener('miracleCommand', function(commandEvent) {
  1650. if (commandEvent.command === '/waste') {
  1651. if (self.wasting) {
  1652. self.wasting = false;
  1653. self.message('Stopped wasting all mass.');
  1654. self.dancing = false;
  1655. } else {
  1656. self.wasting = true;
  1657. self.message('Wasting all mass... 💥');
  1658. if (! self.dancing) {
  1659. self.dancing = true;
  1660. self.performDance.apply(self);
  1661. }
  1662. $('#chtbox').val('spinshakeflip').focus();
  1663. }
  1664.  
  1665. var doWaste = function() {
  1666. // Stop wasting mass if dead ... to avoid continuing wasting after next respawn
  1667. if (document.getElementById('advert').style.display !== 'none') {
  1668. self.wasting = false;
  1669. }
  1670. if (! self.wasting) {
  1671. return;
  1672. }
  1673. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.W.c}));
  1674. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.W.c}));
  1675. window.requestAnimationFrame(doWaste);
  1676. };
  1677. doWaste();
  1678. }
  1679. });
  1680. },
  1681.  
  1682. fpsPing: function () {
  1683. var self = this;
  1684.  
  1685. window.addEventListener('miracleCommand', function(commandEvent) {
  1686. if (commandEvent.command === 'ping' || commandEvent.command === '/ping' || commandEvent.command === '/lag') {
  1687. window.setFPS(1);
  1688. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  1689. if (parseInt(ping) > 0) {
  1690. if (parseInt(ping) >= 0 && parseInt(ping) < 35) { pingRating = 'Perfect! ✔️'; }
  1691. if (parseInt(ping) >= 35 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  1692. if (parseInt(ping) >= 70 && parseInt(ping) < 120) { pingRating = 'Acceptable! ✔️'; }
  1693. if (parseInt(ping) >= 120 && parseInt(ping) < 200) { pingRating = 'Bad! ❌'; }
  1694. if (parseInt(ping) >= 200 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  1695. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  1696. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  1697. } else {
  1698. ping = '∞ (infinite) ';
  1699. }
  1700. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating + self.watermark).focus();
  1701. }
  1702. if (commandEvent.command === 'fps' || commandEvent.command === '/fps') {
  1703. window.setFPS(1);
  1704. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  1705. if (parseInt(fps) > 0) {
  1706. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  1707. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  1708. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  1709. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  1710. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  1711. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  1712. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  1713. } else {
  1714. fpsRating = '';
  1715. }
  1716.  
  1717. $('#chtbox').val('has ' + fps + 'fps. ' + fpsRating + self.watermark).focus();
  1718. }
  1719. });
  1720. },
  1721.  
  1722. timer: function() {
  1723. var self = this;
  1724.  
  1725. var timerStartedAt = null;
  1726. var timerMinutes = null;
  1727. var timeoutId = null;
  1728. var updateId = null;
  1729.  
  1730. // Note: The "settings" item is missing in the local storage until settings have been changed
  1731. var agmaSettings = localStorage.getItem('settings') ? JSON.parse(localStorage.getItem('settings')) : { sDark : false };
  1732. var color = (agmaSettings.sDark) ? '#999' : '#3e3e3e';
  1733. var $timeUi = $('<div style="position: fixed; right: 20px; bottom: 230px; z-index: 998; color: ' + color + '; pointer-events: none"></div>');
  1734. $('body').append($timeUi);
  1735.  
  1736.  
  1737. var updateUi = function () {
  1738.  
  1739. var time = '';
  1740. if (self.settings.showClock) {
  1741. var hours = (new Date).getHours();
  1742. var minutes = (new Date).getMinutes();
  1743. time = (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
  1744. if (timeoutId) {
  1745. time = ' - ' + time;
  1746. }
  1747. }
  1748.  
  1749. var remaining = '';
  1750. if (timeoutId) {
  1751. remaining = Math.ceil(((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60) + 'm';
  1752. }
  1753.  
  1754. if (time || remaining) {
  1755. $timeUi.text('🕒 ' + remaining + time);
  1756. } else {
  1757. $timeUi.text('');
  1758. }
  1759. };
  1760. updateUi();
  1761. updateId = setInterval(updateUi, 2000);
  1762.  
  1763. window.addEventListener('miracleCommand', function(commandEvent) {
  1764. if (commandEvent.command === 'timer' || commandEvent.command === '/timer') {
  1765. var argument1 = commandEvent.argument1;
  1766. var argument2 = commandEvent.argument2;
  1767.  
  1768. if (argument1) {
  1769. timerMinutes = parseInt(argument1);
  1770. if (argument2 === 'h' || argument2 === 'hour' || argument2 === 'hours') {
  1771. timerMinutes *= 60;
  1772. }
  1773. if (timeoutId !== null) {
  1774. clearTimeout(timeoutId);
  1775. }
  1776.  
  1777. if (argument1 === '0' || argument1 === 'reset' || argument1 === 'stop' || argument1 === 'clear' || argument1 === 'remove') {
  1778. self.message('🗑️ Timer removed');
  1779. } else {
  1780. timerStartedAt = Date.now();
  1781. timeoutId = setTimeout(function () {
  1782. timeoutId = null;
  1783. updateUi()
  1784. var message = '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.';
  1785. self.message(message);
  1786. self.swal('Time has expired', '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.');
  1787. }, timerMinutes * 60 * 1000);
  1788. updateUi();
  1789.  
  1790. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  1791. }
  1792. } else {
  1793. if (timeoutId === null) {
  1794. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  1795. } else {
  1796. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1797. self.message('🕒 ' + Math.round(remaining * 10) / 10 + ' minutes remaining.');
  1798. }
  1799. }
  1800. $('#chtbox').val('').focus();
  1801. }
  1802. });
  1803. },
  1804.  
  1805. alive: function() {
  1806. var self = this;
  1807.  
  1808. var element = document.getElementById('playBtn');
  1809. element.addEventListener('click', function() {
  1810. if (! self.isAlive) {
  1811. self.spawnedAt = Date.now();
  1812. self.isAlive = true;
  1813. }
  1814. });
  1815. element = document.querySelector('.bottom-dashboard-box img[title=Respawn]');
  1816. element.addEventListener('click', function() {
  1817. self.spawnedAt = Date.now();
  1818. self.isAlive = true;
  1819. });
  1820. element = document.getElementById('advertContinue');
  1821. element.addEventListener('click', function() {
  1822. self.isAlive = false;
  1823. });
  1824.  
  1825. window.addEventListener('keydown', function (event) {
  1826. if (self.hotkeys && event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1827. self.spawnedAt = Date.now();
  1828. self.isAlive = true;
  1829. }
  1830. });
  1831.  
  1832. window.addEventListener('miracleCommand', function(commandEvent) {
  1833. if (commandEvent.command === '/alive' || commandEvent.command === 'alive') {
  1834. var minutes = parseInt((Date.now() - self.spawnedAt) / 1000 / 60);
  1835. if (minutes < 1) {
  1836. minutes = parseInt((Date.now() - self.spawnedAt) / 1000) + ' Seconds & 0';
  1837. }
  1838. if (minutes > 60) {
  1839. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1840. }
  1841.  
  1842. if (! self.isAlive || document.getElementById('advert').style.display !== 'none') {
  1843. if (isNaN(minutes)) {
  1844. $('#chtbox').val('is not alive ☠️');
  1845. } else {
  1846. $('#chtbox').val('is not alive but spawned ' + minutes + ' Minutes ago' + self.watermark);
  1847. }
  1848. } else {
  1849. $('#chtbox').val('has been alive for ' + minutes + ' Minutes' + self.watermark);
  1850. }
  1851. }
  1852. });
  1853.  
  1854. },
  1855.  
  1856. guessing: function() {
  1857. var self = this;
  1858.  
  1859. var guessItem = null;
  1860. var startedAt = null;
  1861. var timeout = null;
  1862. var roundLength = 60 * 1000;
  1863. var library = [ // LMAO.... go away, no cheating please! 🙄
  1864. ['🌞🌼', 'Sunflower', 1],
  1865. ['🌧️🏹', 'Rainbow', 1],
  1866. ['🌧️📅', 'Rainy day', 3],
  1867. ['❄️👑', 'Ice Queen', 3],
  1868. ['🦶⚽', 'Football', 1],
  1869. ['🌙💡', 'Moonlight', 2],
  1870. ['🌞💡', 'Sunlight', 2],
  1871. ['😱🎥', 'Horror movie', 3],
  1872. ['👨🐺', 'Werewolf', 2],
  1873. ['🐮👦', 'Cowboy', 1],
  1874. ['🌌🚢', 'Spaceship', 2],
  1875. ['🔥👨', 'Fireman', 2],
  1876. ['🔥⚔️', 'Firefighter', 2],
  1877. ['🔵🍓', 'Blueberry', 3],
  1878. ['🔥🐶', 'Hotdog', 2],
  1879. ['📹🎮', 'Video game', 4],
  1880. ['⭕💺', 'Wheelchair', 3],
  1881. ['🌚🚶', 'Moonwalk', 3],
  1882. ['🔒🏠', 'Secret room', 4],
  1883. ['🔴🦠', 'Mothercell', 5],
  1884. ['📺👨', 'YouTuber', 3],
  1885. ['🚶💀', 'Walking Dead', 3],
  1886. ['🔥🚧', 'Fireworks', 4],
  1887. ['🧺⚽', 'Basketball', 2],
  1888. ['🍯🌙', 'Honeymoon', 2],
  1889. ['🤗🚢', 'Friendship', 3],
  1890. ['👪💼', 'Teamwork', 4],
  1891. ['🧀🍔', 'Cheeseburger', 2],
  1892. ['❄️⚽', 'Snowball', 1],
  1893. ['👑👨', 'Gold member', 4],
  1894. ['❄️⚪', 'Snow white', 4],
  1895. ['⛰️💡', 'Highlight', 4],
  1896. ['💀🌍', 'Unwerworld', 4],
  1897. ['🔵☁️', 'Blue sky', 3],
  1898. ['⚡🌧️', 'Thunderstorm', 3],
  1899. ['🔴🔴🔴🔴🔴', 'Line split', 2],
  1900. ];
  1901.  
  1902. window.addEventListener('miracleCommand', function(commandEvent) {
  1903. if (commandEvent.command === '/guess') {
  1904. if (startedAt !== null && Date.now() - startedAt < roundLength) {
  1905. self.message('🚫 Wait a little longer (' + Math.ceil((roundLength - (Date.now() - startedAt)) / 1000) + ' seconds)', true);
  1906. $('#chtbox').val('');
  1907. return;
  1908. }
  1909.  
  1910. guessItem = library[self.getRandomInt(0, library.length - 1)];
  1911.  
  1912. var hint = '';
  1913. if (guessItem[2] !== null) {
  1914. hint = guessItem[1];
  1915. hint = self.fonts['monospace'](hint.charCodeAt(0)) + hint.substr(1);
  1916. for (var i = 1; i < guessItem[2]; i++) {
  1917. var pos = self.getRandomInt(0, hint.length);
  1918. hint = hint.substr(0, pos) +
  1919. self.fonts['monospace'](hint.charCodeAt(pos)) +
  1920. hint.substr(pos + 1);
  1921. }
  1922. hint = hint.replace(/(\w)/gi, '_ ');
  1923. hint = ' → ' + hint;
  1924. }
  1925.  
  1926. $('#chtbox').val('𝘎𝘶𝘦𝘴𝘴 𝘸𝘩𝘢𝘵 𝘵𝘩𝘪𝘴 𝘪𝘴: ' + guessItem[0] + hint);
  1927.  
  1928. startedAt = Date.now();
  1929. timeout = setTimeout(function() {
  1930. self.message('Guessing game ended without a winner. The word was: "' + guessItem[1] + '"');
  1931. self.swal('Miracle Guessing Game', 'Guessing game ended without a winner. The word was: "<span style="color: silver">' + guessItem[1] + '</span>"');
  1932. }, roundLength);
  1933. }
  1934. });
  1935.  
  1936. window.addEventListener('miracleChatMessage', function(messageEvent) {
  1937. if (startedAt !== null && Date.now() - startedAt <= roundLength) {
  1938. if (messageEvent.message.toLowerCase().trim().replace(/\s/g, '') === ':' + guessItem[1].toLowerCase()) {
  1939. $('#chtbox').val('𝘎𝘶𝘦𝘴𝘴𝘪𝘯𝘨 𝘨𝘢𝘮𝘦 𝘸𝘰𝘯 𝘣𝘺 𝘱𝘭𝘢𝘺𝘦𝘳 ' + messageEvent.nickname);
  1940. self.message('Guessing game won by player "' + messageEvent.nickname + '"!');
  1941. self.swal('Miracle Guessing Game', 'Guessing game won by "<span style="color: ' + messageEvent.nicknameColor + '">' + messageEvent.nickname + '</span>"!');
  1942. startedAt = null;
  1943. clearTimeout(timeout);
  1944. }
  1945. }
  1946. });
  1947. },
  1948.  
  1949. nameColor: function() {
  1950. var self = this;
  1951.  
  1952. window.addEventListener('miracleCommand', function(commandEvent) {
  1953. if (commandEvent.command === '/namecolor' || commandEvent.command === '/colorname' || commandEvent.command === '/colorchange') {
  1954. self.message('🚫 Changing the name color is no longer possible as there is a server-side fix', true);
  1955. $('#chtbox').val('');
  1956. }
  1957. });
  1958. },
  1959.  
  1960. wearablesToggle: function() {
  1961. var self = this;
  1962.  
  1963. // Note: Doesn't get updated, so we can only use it to init
  1964. var checked = document.getElementById('cWearables').checked;
  1965.  
  1966. window.addEventListener('keydown', function () {
  1967.  
  1968. if (event.keyCode == self.settings.bindings.wearables) {
  1969. checked = ! checked;
  1970. window.setWearables(checked);
  1971. }
  1972. });
  1973. },
  1974.  
  1975. keyboardLayout: function() {
  1976. if (this.settings.showKeyboardLayout && this.hotkeys) {
  1977. var $element = $('<table id="keyboard-layout" style="position: fixed; right: 10px; top: 345px; border-collapse: separate; border-spacing: 10px 0; text-align: right">' +
  1978. '<tr><td>Split: </td><td>&nbsp;&nbsp;' + this.hotkeys.Space.d + '</td></tr>' +
  1979. '<tr><td>Double Split: </td><td>' + this.hotkeys.D.d + '</td></tr>' +
  1980. '<tr><td>Triple Split: </td><td>' + this.hotkeys.T.d + '</td></tr>' +
  1981. '<tr><td>Macro Split: </td><td>' + this.hotkeys.Z.d + '</td></tr>' +
  1982. '<tr><td>Ultra Split: </td><td>' + this.keyboardMap[this.settings.bindings.ultraSplit] + '</td></tr>' +
  1983. '<tr><td>Feed: </td><td>' + this.hotkeys.W360.d + '</td></tr>' +
  1984. '<tr><td>Respawn: </td><td>' + this.hotkeys.M.d + '</td></tr>' +
  1985. '<tr><td>Recombine: </td><td>' + this.hotkeys.E.d + '</td></tr>' +
  1986. '<tr><td>2x Speed: </td><td>' + this.hotkeys.S.d + '</td></tr>' +
  1987. '<tr><td>Freeze Self: </td><td>' + this.hotkeys.F.d + '</td></tr>' +
  1988. '<tr><td>Invisibility: </td><td>' + this.hotkeys.I.d + '</td></tr>' +
  1989. '<tr><td>Toogle Camera: </td><td>' + this.hotkeys.Q.d + '</td></tr>' +
  1990. '</table>');
  1991.  
  1992.  
  1993. $element.insertAfter($('#leaderboard'));
  1994. }
  1995. },
  1996.  
  1997. nameCopier: function() {
  1998. 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>');
  1999. $copyNameItem.insertAfter('#contextPlayer');
  2000.  
  2001. $copyNameItem.click(function() {
  2002. $('#chtbox').val($('#chtbox').val() + $('#contextPlayerName').text().trim());
  2003. });
  2004. },
  2005.  
  2006. skinApplier: function() {
  2007. var self = this;
  2008.  
  2009. 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>');
  2010. $useWearablesItem.insertAfter('#contextPlayer');
  2011. 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>');
  2012. $useSkinItem.insertAfter('#contextPlayer');
  2013.  
  2014. $useSkinItem.click(function() {
  2015. var skinUrl = self.getSkinUrl('#contextPlayerSkin');
  2016. if (skinUrl === null) {
  2017. self.message('This player does not use a skin or no player selected 🚫', true);
  2018. } else {
  2019. var skinId = parseInt(skinUrl.substr(22)); // Cut off "https://agma.io/skins/"
  2020. self.useSkin(skinId);
  2021. }
  2022. });
  2023.  
  2024. $useWearablesItem.click(function() {
  2025. var extractWearableId = function(style) {
  2026. var pos = style.indexOf('background-image: url("wearables/');
  2027. if (pos === -1) {
  2028. return null;
  2029. }
  2030. return parseInt(style.substr(pos + 33));
  2031. }
  2032.  
  2033. var wearables = [
  2034. extractWearableId($('#contextPlayerWear1').attr('style')),
  2035. extractWearableId($('#contextPlayerWear2').attr('style')),
  2036. extractWearableId($('#contextPlayerWear3').attr('style')),
  2037. extractWearableId($('#contextPlayerWear4').attr('style')),
  2038. extractWearableId($('#contextPlayerWear5').attr('style')),
  2039. ];
  2040.  
  2041. var useWearables = function(wearables) {
  2042. window.azad(true);
  2043.  
  2044. setTimeout(function () {
  2045. $('#skinExampleMenu').click();
  2046.  
  2047.  
  2048. setTimeout(function () {
  2049.  
  2050. $('#wearablesTab a').click()
  2051.  
  2052. setTimeout(function () {
  2053. // First remove all current wearables
  2054. var oldWearables = [
  2055. extractWearableId($('#wearExampleShop1').attr('style')),
  2056. extractWearableId($('#wearExampleShop2').attr('style')),
  2057. extractWearableId($('#wearExampleShop3').attr('style')),
  2058. extractWearableId($('#wearExampleShop4').attr('style')),
  2059. extractWearableId($('#wearExampleShop5').attr('style')),
  2060. ]
  2061. oldWearables.forEach(function(id) {
  2062. //toggleWearable(id, 0, 0, 0, false);
  2063. $('#wearableUseBtn' + id).click();
  2064. });
  2065.  
  2066.  
  2067. wearables.forEach(function(id) {
  2068. $('#wearableUseBtn' + id).click();
  2069. });
  2070.  
  2071. setTimeout(function () {
  2072. $('#shopModalDialog button.close').click();
  2073.  
  2074. setTimeout(function () {
  2075. window.setNick(document.getElementById('nick').value);
  2076. }, 200);
  2077. }, 200);
  2078. }, 1000);
  2079.  
  2080. }, 200);
  2081. }, 200);
  2082. }
  2083. useWearables(wearables);
  2084. });
  2085. },
  2086.  
  2087. help: function() {
  2088. $('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>');
  2089. 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>');
  2090. $modal.append('<h1>Miracle Scripts Help</h1>');
  2091.  
  2092. 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>' +
  2093. '<tr><th style="padding-right: 70px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  2094. '<tr><td><code>/help</code></td><td>Show this help</td></tr>' +
  2095. '<tr><td><code>/miracle</code></td><td>Show version info</td></tr>' +
  2096. '<tr><td><code>/miraclesettings</code></td><td>Show the miracle settings page</td></tr>' +
  2097. '<tr><td><code>/players</code></td><td>Display how many players are online</td></tr>' +
  2098. '<tr><td><code>/skin&lt;n></code></td><td>Change to skin &lt;n> (1-20)</td></tr>' +
  2099. '<tr><td><code>/skin&lt;n> this</code></td><td>Store current skin as skin <n></td></tr>' +
  2100. '<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>' +
  2101. '<tr><td><code>/skinid</code></td><td>Send a chat message with your skin ID</td></tr>' +
  2102. '<tr><td><code>/useskin &lt;id></code></td><td>Use skin with the given ID</td></tr>' +
  2103. '<tr><td><code>/chatlog</code></td><td>Show the extended chat log</td></tr>' +
  2104. '<tr><td><code>/shout &lt;text></code></td><td>Purchase a megaphone shout for 20000 coins</td></tr>' +
  2105. '<tr><td><code>/paste</code></td><td>Show the emojis and text paste page</td></tr>' +
  2106. '<tr><td><code>/timer &lt;n></code></td><td>Set timer for &lt;n> minutes</td></tr>' +
  2107. '<tr><td><code>/timer &lt;n> h</code></td><td>Set timer for &lt;n> hours</td></tr>' +
  2108. '<tr><td><code>/timer stop</code></td><td>Stop the timer</td></tr>' +
  2109. '<tr><td><code>/xp</code></td><td>Send a chat message with your level and next level\'s progress</td></tr>' +
  2110. '<tr><td><code>/powerups</code></td><td>Send a chat message with your powerup amounts</td></tr>' +
  2111. '<tr><td><code>/fps</code></td><td>Send a chat message with current fps</td></tr>' +
  2112. '<tr><td><code>/ping</code></td><td>Send a chat message with current ping</td></tr>' +
  2113. '<tr><td><code>/online</code></td><td>For how long are you online in the current session?</td></tr>' +
  2114. '<tr><td><code>/alive</code></td><td>For how long are you alive?</td></tr>' +
  2115. '<tr><td><code>/solo</code></td><td>Show the solo server message</td></tr>' +
  2116. '<tr><td><code>/dice</code></td><td>Roll a die with 6 sides</td></tr>' +
  2117. '<tr><td><code>/dice &lt;n></code></td><td>Roll a die with &lt;n> sides</td></tr>' +
  2118. '<tr><td><code>/guess</code></td><td>Start a guessing chat game</td></tr>' +
  2119. '<tr><td><code>/linesplit</code></td><td>Let your cell make a linesplit</td></tr>' +
  2120. '<tr><td><code>/waste</code></td><td>Waste all your mass</td></tr>' +
  2121. '<tr><td><code>/dance</code></td><td>Let your cell dance</td></tr>' +
  2122. '<tr><td><code>/halt</code></td><td>Let your cells stop moving</td></tr>' +
  2123.  
  2124.  
  2125. '</table></td><td style="vertical-align: top"><table>' +
  2126. '<tr><th style="padding-right: 70px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  2127. '<tr><td><code>/coins</code></td><td>Send a chat message with your coins</td></tr>' +
  2128. '<tr><td><code>/level</code></td><td>Send a chat message with your account level</td></tr>' +
  2129. '<tr><td><code>/rank</code></td><td>Send a chat message with your account rank</td></tr>' +
  2130. '<tr><td><code>/hours</code></td><td>Send a chat message with the time you played</td></tr>' +
  2131. '<tr><td><code>/shake</code></td><td>Let your cells shake!</td></tr>' +
  2132. '<tr><td><code>/flip</code></td><td>Let your cells flip!</td></tr>' +
  2133. '<tr><td><code>/spin</code></td><td>Let your cells spin!</td></tr>' +
  2134. '<tr><td><code>/jump</code></td><td>Let your cells jump!</td></tr>' +
  2135. '<tr><td><code>/wacky</code></td><td>Your cells will be laughing faces!</td></tr>' +
  2136. '<tr><td><code>/stats</code></td><td>Show your battle royale stats</td></tr>' +
  2137. '<tr><td><code>/party &lt;message></code></td><td>Write a message to your party</td></tr>' +
  2138. '<tr><td><code>/pm &lt;account></code></td><td>Write a message to a given account</td></tr>' +
  2139. '</table></td></tr></table>';
  2140.  
  2141. $modal.append(helpText);
  2142.  
  2143. $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 () {
  2144. $modal.hide();
  2145. }));
  2146.  
  2147. $('body').append($modal);
  2148.  
  2149. this.$helpModal = $modal;
  2150.  
  2151. $('#miracle-help-table table tr').click(function() {
  2152. var cmd = $(this).find('code').text();
  2153. $('#chtbox').val($('#chtbox').val() + cmd).focus();
  2154. $modal.hide();
  2155. });
  2156.  
  2157. 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() {
  2158. $modal.show();
  2159. });
  2160. $helpButton.insertAfter('#emojiBtn');
  2161. $('body').append('<style>@media (max-width: 1288px) { #inventory1 { left: 675px !important; } }</style>'); // Ensure help icon does not overlap pwoerups
  2162.  
  2163. window.addEventListener('miracleCommand', function(commandEvent) {
  2164. if (commandEvent.command === '/help' || commandEvent.command === '/miraclehelp') {
  2165. $('#chtbox').val('').focus();
  2166. $modal.show();
  2167. }
  2168. });
  2169. },
  2170.  
  2171. commands: function () {
  2172. var self = this;
  2173. var minutes, skinId;
  2174.  
  2175. var sessionStartedAt = Date.now();
  2176.  
  2177. $('#chtbox').keydown(function (event) {
  2178. if (event.keyCode === 13) {
  2179. var message = $('#chtbox').val();
  2180. var command = message.split(' ')[0];
  2181. var argument1 = message.split(' ')[1];
  2182. var argument2 = message.split(' ')[2];
  2183.  
  2184. if (message === 'time' || command === '/time' || command === '/localtime') {
  2185. var now = new Date();
  2186. $('#chtbox').val('Local time: ' + now.toLocaleString() + self.watermark).focus();
  2187. }
  2188.  
  2189. if (message === 'minutes' || command === '/minutes' || message === 'online' || command === '/online' || command === '/session') {
  2190. if (message === 'minutes' || command === '/minutes') {
  2191. self.message('⛔ The /minutes command is deprecated, please use /online instead.', true);
  2192. }
  2193.  
  2194. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  2195. if (minutes < 1) {
  2196. minutes = parseInt((Date.now() - sessionStartedAt) / 1000) + ' Seconds & 0';
  2197. }
  2198. if (minutes > 60) {
  2199. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  2200. }
  2201. $('#chtbox').val('is online for: ' + minutes + ' Minutes in the current session' + self.watermark).focus();
  2202. }
  2203.  
  2204. if (command === '/solo' || command === '/noteam') {
  2205. $('#chtbox').val(':warning: SOLO SERVER :warning: No teaming!! No hay equipo!! Pas d\'équipe!! Kein Teaming!! لا فريق').focus();
  2206. }
  2207.  
  2208. if (command === '/miracle') {
  2209. var miracleInfo = 'uses 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴';
  2210.  
  2211. if (GM_info) {
  2212. miracleInfo += ' ' + GM_info.script.version;
  2213. }
  2214.  
  2215. $('#chtbox').val(miracleInfo + '. Install for free from 𝘎𝘳𝘦𝘢𝘴𝘺𝘧𝘰𝘳𝘬.𝘰𝘳𝘨!' + self.watermark).focus();
  2216. }
  2217.  
  2218. if (command === '/skinid' || command === '/sayskin') {
  2219. var skinUri = self.getSkinUrl();
  2220. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  2221. $('#chtbox').val('uses the skin with the ID ' + skinId + self.watermark);
  2222. return;
  2223. }
  2224.  
  2225. if (command === '/useskin') {
  2226. skinId = parseInt(argument1);
  2227. if (! (skinId > 0)) {
  2228. self.message('Invalid skin ID given. Example usage of command: /useskin 123', true);
  2229. } else {
  2230. self.useSkin(skinId);
  2231. }
  2232.  
  2233. $('#chtbox').val('');
  2234. }
  2235.  
  2236. if (command.substr(0, 4) === '/say' || (command === '/party' && argument1.substr(0, 4) === '/say') || (command === '/pm' && argument2.substr(0, 4) === '/say')) {
  2237. self.message('🚫 This feature has been removed since the Agma staff does not allow it', true);
  2238. $('#chtbox').val('');
  2239. }
  2240.  
  2241. if (command === '/dice') {
  2242. var max = (argument1 > 0) ? parseInt(argument1) : 6;
  2243. var number = self.getRandomInt(1, max);
  2244. $('#chtbox').val('rolled a die with ' + max + ' sides. Result: ' + number + self.watermark);
  2245. }
  2246.  
  2247. if (command === '/powerups' || command === '/powers' || command === '/has') {
  2248. var map = {
  2249. invRecombine: 'recombine',
  2250. invSpeed: 'speed',
  2251. invGrowth: 'growth',
  2252. invSpawnVirus: 'virus',
  2253. invSpawnMothercell: 'red virus',
  2254. invSpawnPortal: 'portal',
  2255. invSpawnGoldOre: 'gold block',
  2256. invFreeze: 'freeze',
  2257. inv360Shot: 'push',
  2258. invWall: 'wall',
  2259. invAntiFreeze: 'nofreeze',
  2260. invAntiRecombine: 'anti-rec',
  2261. invFrozenVirus: 'frozen virus',
  2262. }
  2263. var getPowerUps = function(map, shortNames) {
  2264. var ids = Object.keys(map); var amount; var powerups = ''; var powerUpName;
  2265. for (var i = 0; i < ids.length; i++) {
  2266. // Note: If the amount of a powerup is 1, no number will be displayed.
  2267. amount = $('#' + ids[i] + ' p').text() || ($('#' + ids[i]).css('display') === 'none' ? 0 : 1);
  2268. if (amount > 0) {
  2269. if (powerups != '') {
  2270. powerups += ', ';
  2271. }
  2272. powerUpName = map[ids[i]];
  2273. if (shortNames) {
  2274. powerUpName = powerUpName.substr(0, 3);
  2275. }
  2276. powerups += amount + ' ' + powerUpName;
  2277. }
  2278. }
  2279. return powerups;
  2280. }
  2281.  
  2282. var powerups = getPowerUps(map, false);
  2283. if (powerups.length >= 95) {
  2284. powerups = getPowerUps(map, true);
  2285. }
  2286.  
  2287. if (powerups === '') {
  2288. powerups = 'no';
  2289. }
  2290. $('#chtbox').val(self.watermark + 'has ' + powerups);
  2291. }
  2292.  
  2293. if (command === '/xp' || command === '/progress') {
  2294. var xp = parseInt($('.xpBarTop span').text());
  2295. var text = '█'.repeat(xp / 10) + '▒'.repeat(10 - parseInt(xp / 10)) + ' ' + xp + '%';
  2296. $('#chtbox').val('is currently level ' + $('#level2').text() + ' with ' + text + ' of the next level completed' + self.watermark);
  2297. }
  2298.  
  2299. if (command === '/megaphone' || command === '/megashout' || command === '/shout') {
  2300. // Notes: 1-7 = colors. The shout message can have max 130 chars, but chat messages can be only 100(?) chars long so np
  2301. self.warnBeforeMegaShout(message.substr(message.indexOf(' ') + 1), self.getRandomInt(1, 7));
  2302. $('#chtbox').val('');
  2303. }
  2304.  
  2305. if (command === '/players') {
  2306. var gameservers = JSON.parse(localStorage.getItem('gameservers'));
  2307. var players = 0;
  2308. var current = null;
  2309.  
  2310. gameservers.forEach(function(gameserver) {
  2311. players += gameserver.players;
  2312. if (gameserver.isCurrent) {
  2313. current = gameserver.players + '/' + gameserver.maxPlayers;
  2314. }
  2315. });
  2316.  
  2317. $('#chtbox').val('Players online in Agma: ' + players);
  2318.  
  2319. if (current !== null) {
  2320. $('#chtbox').val($('#chtbox').val() + ' - current server: ' + current);
  2321. }
  2322. }
  2323.  
  2324. var commandEvent = new Event('miracleCommand');
  2325. commandEvent.message = message;
  2326. commandEvent.command = command;
  2327. commandEvent.argument1 = argument1;
  2328. commandEvent.argument2 = argument2;
  2329. window.dispatchEvent(commandEvent);
  2330. }
  2331. });
  2332. },
  2333.  
  2334. /**
  2335. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  2336. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  2337. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumerics
  2338. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumeric_Supplement
  2339. */
  2340. fonts: {
  2341. doubleStruck : function(charCode) {
  2342. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  2343. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  2344. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  2345. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  2346. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  2347. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  2348. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  2349. if (charCode >= 65 && charCode <= 90) {
  2350. return String.fromCodePoint(0x1D538 + charCode - 65);
  2351. }
  2352. if (charCode >= 97 && charCode <= 122) {
  2353. return String.fromCodePoint(0x1D552 + charCode - 97);
  2354. }
  2355. if (charCode >= 48 && charCode <= 57) {
  2356. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  2357. }
  2358. return String.fromCharCode(charCode);
  2359. },
  2360.  
  2361. monospace : function(charCode) {
  2362. if (charCode >= 65 && charCode <= 90) {
  2363. return String.fromCodePoint(0x1D670 + charCode - 65);
  2364. }
  2365. if (charCode >= 97 && charCode <= 122) {
  2366. return String.fromCodePoint(0x1D68A + charCode - 97);
  2367. }
  2368. if (charCode >= 48 && charCode <= 57) {
  2369. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  2370. }
  2371. return String.fromCharCode(charCode);
  2372. },
  2373.  
  2374. scriptBold : function(charCode) {
  2375. if (charCode >= 65 && charCode <= 90) {
  2376. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  2377. }
  2378. if (charCode >= 97 && charCode <= 122) {
  2379. return String.fromCodePoint(0x1D4EA + charCode - 97);
  2380. }
  2381. if (charCode >= 48 && charCode <= 57) {
  2382. return String.fromCodePoint(0x1D7CE + charCode - 48);
  2383. }
  2384. return String.fromCharCode(charCode);
  2385. },
  2386.  
  2387. frakturBold : function(charCode) {
  2388. if (charCode === 121) { return '𝐲'; } // y
  2389. if (charCode >= 65 && charCode <= 90) {
  2390. return String.fromCodePoint(0x1D56C + charCode - 65);
  2391. }
  2392. if (charCode >= 97 && charCode <= 122) {
  2393. return String.fromCodePoint(0x1D586 + charCode - 97);
  2394. }
  2395. if (charCode >= 48 && charCode <= 57) {
  2396. return String.fromCodePoint(0x1D7CE + charCode - 48);
  2397. }
  2398. return String.fromCharCode(charCode);
  2399. },
  2400.  
  2401. serifItalic: function(charCode) {
  2402. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  2403. if (charCode >= 65 && charCode <= 90) {
  2404. return String.fromCodePoint(0x1D434 + charCode - 65);
  2405. }
  2406. if (charCode >= 97 && charCode <= 122) {
  2407. return String.fromCodePoint(0x1D44E + charCode - 97);
  2408. }
  2409. return String.fromCharCode(charCode);
  2410. },
  2411.  
  2412. circled: function(charCode) {
  2413. if (charCode >= 65 && charCode <= 90) {
  2414. return String.fromCodePoint(0x24B6 + charCode - 65);
  2415. }
  2416. if (charCode >= 97 && charCode <= 122) {
  2417. return String.fromCodePoint(0x24D0 + charCode - 97);
  2418. }
  2419. if (charCode >= 49 && charCode <= 57) {
  2420. return String.fromCodePoint(0x2460 + charCode - 49);
  2421. }
  2422. return String.fromCharCode(charCode);
  2423. },
  2424.  
  2425. boxed: function(charCode) {
  2426. if (charCode >= 65 && charCode <= 90) {
  2427. return String.fromCodePoint(0x1F130 + charCode - 65);
  2428. }
  2429. if (charCode >= 97 && charCode <= 122) {
  2430. return String.fromCodePoint(0x1F130 + charCode - 97);
  2431. }
  2432. if (charCode >= 49 && charCode <= 57) {
  2433. return String.fromCodePoint(0x2460 + charCode - 49);
  2434. }
  2435. return String.fromCharCode(charCode);
  2436. }
  2437. },
  2438.  
  2439. /**
  2440. * True if currently a HTML text element is focused
  2441. */
  2442. isWritingText: function() {
  2443. return document.activeElement.type === 'text' || document.activeElement.type === 'password' || document.activeElement.type === 'textarea';
  2444. },
  2445.  
  2446. /**
  2447. * Let the browser download string data as a text file with a given filename.
  2448. */
  2449. download: function (filename, text) {
  2450. var element = document.createElement('a');
  2451. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  2452. element.setAttribute('download', filename);
  2453.  
  2454. element.style.display = 'none';
  2455. document.body.appendChild(element);
  2456.  
  2457. element.click();
  2458.  
  2459. document.body.removeChild(element);
  2460. },
  2461.  
  2462. /**
  2463. * Converts a version string (for example "1.5.7") to an integer (for example 1005007)
  2464. * If no string version is given, the current version of the script will be used.
  2465. */
  2466. getVersionAsInt: function(stringVersion) {
  2467. if (stringVersion === undefined) {
  2468. stringVersion = typeof GM_info !== 'undefined' ? GM_info.script.version : '0';
  2469. }
  2470.  
  2471. var parts = stringVersion.split('.');
  2472. if (parts.length === 1) {
  2473. parts.push('0');
  2474. }
  2475. if (parts.length === 2) {
  2476. parts.push('0');
  2477. }
  2478.  
  2479. return parseInt(parts[0]) * 1000000 + parseInt(parts[1]) * 1000 + parseInt(parts[2]);
  2480. },
  2481.  
  2482. /**
  2483. * Returns a random number between min and max (both inclusive)
  2484. * Source: MDN
  2485. */
  2486. getRandomInt: function (min, max) {
  2487. return Math.round(Math.random() * (max - min) + min);
  2488. },
  2489.  
  2490.  
  2491. /**
  2492. * Returns the 360-angle between two points 8coordinates), starting by the first point.
  2493. * 0° means the second point is in the north of the first point.
  2494. * The returned angle will always be >= 0 and < 360.
  2495. */
  2496. getAngle: function(x1, y1, x2, y2) {
  2497. var angle = Math.atan2(y2 - y1, x2 - x1); // range (-PI, PI]
  2498. angle *= 180 / Math.PI; // rads to degs, range (-180, 180]
  2499. angle += 90;
  2500.  
  2501. if (angle < 0) angle = 360 + angle; // range [0, 360)
  2502. if (angle >= 360) angle = 360 - angle; // range [0, 360)
  2503.  
  2504. return angle;
  2505. },
  2506.  
  2507. /**
  2508. * Adds angle2 to angle1 and returns the resulting angle.
  2509. */
  2510. addAngle: function(angle1, angle2) {
  2511. var angle = angle1 + angle2;
  2512.  
  2513. angle %= 360;
  2514. if (angle < 0) angle += 360;
  2515.  
  2516. return angle;
  2517. },
  2518.  
  2519. /**
  2520. * Use the curser div to display a message at the top of the screen.
  2521. *
  2522. * @param message
  2523. * @param isError
  2524. */
  2525. message: function (message, isError) {
  2526. var curser = document.querySelector('#curser');
  2527.  
  2528. curser.textContent = message;
  2529. curser.style.display = 'block';
  2530. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  2531.  
  2532. window.setTimeout(function () {
  2533. curser.style.display = 'none';
  2534. }, 5000);
  2535. },
  2536.  
  2537. /**
  2538. * Show a sweet alert (modal/popup) with a given title and message.
  2539. */
  2540. swal: function (title, message, html) {
  2541. if (html === undefined) {
  2542. html = true;
  2543. }
  2544. window.swal({
  2545. title: '📢 <span class="miracle-primary-color-font">' + title + '</span>',
  2546. text: message,
  2547. html: html
  2548. });
  2549. },
  2550.  
  2551. /**
  2552. * Returns the URI of my skin or null if not skin has been set.
  2553. * Use this.skinUrl() to get it.
  2554. */
  2555. getSkinUrl: function(sourceSelector) {
  2556. if (sourceSelector === undefined) {
  2557. sourceSelector = '#skinExampleMenu';
  2558. }
  2559. var skinUrlRaw = $(sourceSelector).css('background-image');
  2560.  
  2561. var parts = skinUrlRaw.split('"');
  2562.  
  2563. if (parts.length !== 3) {
  2564. return null;
  2565. } else {
  2566. return parts[1];
  2567. }
  2568. },
  2569.  
  2570. getAccountName: function() {
  2571. return document.querySelector('#dashPanel .username').innerText;
  2572. },
  2573.  
  2574. /**
  2575. * Tries to pick a skin that is identified by its skin ID.
  2576. * Opens the skin menu, chooses the skin, and closes the menu again.
  2577. * The skin must be available for the current player (e.g. because it's a public one).
  2578. */
  2579. useSkin: function(skinId) {
  2580. window.azad(true);
  2581.  
  2582. setTimeout(function () {
  2583. $('#skinExampleMenu').click();
  2584.  
  2585. var checkLoaded = function () {
  2586. var loaded = ($('#skinsFree tr').length > 1);
  2587. if (loaded) {
  2588. window.toggleSkin(skinId);
  2589.  
  2590. setTimeout(function () {
  2591. $('#shopModalDialog button.close').click();
  2592.  
  2593. setTimeout(function () {
  2594. window.setNick(document.getElementById('nick').value);
  2595. }, 200);
  2596. }, 200);
  2597. } else {
  2598. setTimeout(checkLoaded, 300);
  2599. }
  2600. };
  2601. checkLoaded();
  2602. }, 200);
  2603. },
  2604.  
  2605. /**
  2606. * This is an original Agma function but the original is not accessible - so this is a copy.
  2607. */
  2608. warnBeforeMegaShout: function(msg, color) {
  2609. swal({
  2610. title: "Confirm",
  2611. text: 'If you click "Buy", you will purchase the megaphone shout.',
  2612. type: "warning",
  2613. showCancelButton: true,
  2614. confirmButtonColor: "#4CAF50",
  2615. confirmButtonText: "Yes, confirm purchase",
  2616. cancelButtonText: "No, cancel purchase"
  2617. }, function() {
  2618. //Confirm purchase
  2619. //console.log('purchased megaphone');
  2620. purchaseMega(msg,color);
  2621. //window.location.href = linkURL;
  2622. });
  2623. },
  2624.  
  2625. setupPolyfills: function() {
  2626. // Polyfill for old browser so they have String.fromCodePoint()
  2627. if (!String.fromCodePoint) (function(stringFromCharCode) {
  2628. var fromCodePoint = function(_) {
  2629. var codeUnits = [], codeLen = 0, result = "";
  2630. for (var index=0, len = arguments.length; index !== len; ++index) {
  2631. var codePoint = +arguments[index];
  2632. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  2633. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  2634. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  2635. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  2636. throw RangeError("Invalid code point: " + codePoint);
  2637. if (codePoint <= 0xFFFF) { // BMP code point
  2638. codeLen = codeUnits.push(codePoint);
  2639. } else { // Astral code point; split in surrogate halves
  2640. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  2641. codePoint -= 0x10000;
  2642. codeLen = codeUnits.push(
  2643. (codePoint >> 10) + 0xD800, // highSurrogate
  2644. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  2645. );
  2646. }
  2647. if (codeLen >= 0x3fff) {
  2648. result += stringFromCharCode.apply(null, codeUnits);
  2649. codeUnits.length = 0;
  2650. }
  2651. }
  2652. return result + stringFromCharCode.apply(null, codeUnits);
  2653. };
  2654. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  2655. Object.defineProperty(String, "fromCodePoint", {
  2656. "value": fromCodePoint, "configurable": true, "writable": true
  2657. });
  2658. } catch(e) {
  2659. String.fromCodePoint = fromCodePoint;
  2660. }
  2661. }(String.fromCharCode));
  2662. },
  2663. };
  2664.  
  2665. window.miracleScripts.init();
  2666. })();