Miracle Scripts

Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chat log! Use chat replacements! And many more...

目前为 2020-02-27 提交的版本,查看 最新版本

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