Miracle Scripts

Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chat log! Dance! Use chat replacements! Display the time!

当前为 2020-02-26 提交的版本,查看 最新版本

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