Miracle Scripts

Best Agma.io script with tons of features

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

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