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-27 提交的版本,查看 最新版本

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