Miracle Scripts

Best Agma.io script with tons of features

目前为 2020-11-13 提交的版本。查看 最新版本

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