Miracle Scripts

Best Agmma.io script with tons of features

目前为 2020-04-05 提交的版本。查看 最新版本

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