Miracle Scripts

Best Agma.io extension - bookmark skins, use custom chat fonts, enjoy the extended chat log, use chat replacements, and many more...

当前为 2020-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 2.5.9
  5. // @description Best Agma.io extension - bookmark skins, use custom chat fonts, enjoy the extended 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.players();
  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. if (typeof settings.players === 'undefined') {
  370. settings.players = [];
  371. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  372. }
  373. }
  374.  
  375. self.settings = settings;
  376. };
  377. loadSettings(localStorage.getItem('miracleScripts'));
  378.  
  379. if (settings.installedVersion < this.getVersionAsInt()) {
  380. if (settings.installedVersion > 1) { // We do not want to inform new scripts user of past updated
  381. if (settings.installedVersion < this.getVersionAsInt('2.4.3')) {
  382. window.alert('📢 Miracle Scripts Update: \n\n' +
  383. 'As of version 2.4.3 the nickname color change feature has been removed ' +
  384. 'according to an official decision of the Agma team.\n\n' +
  385. 'To avoid trouble for its users Miracle Scripts respects this decision. ' +
  386. 'Therefore Miracle Scripts is a legit extension for Agma and using it is safe.'
  387. );
  388. }
  389. if (settings.installedVersion < this.getVersionAsInt('2.5.6')) {
  390. self.swal(
  391. 'Miracle Scripts Update',
  392. 'You may now use 20 slots for skins (previously: 15). Type <i>/slot16</i> - <i>/slot20</i> in the chat box!');
  393. }
  394. if (settings.installedVersion < this.getVersionAsInt('2.5.8')) {
  395. self.swal(
  396. 'Miracle Scripts Update',
  397. '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".');
  398. }
  399. }
  400.  
  401. settings.installedVersion = this.getVersionAsInt();
  402. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  403. self.settings = settings;
  404. }
  405.  
  406. var applyPrimaryColor = function () {
  407. var primaryColorCss = '.miracle-primary-color-font { color: ' + self.settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + self.settings.primaryColor + ' !important }; ';
  408. $('body').append('<style>' + primaryColorCss + '</style>');
  409. };
  410. applyPrimaryColor();
  411.  
  412. // We need to have a delay, because the menu is not loaded right away
  413. setTimeout(function () {
  414. var $playButton = $('#playBtn');
  415. var $specateButton = $('#spectateBtn');
  416.  
  417. $playButton.get(0).style.width = '40%';
  418. $specateButton.get(0).style.width = '40%';
  419.  
  420. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">📜</button>');
  421. $settingsButton.insertAfter($playButton);
  422.  
  423. var changeKey = function (event) {
  424. var name = this.name.substr(4);
  425. $(this).val(self.keyboardMap[event.keyCode]);
  426. self.settings.bindings[name] = event.keyCode;
  427. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  428. };
  429.  
  430. var deleteKey = function () {
  431. var action = $(this).attr('data-action');
  432. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  433. self.settings.bindings[action] = null;
  434. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  435. };
  436.  
  437. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  438. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  439. // focus again (delayed) and go to the end of the text where the linebreak is.
  440. // We can improve this later on...
  441. var addReturn = function (event) {
  442. if (event.keyCode === 13) {
  443. var textarea = this;
  444. $(textarea).text($(this).text() + '\n').focus();
  445. setTimeout(function () {
  446. $(textarea).focus();
  447. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  448. }, 1);
  449. }
  450. };
  451. var changeReplacements = function () {
  452. self.settings.replacements = $(this).val();
  453. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  454. };
  455. var changePrimaryColor = function () {
  456. self.settings.primaryColor = $(this).val();
  457. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  458. applyPrimaryColor();
  459. };
  460. var changeTargetLanguage = function () {
  461. self.settings.targetLanguage = $(this).val();
  462. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  463. };
  464.  
  465. 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>');
  466. $modal.append('<h1>Miracle Scripts Settings</h1>');
  467.  
  468. if (GM_info) {
  469. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  470. }
  471.  
  472. var $element = $('<input name="key_animation" value="' + self.keyboardMap[self.settings.bindings.animation] + '"/>').keyup(changeKey);
  473. $modal.append('<br><br>Animation-Key:<br>', $element);
  474. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  475. $modal.append($element);
  476.  
  477. $element = $('<input name="key_paste" value="' + self.keyboardMap[self.settings.bindings.paste] + '"/>').keyup(changeKey);
  478. $modal.append('<br>Paste-Key:<br>', $element);
  479. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  480. $modal.append($element);
  481.  
  482. $element = $('<input name="key_dance" value="' + self.keyboardMap[self.settings.bindings.dance] + '"/>').keyup(changeKey);
  483. $modal.append('<br>Dance-Key:<br>', $element);
  484. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  485. $modal.append($element);
  486.  
  487. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[self.settings.bindings.chatLog] + '"/>').keyup(changeKey);
  488. $modal.append('<br>Chat-Log-Key:<br>', $element);
  489. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  490. $modal.append($element);
  491.  
  492. $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);
  493. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  494. $element.get(0).value = self.settings.targetLanguage;
  495.  
  496. $element = $('<input type="color" name="favcolor" value="' + self.settings.primaryColor + '"/>').change(changePrimaryColor);
  497. $modal.append('<br><br>User interface color:<br>', $element);
  498.  
  499. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(self.settings.replacements).keydown(addReturn).keyup(changeReplacements);
  500. $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>');
  501.  
  502. $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 () {
  503. $modal.hide();
  504. }));
  505. $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 () {
  506. self.download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  507. }));
  508. $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 () {
  509. var stringifiedSettings = window.prompt('Paste the settings here');
  510. if (stringifiedSettings !== null) {
  511. loadSettings(stringifiedSettings);
  512. localStorage.setItem('miracleScripts', stringifiedSettings);
  513. $modal.hide();
  514. self.message('Settings loaded! Reload Agma to refresh. 😄');
  515. }
  516. }));
  517. $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>'));
  518. $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 () {
  519. $modal.hide();
  520. self.$helpModal.show();
  521. }));
  522.  
  523. $('body').append($modal);
  524.  
  525. $settingsButton.click(function (event) {
  526. $modal.show();
  527.  
  528. event.preventDefault();
  529. });
  530.  
  531. window.addEventListener('miracleCommand', function(commandEvent) {
  532. if (commandEvent.command === '/miraclesettings' || commandEvent.command === '/miracleconfig') {
  533. $modal.show();
  534. $('#chtbox').val('');
  535. }
  536. });
  537. }, 500);
  538. },
  539.  
  540. moveRespawnBtn: function() {
  541. $('#advBox > div:last-child').css('position', 'absolute');
  542. $('#advBox > div:last-child').css('left', '48%');
  543. $('#advBox > div:last-child').css('marginTop', '5px');
  544. $('#advBox > div:nth-child(2)').css('marginLeft', '10%');
  545. },
  546.  
  547. players: function() {
  548. var self = this;
  549.  
  550. $('body').append('<style>#friendList .name { text-decoration: underline; cursor: pointer; }</style>');
  551.  
  552. $('#phpFriendlist').click(function(event) {
  553. if (event.target.classList.contains('name')) { // TODO check: what happens if player is online?
  554. insertPMText($(event.target).text());
  555. }
  556. });
  557.  
  558. $('#btnFriends').click(function() {
  559. var updater = function() {
  560. if ($('#friendDialogMessage').length > 0) {
  561. window.setTimeout(updater, 200);
  562. return;
  563. }
  564.  
  565. $('#phpFriendlist span.name, #requestList span.name').each(function() {
  566. var $nameElement = $(this);
  567. var name = $nameElement.text();
  568. self.settings.players.forEach(function(player) {
  569. if (player.name === name && player.alias) {
  570. $nameElement.attr('title', 'Accountname: ' + name);
  571. $nameElement.css('fontStyle', 'italic');
  572. $nameElement.text(player.alias);
  573. }
  574. });
  575. });
  576. };
  577. window.setTimeout(updater, 200);
  578. });
  579.  
  580. $('#contextUserProfile').click(function() {
  581. $('#miracle-player-settings').remove();
  582.  
  583. window.setTimeout(function() {
  584. if ($('.sweet-alert .sa-error').css('display') === 'block') {
  585. return; // No (public) profile available
  586. }
  587.  
  588. var player = null;
  589. var accountName = $('.sweet-alert h2').text();
  590.  
  591. self.settings.players.some(function(candidate) {
  592. if (candidate.name === accountName) {
  593. player = candidate;
  594. return true;
  595. }
  596. });
  597.  
  598.  
  599. var $editArea = $('<div id="miracle-player-settings">');
  600. var $aliasField = $('<input type="text" maxlength="30" placeholder="Alias" title="Alias" style="display: block; color: #333">').blur(function() {
  601. var alias = $(this).val();
  602. if (player) {
  603. player.alias = alias;
  604. } else {
  605. player = {name: accountName, alias: alias};
  606. self.settings.players.push(player);
  607. }
  608. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  609. });
  610. if (player) {
  611. $aliasField.val(player.alias);
  612. }
  613. $editArea.append($aliasField);
  614. var $noteField = $('<textarea maxlength="250" placeholder="Notes" title="Notes" rows="4" style="width: 100%; padding: 10px; color: #333"></textarea>').blur(function() {
  615. var note = $(this).val();
  616. if (player) {
  617. player.note = note;
  618. } else {
  619. player = {name: accountName, note: note};
  620. self.settings.players.push(player);
  621. }
  622. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  623. });
  624. if (player) {
  625. $noteField.val(player.note);
  626. }
  627. $editArea.append($noteField);
  628.  
  629. $editArea.insertBefore('.sweet-alert .sa-button-container');
  630.  
  631. if ($('.sweet-overlay').attr('data-listening') != 1) {
  632. $('.sweet-overlay').attr('data-listening', 1);
  633.  
  634. $('.sweet-overlay').click(function() {
  635. console.log('sweet bg clicked');
  636. $('#miracle-player-settings').remove();
  637. });
  638. $('.sweet-alert .sa-button-container button').click(function() {
  639. console.log('sweet btn clicked');
  640. $('#miracle-player-settings').remove();
  641. });
  642. }
  643. }, 200);
  644. });
  645.  
  646. },
  647.  
  648. animation: function () {
  649. var self = this;
  650.  
  651. var chatAnimate = function () {
  652. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  653. $('#chtbox').val('');
  654. }
  655.  
  656. // All available commands and combinations
  657. var items = ['wacky',
  658. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  659. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  660. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake', 'wackyshakeshakeshake',
  661. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump',
  662. ];
  663.  
  664. // Super-combinations!!
  665. if (self.getRandomInt(1, 3) === 1) {
  666. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  667. }
  668.  
  669. // Choose randomly an item of the items array
  670. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  671. var item = items[Math.floor(Math.random() * items.length)];
  672.  
  673. // Attempt to avoid triggering spam protection - probably useless :-/
  674. item += String.fromCharCode(8203).repeat(self.getRandomInt(1, 5));
  675.  
  676. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  677. $('#chtbox').val($('#chtbox').val() + item).focus();
  678.  
  679. // Stop the event so that the pressed key won't be written into the chat box!
  680. event.preventDefault();
  681. };
  682.  
  683. window.addEventListener('keydown', function (event) {
  684. // Do nothing if a menu is open
  685. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  686. return;
  687. }
  688.  
  689. if (event.keyCode == self.settings.bindings.animation) {
  690. chatAnimate();
  691. }
  692. });
  693. },
  694.  
  695. paste: function () {
  696. var self = this;
  697. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  698. 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' +
  699. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  700.  
  701. var emojis = this.emojis.split(' ');
  702. var emojiCode = '';
  703.  
  704. emojis.forEach(function (emoji) {
  705. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  706. });
  707.  
  708. var addEmoji = function () {
  709. setTimeout(function () {
  710. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  711.  
  712. // Add text into the chatbox and focus it
  713. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  714. }, 200);
  715.  
  716. $modal.hide();
  717. };
  718.  
  719. 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>');
  720. $modal.append('<style>' + css + '</style>');
  721. $modal.append('<h1>Insert text or emoji</h1>');
  722. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  723. $modal.append('<br><br>Insert:<br>', $pasteInput);
  724. $modal.html($modal.html() + '<br><br>' + emojiCode);
  725. $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));
  726. $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 () {
  727. $modal.hide();
  728. }));
  729.  
  730. $modal.find('input[name=paste]').click(function () {
  731. var text = window.prompt('Please paste your text here!');
  732.  
  733. if (text !== null) {
  734. var $pasteInput = $modal.find('input[name=paste]');
  735.  
  736. // Add text into the paste input
  737. $pasteInput.val($pasteInput.val() + text);
  738. }
  739. });
  740.  
  741. $modal.click(function (event) {
  742. if (event.target.classList.contains('miracle-emoji')) {
  743. var $target = $(this).find('input[name=paste]');
  744. $target.val($target.val() + $(event.target).text());
  745.  
  746. event.preventDefault();
  747. }
  748. });
  749.  
  750. $modal.dblclick(function (event) {
  751. if (event.target.classList.contains('miracle-emoji')) {
  752. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  753. $(this).hide();
  754.  
  755. event.preventDefault();
  756. }
  757. });
  758.  
  759. $('body').append($modal);
  760.  
  761. window.addEventListener('keydown', function (event) {
  762. // Do nothing if a menu is open
  763. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  764. return;
  765. }
  766.  
  767. if (event.keyCode == self.settings.bindings.paste) {
  768. $modal.find('input[name=paste]').val('');
  769. $modal.toggle();
  770. }
  771. });
  772.  
  773. window.addEventListener('miracleCommand', function(commandEvent) {
  774. if (commandEvent.command === '/paste') {
  775. $modal.find('input[name=paste]').val('');
  776. $modal.toggle();
  777. $('#chtbox').val('');
  778. }
  779. });
  780. },
  781.  
  782. replacements: function () {
  783. var self = this;
  784.  
  785. $('#chtbox').keyup(function () {
  786. var lines = self.settings.replacements.split('\n');
  787.  
  788. var text = $('#chtbox').val();
  789.  
  790. lines.forEach(function (line) {
  791. var replacement = line.split('|');
  792. if (replacement.length === 2) {
  793. text = text.replace(replacement[0], replacement[1]);
  794. $('#chtbox').val(text).focus();
  795. }
  796. });
  797. });
  798. },
  799.  
  800. chatLog: function () {
  801. var self = this;
  802.  
  803. // We escape the message before we print them, so no one can inject JS code!
  804. var htmlEntities = function (str) {
  805. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  806. };
  807.  
  808. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  809. var lastChatNickname = null;
  810. var lastChatNicknameColor = null;
  811. var chatLogCode = '';
  812. var chatLog = [];
  813. CanvasRenderingContext2D.prototype.fillText = function () {
  814. if (this.canvas.id !== 'leaderboard' && this.canvas.height === 23) {
  815. var text = arguments[0];
  816. var xPos = arguments[1]; // Usually 3 for nicknames but bigger when a crown, donator icon etc. are displayed
  817. var lineSize = this.canvas.width; // ATTENTION: Not sure if that really is the total size (icons+ nickname + message)
  818.  
  819. // Sometimes also numbers (int) are printed (probably masses on cells) so we filter for strings
  820. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  821. // Dirty fix for the missing icon in the initial welcome messages
  822. if (text == '') {
  823. text = '📢';
  824. }
  825. lastChatNickname = text;
  826. lastChatNicknameColor = this.fillStyle;
  827. }
  828. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  829. // Unfortunately chat messages will be printed more than just once and I don't know
  830. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  831. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  832. var found = false;
  833. for (var i = 0; i < chatLog.length; i++) {
  834. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  835. found = true;
  836. break;
  837. }
  838. }
  839.  
  840. if (!found) {
  841. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  842. chatLogCode += '<div><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  843. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  844. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  845. }
  846. }
  847. }
  848.  
  849. return originalFillText.apply(this, arguments);
  850. };
  851.  
  852. var performSearch = function (searchElement) {
  853. var subject = searchElement.value.toLowerCase();
  854.  
  855. $('#miracle-complete-chatlog div').each(function () {
  856. var $entry = $(this);
  857.  
  858. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  859. $entry.hide();
  860. } else {
  861. $entry.show();
  862. }
  863. });
  864. };
  865.  
  866. 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>');
  867. $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>');
  868. $modal.append('<h1>Complete chatlog</h1><br>');
  869. $modal.append('<div id="miracle-complete-chatlog"></div>');
  870. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  871. performSearch(this);
  872. }));
  873. $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 () {
  874. $modal.hide();
  875. }));
  876. $('body').append($modal);
  877.  
  878. $('#miracle-complete-chatlog').dblclick(function (event) {
  879. var $clickTarget;
  880.  
  881. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  882. if (event.target.tagName.toLowerCase() === 'span') {
  883. $clickTarget = $(event.target).parent();
  884. } else {
  885. $clickTarget = $(event.target);
  886. }
  887.  
  888. var message = $clickTarget.find('.message').text();
  889.  
  890. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  891. if (message.substr(0, 2) === ': ') {
  892. message = message.substr(2);
  893. }
  894.  
  895. window.open('https://www.deepl.com/translator#en/' + self.settings.targetLanguage + '/' + message);
  896. });
  897.  
  898. var showChatlog = function() {
  899. $('#miracle-complete-chatlog').html(chatLogCode);
  900. $modal.toggle();
  901. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  902. };
  903.  
  904. window.addEventListener('keyup', function (event) {
  905. // Ignore text input field so typing in them is possible
  906. if (self.isWritingText()) {
  907. return;
  908. }
  909.  
  910. if (event.keyCode == self.settings.bindings.chatLog) {
  911. showChatlog();
  912. }
  913. });
  914.  
  915. window.addEventListener('miracleCommand', function(commandEvent) {
  916. if (commandEvent.command === '/chatlog') {
  917. showChatlog();
  918. $('#chtbox').val('');
  919. }
  920. });
  921. },
  922.  
  923. favSkins: function () {
  924. var self = this;
  925.  
  926. // We need to have a delay, because the menu is not loaded right away
  927. setTimeout(function () {
  928. var favIconClick = function () {
  929. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  930.  
  931. if (self.settings.favSkins.includes(id)) {
  932. $(this).addClass('skin-not-fav');
  933. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  934. var index = self.settings.favSkins.indexOf(id);
  935. self.settings.favSkins.splice(index, 1);
  936. } else {
  937. $(this).removeClass('skin-not-fav');
  938. self.settings.favSkins.push(id);
  939. }
  940. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  941. renderFavSkins();
  942. };
  943.  
  944. var renderFavSkins = function () {
  945. var $skins = null;
  946.  
  947. if ($('#fav-skins').length > 0) {
  948. $skins = $('#fav-skins');
  949. $skins.html('');
  950. } else {
  951. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  952. $skins.insertAfter('#publicSkinsHeader');
  953.  
  954. $('#fav-skins').click(function (event) {
  955. if (event.target.tagName.toLowerCase() === 'span') {
  956. favIconClick.apply(event.target);
  957. }
  958. });
  959. }
  960. self.settings.favSkins.forEach(function (id) {
  961. $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>');
  962. });
  963. $skins.append('<div style="clear: both"></div>');
  964. };
  965.  
  966. var addFavIcons = function () {
  967. var $skins = $('#publicSkinsPage');
  968. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  969.  
  970. $skins.find('h4').each(function () {
  971. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  972. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  973.  
  974. $favIcon.click(favIconClick);
  975.  
  976. $(this).append($favIcon);
  977.  
  978. if (! self.settings.favSkins.includes(id)) {
  979. $favIcon.addClass('skin-not-fav');
  980. }
  981. });
  982. };
  983. var initialized = false;
  984. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  985. if (!initialized) {
  986. var checkState = function () {
  987. if ($('#publicSkinsPage').html() !== '') {
  988. addFavIcons();
  989. renderFavSkins();
  990. } else {
  991. setTimeout(checkState, 30);
  992. }
  993. };
  994. checkState();
  995. initialized = true;
  996. }
  997. });
  998. $('#phpSkins').click(function (event) {
  999. if (event.target.classList.contains('publicskins-nav-btn')) {
  1000. addFavIcons();
  1001. }
  1002. });
  1003.  
  1004. }, 500);
  1005. },
  1006.  
  1007. skinChanger: function() {
  1008. var self = this;
  1009.  
  1010. // When the user changes the skin, display ID of the picked skin
  1011. var originalToggleSkin = window.toggleSkin;
  1012. window.toggleSkin = function () {
  1013. self.message('Picked skin with ID ' + arguments[0]);
  1014.  
  1015. return originalToggleSkin.apply(this, arguments);
  1016. };
  1017.  
  1018. window.addEventListener('miracleCommand', function(commandEvent) {
  1019. var useSkinFromSlot = function (skinSlot, skinId) {
  1020. if (skinId) {
  1021. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  1022. var skinUri = self.getSkinUrl();
  1023. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1024. }
  1025.  
  1026. skinId = parseInt(skinId);
  1027. self.settings.quickSkins[skinSlot - 1] = skinId;
  1028. localStorage.setItem('miracleScripts', JSON.stringify(self.settings));
  1029. } else {
  1030. skinId = self.settings.quickSkins[skinSlot - 1];
  1031. if (!skinId) {
  1032. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  1033. $('#chtbox').val('').focus();
  1034. return;
  1035. }
  1036. }
  1037.  
  1038. self.useSkin(skinId);
  1039.  
  1040. $('#chtbox').val('').focus();
  1041. };
  1042.  
  1043. if (commandEvent.command === 'skin1' || commandEvent.command === '/skin1') {
  1044. useSkinFromSlot(1, commandEvent.argument1);
  1045. }
  1046. if (commandEvent.command === 'skin2' || commandEvent.command === '/skin2') {
  1047. useSkinFromSlot(2, commandEvent.argument1);
  1048. }
  1049. if (commandEvent.command === 'skin3' || commandEvent.command === '/skin3') {
  1050. useSkinFromSlot(3, commandEvent.argument1);
  1051. }
  1052. if (commandEvent.command === 'skin4' || commandEvent.command === '/skin4') {
  1053. useSkinFromSlot(4, commandEvent.argument1);
  1054. }
  1055. if (commandEvent.command === 'skin5' || commandEvent.command === '/skin5') {
  1056. useSkinFromSlot(5, commandEvent.argument1);
  1057. }
  1058. if (commandEvent.command === 'skin6' || commandEvent.command === '/skin6') {
  1059. useSkinFromSlot(6, commandEvent.argument1);
  1060. }
  1061. if (commandEvent.command === 'skin7' || commandEvent.command === '/skin7') {
  1062. useSkinFromSlot(7, commandEvent.argument1);
  1063. }
  1064. if (commandEvent.command === 'skin8' || commandEvent.command === '/skin8') {
  1065. useSkinFromSlot(8, commandEvent.argument1);
  1066. }
  1067. if (commandEvent.command === 'skin9' || commandEvent.command === '/skin9') {
  1068. useSkinFromSlot(9, commandEvent.argument1);
  1069. }
  1070. if (commandEvent.command === 'skin10' || commandEvent.command === '/skin10') {
  1071. useSkinFromSlot(10, commandEvent.argument1);
  1072. }
  1073. if (commandEvent.command === 'skin11' || commandEvent.command === '/skin11') {
  1074. useSkinFromSlot(11, commandEvent.argument1);
  1075. }
  1076. if (commandEvent.command === 'skin12' || commandEvent.command === '/skin12') {
  1077. useSkinFromSlot(12, commandEvent.argument1);
  1078. }
  1079. if (commandEvent.command === 'skin13' || commandEvent.command === '/skin13') {
  1080. useSkinFromSlot(13, commandEvent.argument1);
  1081. }
  1082. if (commandEvent.command === 'skin14' || commandEvent.command === '/skin14') {
  1083. useSkinFromSlot(14, commandEvent.argument1);
  1084. }
  1085. if (commandEvent.command === 'skin15' || commandEvent.command === '/skin15') {
  1086. useSkinFromSlot(15, commandEvent.argument1);
  1087. }
  1088. if (commandEvent.command === 'skin16' || commandEvent.command === '/skin16') {
  1089. useSkinFromSlot(16, commandEvent.argument1);
  1090. }
  1091. if (commandEvent.command === 'skin17' || commandEvent.command === '/skin17') {
  1092. useSkinFromSlot(17, commandEvent.argument1);
  1093. }
  1094. if (commandEvent.command === 'skin18' || commandEvent.command === '/skin18') {
  1095. useSkinFromSlot(18, commandEvent.argument1);
  1096. }
  1097. if (commandEvent.command === 'skin19' || commandEvent.command === '/skin19') {
  1098. useSkinFromSlot(19, commandEvent.argument1);
  1099. }
  1100. if (commandEvent.command === 'skin20' || commandEvent.command === '/skin20') {
  1101. useSkinFromSlot(20, commandEvent.argument1);
  1102. }
  1103. if (commandEvent.command === 'skin21' || commandEvent.command === '/skin21') {
  1104. self.message('Only 20 skin slots are available ❌', true);
  1105. $('#chtbox').val('').focus();
  1106. }
  1107. });
  1108. },
  1109.  
  1110. lineSplit: function() {
  1111. var self = this;
  1112.  
  1113. window.addEventListener('miracleCommand', function(commandEvent) {
  1114. if (commandEvent.command === '/linesplit') {
  1115. self.lineSplitAt = Date.now();
  1116. self.message('Linesplit •••••');
  1117.  
  1118. var doSplit = function() {
  1119. if (Date.now() - self.lineSplitAt < 1000) {
  1120. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  1121. var x = window.innerWidth / 2;
  1122. var y = factor * (window.innerHeight / 2);
  1123.  
  1124. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1125.  
  1126. window.requestAnimationFrame(doSplit);
  1127. } else {
  1128. if (Date.now() - self.lineSplitAt < 3000) {
  1129. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  1130. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.Space.c}));
  1131. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.Space.c}));
  1132. self.splitAt = Date.now();
  1133. }
  1134.  
  1135. window.requestAnimationFrame(doSplit);
  1136. }
  1137. }
  1138. };
  1139. doSplit();
  1140. $('#chtbox').val('');
  1141. }
  1142. });
  1143. },
  1144.  
  1145. dance: function () {
  1146. var self = this;
  1147.  
  1148. // Stop dancing on respawn
  1149. window.addEventListener('keydown', function (event) {
  1150. if (event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1151. self.dancing = false;
  1152. }
  1153. });
  1154.  
  1155. var initDance = function() {
  1156. // Do nothing if a menu is open
  1157. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1158. return;
  1159. }
  1160.  
  1161. self.dancing = ! self.dancing;
  1162.  
  1163. if (self.dancing) {
  1164. self.performDance.apply(self);
  1165. }
  1166. };
  1167.  
  1168. window.addEventListener('keyup', function () {
  1169. if (event.keyCode == self.settings.bindings.dance) {
  1170. initDance();
  1171. }
  1172. });
  1173.  
  1174. window.addEventListener('miracleCommand', function(commandEvent) {
  1175. if (commandEvent.command === '/dance') {
  1176. initDance();
  1177. $('#chtbox').val('');
  1178. }
  1179. });
  1180. },
  1181.  
  1182. performDance: function () {
  1183. var self = this ? this : window.miracleScripts;
  1184.  
  1185. if (self.danceAngle === undefined) {
  1186. self.danceAngle = 0;
  1187. }
  1188.  
  1189. self.danceAngle += 20;
  1190.  
  1191. if (self.danceAngle > 360) {
  1192. self.danceAngle = 0;
  1193. }
  1194.  
  1195. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  1196. var x = window.innerWidth / 2 + Math.sin(self.danceAngle * Math.PI / 180) * distance;
  1197. var y = window.innerHeight / 2 + Math.cos(self.danceAngle * Math.PI / 180) * distance;
  1198. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1199.  
  1200. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  1201. if (document.getElementById('advert').style.display !== 'none') {
  1202. self.dancing = false;
  1203. }
  1204. if (self.dancing) {
  1205. window.requestAnimationFrame(self.performDance);
  1206. }
  1207. },
  1208.  
  1209. waste: function() {
  1210. var self = this;
  1211.  
  1212. window.addEventListener('keydown', function (event) {
  1213. if (event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1214. self.wasting = false;
  1215. }
  1216. });
  1217.  
  1218. window.addEventListener('miracleCommand', function(commandEvent) {
  1219. if (commandEvent.command === '/waste') {
  1220. if (self.wasting) {
  1221. self.wasting = false;
  1222. self.message('Stopped wasting all mass.');
  1223. self.dancing = false;
  1224. } else {
  1225. self.wasting = true;
  1226. self.message('Wasting all mass... 💥');
  1227. if (! self.dancing) {
  1228. self.dancing = true;
  1229. self.performDance.apply(self);
  1230. }
  1231. $('#chtbox').val('spinshakeflip').focus();
  1232. }
  1233.  
  1234. var doWaste = function() {
  1235. // Stop wasting mass if dead ... to avoid continuing wasting after next respawn
  1236. if (document.getElementById('advert').style.display !== 'none') {
  1237. self.wasting = false;
  1238. }
  1239. if (! self.wasting) {
  1240. return;
  1241. }
  1242. $('body').trigger($.Event('keydown', { keyCode: self.hotkeys.W.c}));
  1243. $('body').trigger($.Event('keyup', { keyCode: self.hotkeys.W.c}));
  1244. window.requestAnimationFrame(doWaste);
  1245. };
  1246. doWaste();
  1247. }
  1248. });
  1249. },
  1250.  
  1251. fpsPing: function () {
  1252. window.addEventListener('miracleCommand', function(commandEvent) {
  1253. if (commandEvent.command === 'ping' || commandEvent.command === '/ping') {
  1254. window.setFPS(1);
  1255. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  1256. if (parseInt(ping) > 0) {
  1257. if (parseInt(ping) >= 0 && parseInt(ping) < 40) { pingRating = 'Perfect! ✔️'; }
  1258. if (parseInt(ping) >= 40 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  1259. if (parseInt(ping) >= 70 && parseInt(ping) < 120) { pingRating = 'Acceptable! ✔️'; }
  1260. if (parseInt(ping) >= 120 && parseInt(ping) < 200) { pingRating = 'Bad! ❌'; }
  1261. if (parseInt(ping) >= 200 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  1262. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  1263. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  1264. } else {
  1265. ping = '∞ (infinite) ';
  1266. }
  1267. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating).focus();
  1268. }
  1269. if (commandEvent.command === 'fps' || commandEvent.command === '/fps') {
  1270. window.setFPS(1);
  1271. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  1272. if (parseInt(fps) > 0) {
  1273. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  1274. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  1275. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  1276. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  1277. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  1278. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  1279. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  1280. } else {
  1281. fpsRating = '';
  1282. }
  1283.  
  1284. $('#chtbox').val('has ' + fps + ' frames per second (fps). ' + fpsRating).focus();
  1285. }
  1286. });
  1287. },
  1288.  
  1289. timer: function() {
  1290. var self = this;
  1291.  
  1292. var timerStartedAt = null;
  1293. var timerMinutes = null;
  1294. var timeoutId = null;
  1295. var updateId = null;
  1296.  
  1297. var $countdownUi = $('<div style="position: fixed; right: 20px; bottom: 225px; z-index: 9999; color: #3e3e3e; pointer-events: none"></div>');
  1298. $('body').append($countdownUi);
  1299.  
  1300. window.addEventListener('miracleCommand', function(commandEvent) {
  1301. if (commandEvent.command === 'timer' || commandEvent.command === '/timer') {
  1302. var argument1 = commandEvent.argument1;
  1303. var argument2 = commandEvent.argument2;
  1304.  
  1305. if (argument1) {
  1306. timerMinutes = parseInt(argument1);
  1307. if (argument2 === 'h' || argument2 === 'hour' || argument2 === 'hours') {
  1308. timerMinutes *= 60;
  1309. }
  1310. if (timeoutId !== null) {
  1311. clearTimeout(timeoutId);
  1312. }
  1313.  
  1314. if (argument1 === '0' || argument1 === 'reset' || argument1 === 'stop') {
  1315. self.message('🗑️ Timer removed');
  1316. } else {
  1317. timerStartedAt = Date.now();
  1318. var updateUi = function () {
  1319. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1320. $countdownUi.text('🕒 ' + Math.ceil(remaining) + 'm');
  1321. };
  1322. updateId = setInterval(updateUi, 10000);
  1323. updateUi();
  1324. timeoutId = setTimeout(function () {
  1325. timeoutId = null;
  1326. window.clearInterval(updateId);
  1327. $countdownUi.text('');
  1328. var message = '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.';
  1329. this.message(message);
  1330. window.alert(message);
  1331. }, timerMinutes * 60 * 1000);
  1332.  
  1333. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  1334. }
  1335. } else {
  1336. if (timeoutId === null) {
  1337. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  1338. } else {
  1339. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1340. self.message('🕒 ' + Math.round(remaining * 10) / 10 + ' minutes remaining.');
  1341. }
  1342. }
  1343. $('#chtbox').val('').focus();
  1344. }
  1345. });
  1346. },
  1347.  
  1348. alive: function() {
  1349. var self = this;
  1350.  
  1351. var element = document.getElementById('playBtn');
  1352. element.addEventListener('click', function() {
  1353. if (! self.isAlive) {
  1354. self.spawnedAt = Date.now();
  1355. self.isAlive = true;
  1356. }
  1357. });
  1358. element = document.querySelector('.bottom-dashboard-box img[title=Respawn]');
  1359. element.addEventListener('click', function() {
  1360. self.spawnedAt = Date.now();
  1361. self.isAlive = true;
  1362. });
  1363. element = document.getElementById('advertContinue');
  1364. element.addEventListener('click', function() {
  1365. self.isAlive = false;
  1366. });
  1367.  
  1368. window.addEventListener('keydown', function (event) {
  1369. if (event.keyCode == self.hotkeys.M.c && ! self.isWritingText()) {
  1370. self.spawnedAt = Date.now();
  1371. self.isAlive = true;
  1372. }
  1373. });
  1374.  
  1375. window.addEventListener('miracleCommand', function(commandEvent) {
  1376. if (commandEvent.command === '/alive' || commandEvent.command === 'alive') {
  1377. if (! self.isAlive || document.getElementById('advert').style.display !== 'none') {
  1378. $('#chtbox').val('is not alive ☠');
  1379. } else {
  1380. var minutes = parseInt((Date.now() - self.spawnedAt) / 1000 / 60);
  1381. if (minutes < 1) {
  1382. minutes = parseInt((Date.now() - self.spawnedAt) / 1000) + ' Seconds & 0';
  1383. }
  1384. if (minutes > 60) {
  1385. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1386. }
  1387. $('#chtbox').val('has been alive for ' + minutes + ' Minutes');
  1388. }
  1389. }
  1390. });
  1391.  
  1392. },
  1393.  
  1394. nameColor: function() {
  1395. var self = this;
  1396.  
  1397. window.addEventListener('miracleCommand', function(commandEvent) {
  1398. if (commandEvent.command === '/namecolor' || commandEvent.command === '/colorname' || commandEvent.command === '/colorchange') {
  1399. self.message('🚫 This feature has been removed since the Agma staff does not allow it', true);
  1400. $('#chtbox').val('');
  1401. }
  1402. });
  1403. },
  1404.  
  1405. skinApplier: function() {
  1406. var self = this;
  1407.  
  1408. 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>');
  1409. $useSkinItem.insertAfter('#contextPlayer');
  1410.  
  1411. $useSkinItem.click(function() {
  1412. var skinUrl = self.getSkinUrl('#contextPlayerSkin');
  1413. if (skinUrl === null) {
  1414. self.message('This player does not use a skin or no player selected 🚫', true);
  1415. } else {
  1416. var skinId = parseInt(skinUrl.substr(22)); // Cut off "https://agma.io/skins/"
  1417. self.useSkin(skinId);
  1418. }
  1419. });
  1420. },
  1421.  
  1422. help: function() {
  1423. 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>');
  1424. $modal.append('<h1>Miracle Scripts Help</h1>');
  1425.  
  1426. var helpText = '<br><span style="color: #717171">Available chat commands are: </span><br><br><table>' +
  1427. '<tr><th style="padding-right: 70px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  1428. '<tr><td><code>/help</code></td><td>Show this help</td></tr>' +
  1429. '<tr><td><code>/miracle</code></td><td>Show version info</td></tr>' +
  1430. '<tr><td><code>/miraclesettings</code></td><td>Show the miracle settings page</td></tr>' +
  1431. '<tr><td><code>/skin<n></code></td><td>Change to skin &lt;n></td></tr>' +
  1432. '<tr><td><code>/skin<n> this</code></td><td>Store current skin as skin <n></td></tr>' +
  1433. '<tr><td><code>/skin<n> &lt;id></code></td><td>Store skin with ID &lt;id> as skin &lt;n></td></tr>' +
  1434. '<tr><td><code>/skinid</code></td><td>Send a chat message with your skin ID</td></tr>' +
  1435. '<tr><td><code>/useskin &lt;id></code></td><td>Use skin with the given ID</td></tr>' +
  1436. '<tr><td><code>/chatlog</code></td><td>Show the extended chat log</td></tr>' +
  1437. '<tr><td><code>/say &lt;text></code></td><td>Send a chat message with a fancy font</td></tr>' +
  1438. '<tr><td><code>/say&lt;n> &lt;text></code></td><td>Send chat message with fancy font number &lt;n></td></tr>' +
  1439. '<tr><td><code>/shout &lt;text></code></td><td>Purchase a megaphone shout for 20000 coins></td></tr>' +
  1440. '<tr><td><code>/paste</code></td><td>Show the emojis and text paste page</td></tr>' +
  1441. '<tr><td><code>/timer &lt;n></code></td><td>Set timer for &lt;n> minutes</td></tr>' +
  1442. '<tr><td><code>/timer &lt;n> h</code></td><td>Set timer for &lt;n> hours</td></tr>' +
  1443. '<tr><td><code>/timer stop</code></td><td>Stop the timer</td></tr>' +
  1444. '<tr><td><code>/xp</code></td><td>Send a chat message with your level and next level\'s progress</td></tr>' +
  1445. '<tr><td><code>/powerups</code></td><td>Send a chat message with your powerup amounts</td></tr>' +
  1446. '<tr><td><code>/fps</code></td><td>Send a chat message with current fps</td></tr>' +
  1447. '<tr><td><code>/ping</code></td><td>Send a chat message with current ping</td></tr>' +
  1448. '<tr><td><code>/online</code></td><td>For how long are you online in the current session?</td></tr>' +
  1449. '<tr><td><code>/alive</code></td><td>For how long are you alive?</td></tr>' +
  1450. '<tr><td><code>/solo</code></td><td>Show the solo server message</td></tr>' +
  1451. '<tr><td><code>/dice</code></td><td>Roll a dice with 6 sides</td></tr>' +
  1452. '<tr><td><code>/dice &lt;n></code></td><td>Roll a dice with &lt;n> sides</td></tr>' +
  1453. '<tr><td><code>/linesplit</code></td><td>Let your cell make a linesplit</td></tr>' +
  1454. '<tr><td><code>/waste</code></td><td>Waste all your mass</td></tr>' +
  1455. '<tr><td><code>/dance</code></td><td>Let your cell dance</td></tr>' +
  1456. '</table>';
  1457.  
  1458. $modal.append(helpText);
  1459.  
  1460. $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 () {
  1461. $modal.hide();
  1462. }));
  1463.  
  1464. $('body').append($modal);
  1465.  
  1466. this.$helpModal = $modal;
  1467.  
  1468. window.addEventListener('miracleCommand', function(commandEvent) {
  1469. if (commandEvent.command === '/help' || commandEvent.command === '/miraclehelp') {
  1470. $('#chtbox').val('').focus();
  1471. $modal.show();
  1472. }
  1473. });
  1474. },
  1475.  
  1476. commands: function () {
  1477. var self = this;
  1478. var minutes, skinId;
  1479.  
  1480. var sessionStartedAt = Date.now();
  1481.  
  1482. $('#chtbox').keydown(function (event) {
  1483. if (event.keyCode === 13) {
  1484. var message = $('#chtbox').val();
  1485. var command = message.split(' ')[0];
  1486. var argument1 = message.split(' ')[1];
  1487. var argument2 = message.split(' ')[2];
  1488.  
  1489. if (message === 'time' || command === '/time') {
  1490. var now = new Date();
  1491. $('#chtbox').val('Local time: ' + now.toLocaleString()).focus();
  1492. }
  1493.  
  1494. if (message === 'minutes' || command === '/minutes' || message === 'online' || command === '/online') {
  1495. if (message === 'minutes' || command === '/minutes') {
  1496. self.message('⛔ The /minutes command is deprecated, please use /online instead.', true);
  1497. }
  1498.  
  1499. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  1500. if (minutes < 1) {
  1501. minutes = parseInt((Date.now() - self.spawnedAt) / 1000) + ' Seconds & 0';
  1502. }
  1503. if (minutes > 60) {
  1504. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1505. }
  1506. $('#chtbox').val('is online for: ' + minutes + ' Minutes in the current session').focus();
  1507. }
  1508.  
  1509. if (command === '/solo') {
  1510. $('#chtbox').val('⚠️⚠️⚠️ SOLO SERVER ⚠️⚠️⚠️ No teaming!! No hay equipo!! Pas d\'équipe!! Kein Teaming!!').focus();
  1511. }
  1512.  
  1513. if (command === '/miracle') {
  1514. var miracleInfo = 'is using 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴, version ';
  1515.  
  1516. if (GM_info) {
  1517. miracleInfo += GM_info.script.version;
  1518. } else {
  1519. miracleInfo += 'unknown';
  1520. }
  1521.  
  1522. $('#chtbox').val(miracleInfo).focus();
  1523. }
  1524.  
  1525. if (command === '/skinid' || command === '/sayskin') {
  1526. var skinUri = self.getSkinUrl();
  1527. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1528. $('#chtbox').val('uses the skin with the ID ' + skinId);
  1529. return;
  1530. }
  1531.  
  1532. if (command === '/useskin') {
  1533. skinId = parseInt(argument1);
  1534. if (! (skinId > 0)) {
  1535. self.message('Invalid skin ID given. Example usage of command: /useskin 123', true);
  1536. } else {
  1537. self.useSkin(skinId);
  1538. }
  1539.  
  1540. $('#chtbox').val('');
  1541. }
  1542.  
  1543. if (command.substr(0, 4) === '/say' || (command === '/party' && argument1.substr(0, 4) === '/say') || (command === '/pm' && argument2.substr(0, 4) === '/say')) {
  1544. var prefix = '';
  1545. if (command === '/party' && argument1.substr(0, 4) === '/say') {
  1546. prefix = '/party ';
  1547. message = message.substr(7);
  1548. }
  1549. if (command === '/pm' && argument2.substr(0, 4) === '/say') {
  1550. var spacePos = message.indexOf(' ', 5);
  1551. prefix = message.substr(0, spacePos + 1);
  1552. message = message.substr(spacePos + 1);
  1553. }
  1554.  
  1555. var fontIndex = message.charAt(4) - 1;
  1556. if (Number.isNaN(fontIndex)|| fontIndex < 0 || fontIndex > Object.getOwnPropertyNames(self.fonts).length - 1) {
  1557. fontIndex = 1;
  1558. }
  1559.  
  1560. $('#chtbox').val(prefix + self.useUnicodeFont(message.substr(message.indexOf(' ') + 1), Object.getOwnPropertyNames(self.fonts)[fontIndex])).focus();
  1561. }
  1562.  
  1563. if (command === '/dice') {
  1564. var max = (argument1 > 0) ? parseInt(argument1) : 6;
  1565. var number = self.getRandomInt(1, max);
  1566. $('#chtbox').val('rolled a dice with ' + max + ' sides. Result: ' + number);
  1567. }
  1568.  
  1569. if (command === '/powerups' || command === '/powers') {
  1570. // Note: If the amount of a powerup is 1, no number will be displayed.
  1571. var powerups = ($('#invRecombine p').text() || 0) + ' rec, ' +
  1572. ($('#invSpeed p').text() || ($('#invSpeed').css('display') === 'none' ? 0 : 1)) + ' speed, ' +
  1573. ($('#invGrowth p').text() || ($('#invGrowth').css('display') === 'none' ? 0 : 1)) + ' growth, ' +
  1574. ($('#invSpawnVirus p').text() || ($('#invSpawnVirus').css('display') === 'none' ? 0 : 1)) + ' virus, ' +
  1575. ($('#invSpawnMothercell p').text() || ($('#invSpawnMothercell').css('display') === 'none' ? 0 : 1)) + ' red cell, ' +
  1576. ($('#invSpawnPortal p').text() || ($('#invSpawnPortal').css('display') === 'none' ? 0 : 1)) + ' portal, ' +
  1577. ($('#invSpawnGoldOre p').text() || ($('#invSpawnGoldOre').css('display') === 'none' ? 0 : 1)) + ' block, ' +
  1578. ($('#invFreeze p').text() || ($('#invFreeze').css('display') === 'none' ? 0 : 1)) + ' freeze, ' +
  1579. ($('#inv360Shot p').text() || ($('#inv360Shot').css('display') === 'none' ? 0 : 1)) + ' push ';
  1580. $('#chtbox').val('has ' + powerups);
  1581. }
  1582.  
  1583. if (command === '/xp' || command === '/progress') {
  1584. $('#chtbox').val('is level ' + $('#level2').text() + ' and has ' + $('.xpBarTop span').text() + ' of next level');
  1585. }
  1586.  
  1587. if (command === '/megaphone' || command === '/megashout' || command === '/shout') {
  1588. // Notes: 1-7 = colors. The shout message can have max 130 chars, but chat messages can be only 100(?) chars long so np
  1589. self.warnBeforeMegaShout(message.substr(message.indexOf(' ') + 1), self.getRandomInt(1, 7));
  1590. $('#chtbox').val('');
  1591. }
  1592.  
  1593. var commandEvent = new Event('miracleCommand');
  1594. commandEvent.message = message;
  1595. commandEvent.command = command;
  1596. commandEvent.argument1 = argument1;
  1597. commandEvent.argument2 = argument2;
  1598. window.dispatchEvent(commandEvent);
  1599. }
  1600. });
  1601. },
  1602.  
  1603. /**
  1604. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  1605. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  1606. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumerics
  1607. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumeric_Supplement
  1608. */
  1609. fonts: {
  1610. doubleStruck : function(charCode) {
  1611. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  1612. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  1613. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  1614. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  1615. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  1616. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  1617. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  1618. if (charCode >= 65 && charCode <= 90) {
  1619. return String.fromCodePoint(0x1D538 + charCode - 65);
  1620. }
  1621. if (charCode >= 97 && charCode <= 122) {
  1622. return String.fromCodePoint(0x1D552 + charCode - 97);
  1623. }
  1624. if (charCode >= 48 && charCode <= 57) {
  1625. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  1626. }
  1627. return String.fromCharCode(charCode);
  1628. },
  1629.  
  1630. monospace : function(charCode) {
  1631. if (charCode >= 65 && charCode <= 90) {
  1632. return String.fromCodePoint(0x1D670 + charCode - 65);
  1633. }
  1634. if (charCode >= 97 && charCode <= 122) {
  1635. return String.fromCodePoint(0x1D68A + charCode - 97);
  1636. }
  1637. if (charCode >= 48 && charCode <= 57) {
  1638. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  1639. }
  1640. return String.fromCharCode(charCode);
  1641. },
  1642.  
  1643. scriptBold : function(charCode) {
  1644. if (charCode >= 65 && charCode <= 90) {
  1645. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  1646. }
  1647. if (charCode >= 97 && charCode <= 122) {
  1648. return String.fromCodePoint(0x1D4EA + charCode - 97);
  1649. }
  1650. if (charCode >= 48 && charCode <= 57) {
  1651. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1652. }
  1653. return String.fromCharCode(charCode);
  1654. },
  1655.  
  1656. frakturBold : function(charCode) {
  1657. if (charCode === 121) { return '𝐲'; } // y
  1658. if (charCode >= 65 && charCode <= 90) {
  1659. return String.fromCodePoint(0x1D56C + charCode - 65);
  1660. }
  1661. if (charCode >= 97 && charCode <= 122) {
  1662. return String.fromCodePoint(0x1D586 + charCode - 97);
  1663. }
  1664. if (charCode >= 48 && charCode <= 57) {
  1665. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1666. }
  1667. return String.fromCharCode(charCode);
  1668. },
  1669.  
  1670. serifItalic: function(charCode) {
  1671. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  1672. if (charCode >= 65 && charCode <= 90) {
  1673. return String.fromCodePoint(0x1D434 + charCode - 65);
  1674. }
  1675. if (charCode >= 97 && charCode <= 122) {
  1676. return String.fromCodePoint(0x1D44E + charCode - 97);
  1677. }
  1678. return String.fromCharCode(charCode);
  1679. },
  1680.  
  1681. circled: function(charCode) {
  1682. if (charCode >= 65 && charCode <= 90) {
  1683. return String.fromCodePoint(0x24B6 + charCode - 65);
  1684. }
  1685. if (charCode >= 97 && charCode <= 122) {
  1686. return String.fromCodePoint(0x24D0 + charCode - 97);
  1687. }
  1688. if (charCode >= 49 && charCode <= 57) {
  1689. return String.fromCodePoint(0x2460 + charCode - 49);
  1690. }
  1691. return String.fromCharCode(charCode);
  1692. },
  1693.  
  1694. boxed: function(charCode) {
  1695. if (charCode >= 65 && charCode <= 90) {
  1696. return String.fromCodePoint(0x1F130 + charCode - 65);
  1697. }
  1698. if (charCode >= 97 && charCode <= 122) {
  1699. return String.fromCodePoint(0x1F130 + charCode - 97);
  1700. }
  1701. if (charCode >= 49 && charCode <= 57) {
  1702. return String.fromCodePoint(0x2460 + charCode - 49);
  1703. }
  1704. return String.fromCharCode(charCode);
  1705. }
  1706. },
  1707.  
  1708. useUnicodeFont: function(text, font) {
  1709. var regexResults, emojiPositions = [], emojiRegex = /:\w+:/g;
  1710. while ((regexResults = emojiRegex.exec(text)) !== null) {
  1711. emojiPositions.push(regexResults.index);
  1712. }
  1713.  
  1714. var converted = '', convert = true;
  1715. for (var i = 0; i < text.length; i++) {
  1716. if (! convert && text.charAt(i) === ':') {
  1717. convert = true;
  1718. }
  1719. if (emojiPositions.indexOf(i) !== -1) {
  1720. convert = false;
  1721. }
  1722. if (convert) {
  1723. converted += this.fonts[font](text.charCodeAt(i));
  1724. } else {
  1725. converted += text.charAt(i);
  1726. }
  1727. }
  1728.  
  1729. return converted;
  1730. },
  1731.  
  1732. isWritingText: function() {
  1733. return document.activeElement.type === 'text' || document.activeElement.type === 'password' || document.activeElement.type === 'textarea';
  1734. },
  1735.  
  1736. download: function (filename, text) {
  1737. var element = document.createElement('a');
  1738. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  1739. element.setAttribute('download', filename);
  1740.  
  1741. element.style.display = 'none';
  1742. document.body.appendChild(element);
  1743.  
  1744. element.click();
  1745.  
  1746. document.body.removeChild(element);
  1747. },
  1748.  
  1749. getVersionAsInt: function(stringVersion) {
  1750. if (stringVersion === undefined) {
  1751. stringVersion = typeof GM_info !== 'undefined' ? GM_info.script.version : '0';
  1752. }
  1753.  
  1754. var parts = stringVersion.split('.');
  1755. if (parts.length === 1) {
  1756. parts.push('0');
  1757. }
  1758. if (parts.length === 2) {
  1759. parts.push('0');
  1760. }
  1761.  
  1762. return parseInt(parts[0]) * 1000000 + parseInt(parts[1]) * 1000 + parseInt(parts[2]);
  1763. },
  1764.  
  1765. /**
  1766. * Returns a random number between min and max (both inclusive)
  1767. * Source: MDN
  1768. */
  1769. getRandomInt: function (min, max) {
  1770. return Math.round(Math.random() * (max - min) + min);
  1771. },
  1772.  
  1773. /**
  1774. * Use the curser div to display a message at the top of the screen.
  1775. *
  1776. * @param message
  1777. * @param isError
  1778. */
  1779. message: function (message, isError) {
  1780. var curser = document.querySelector('#curser');
  1781.  
  1782. curser.textContent = message;
  1783. curser.style.display = 'block';
  1784. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  1785.  
  1786. window.setTimeout(function () {
  1787. curser.style.display = 'none';
  1788. }, 5000);
  1789. },
  1790.  
  1791. swal: function (title, message, html) {
  1792. if (html === undefined) {
  1793. html = true;
  1794. }
  1795. window.swal({
  1796. title: '📢 <span class="miracle-primary-color-font">' + title + '</span>',
  1797. text: message,
  1798. html: html
  1799. });
  1800. },
  1801.  
  1802. /**
  1803. * Returns the URI of my skin or null if not skin has been set.
  1804. * Use this.skinUrl() to get it.
  1805. */
  1806. getSkinUrl: function(sourceSelector) {
  1807. if (sourceSelector === undefined) {
  1808. sourceSelector = '#skinExampleMenu';
  1809. }
  1810. var skinUrlRaw = $(sourceSelector).css('background-image');
  1811.  
  1812. var parts = skinUrlRaw.split('"');
  1813.  
  1814. if (parts.length !== 3) {
  1815. return null;
  1816. } else {
  1817. return parts[1];
  1818. }
  1819. },
  1820.  
  1821. useSkin: function(skinId) {
  1822. window.azad(true);
  1823.  
  1824. setTimeout(function () {
  1825. $('#skinExampleMenu').click();
  1826.  
  1827. var checkLoaded = function () {
  1828. var loaded = ($('#skinsFree tr').length > 1);
  1829. if (loaded) {
  1830. window.toggleSkin(skinId);
  1831.  
  1832. setTimeout(function () {
  1833. $('#shopModalDialog button.close').click();
  1834.  
  1835. setTimeout(function () {
  1836. window.setNick(document.getElementById('nick').value);
  1837. }, 200);
  1838. }, 200);
  1839. } else {
  1840. setTimeout(checkLoaded, 300);
  1841. }
  1842. };
  1843. checkLoaded();
  1844. }, 200);
  1845. },
  1846.  
  1847. /**
  1848. * This is an original Agma function but its not accessible so this is a copy.
  1849. */
  1850. warnBeforeMegaShout: function(msg, color) {
  1851. swal({
  1852. title: "Confirm",
  1853. text: 'If you click "Buy", you will purchase the megaphone shout.',
  1854. type: "warning",
  1855. showCancelButton: true,
  1856. confirmButtonColor: "#4CAF50",
  1857. confirmButtonText: "Yes, confirm purchase",
  1858. cancelButtonText: "No, cancel purchase"
  1859. }, function() {
  1860. //Confirm purchase
  1861. //console.log('purchased megaphone');
  1862. purchaseMega(msg,color);
  1863. //window.location.href = linkURL;
  1864. });
  1865. },
  1866.  
  1867. setupPolyfills: function() {
  1868. // Polyfill for old browser so they have String.fromCodePoint()
  1869. if (!String.fromCodePoint) (function(stringFromCharCode) {
  1870. var fromCodePoint = function(_) {
  1871. var codeUnits = [], codeLen = 0, result = "";
  1872. for (var index=0, len = arguments.length; index !== len; ++index) {
  1873. var codePoint = +arguments[index];
  1874. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  1875. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  1876. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  1877. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  1878. throw RangeError("Invalid code point: " + codePoint);
  1879. if (codePoint <= 0xFFFF) { // BMP code point
  1880. codeLen = codeUnits.push(codePoint);
  1881. } else { // Astral code point; split in surrogate halves
  1882. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  1883. codePoint -= 0x10000;
  1884. codeLen = codeUnits.push(
  1885. (codePoint >> 10) + 0xD800, // highSurrogate
  1886. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  1887. );
  1888. }
  1889. if (codeLen >= 0x3fff) {
  1890. result += stringFromCharCode.apply(null, codeUnits);
  1891. codeUnits.length = 0;
  1892. }
  1893. }
  1894. return result + stringFromCharCode.apply(null, codeUnits);
  1895. };
  1896. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  1897. Object.defineProperty(String, "fromCodePoint", {
  1898. "value": fromCodePoint, "configurable": true, "writable": true
  1899. });
  1900. } catch(e) {
  1901. String.fromCodePoint = fromCodePoint;
  1902. }
  1903. }(String.fromCharCode));
  1904. },
  1905. };
  1906.  
  1907. window.miracleScripts.init();
  1908. })();
  1909.