Miracle Scripts

Best Agma.io script with tons of features

当前为 2020-08-15 提交的版本,查看 最新版本

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