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

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