Miracle Scripts

Best Agma.io script with tons of features

目前为 2020-06-19 提交的版本,查看 最新版本

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