Miracle Scripts For cellcraft.io

Best Cellcraft.io Script!

当前为 2020-12-06 提交的版本,查看 最新版本

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