Miracle Scripts

Best Agma.io script with tons of features

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

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