Miracle Scripts

Best Agma.io script with tons of features

当前为 2020-05-10 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址