Miracle Scripts

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

目前為 2020-03-07 提交的版本,檢視 最新版本

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