Greasy Fork 支持简体中文。

Miracle Scripts

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

目前為 2020-01-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 2.2.0
  5. // @description Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chatlog! 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 http://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. init: function() {
  283. this.setupPolyfills();
  284.  
  285. this.config();
  286.  
  287. this.animation();
  288. this.chatLog();
  289. this.commands();
  290. this.dance();
  291. this.favSkins();
  292. this.paste();
  293. this.replacements();
  294. this.lineSplit();
  295.  
  296. console.log('🌸 Miracle Scripts successfully loaded!');
  297. },
  298.  
  299. config: function() {
  300. var self = this;
  301. var settings;
  302.  
  303. var loadSettings = function (stringifiedSettings) {
  304. var defaultSettings = {
  305. // To get keycodes: https://keycode.info
  306. bindings: {
  307. animation: 17, // CTRL
  308. paste: 33, // PAGE UP
  309. dance: 34, // PAGE DOWN,
  310. chatLog: 76, // L
  311. },
  312. replacements: ":D|:smile:\n:*(|:sob:\n:'D|:sweat_smiley:\nxD|:joy:",
  313. primaryColor: '#FF69B4',
  314. targetLanguage: 'EN',
  315. favSkins: [],
  316. };
  317.  
  318. if (stringifiedSettings == null) {
  319. settings = defaultSettings;
  320. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  321. } else {
  322. settings = JSON.parse(stringifiedSettings);
  323.  
  324. // Update for settings:
  325. if (typeof settings.primaryColor === 'undefined') {
  326. settings.primaryColor = defaultSettings.primaryColor;
  327. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  328. }
  329. if (typeof settings.bindings.chatLog === 'undefined') {
  330. settings.bindings.chatLog = defaultSettings.bindings.chatLog;
  331. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  332. }
  333. if (typeof settings.favSkins === 'undefined') {
  334. settings.favSkins = defaultSettings.favSkins;
  335. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  336. }
  337. if (typeof settings.targetLanguage === 'undefined') {
  338. settings.targetLanguage = defaultSettings.targetLanguage;
  339. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  340. }
  341. if (typeof settings.quickSkins === 'undefined') {
  342. settings.quickSkins = [];
  343. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  344. }
  345. }
  346. };
  347. loadSettings(localStorage.getItem('miracleScripts'));
  348.  
  349. var applyPrimaryColor = function () {
  350. var primaryColorCss = '.miracle-primary-color-font { color: ' + settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + settings.primaryColor + ' !important }; ';
  351. $('body').append('<style>' + primaryColorCss + '</style>');
  352. };
  353. applyPrimaryColor();
  354.  
  355. var download = function (filename, text) {
  356. var element = document.createElement('a');
  357. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  358. element.setAttribute('download', filename);
  359.  
  360. element.style.display = 'none';
  361. document.body.appendChild(element);
  362.  
  363. element.click();
  364.  
  365. document.body.removeChild(element);
  366. };
  367.  
  368. // We need to have a delay, because the menu is not loaded right away
  369. setTimeout(function () {
  370. var $playButton = $('#playBtn');
  371. var $specateButton = $('#spectateBtn');
  372.  
  373. $playButton.get(0).style.width = '40%';
  374. $specateButton.get(0).style.width = '40%';
  375.  
  376. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">📜</button>');
  377. $settingsButton.insertAfter($playButton);
  378.  
  379. var changeKey = function (event) {
  380. var name = this.name.substr(4);
  381. $(this).val(self.keyboardMap[event.keyCode]);
  382. settings.bindings[name] = event.keyCode;
  383. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  384. };
  385.  
  386. var deleteKey = function () {
  387. var action = $(this).attr('data-action');
  388. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  389. settings.bindings[action] = null;
  390. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  391. };
  392.  
  393. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  394. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  395. // focus again (delayed) and go to the end of the text where the linebreak is.
  396. // We can improve this later on...
  397. var addReturn = function (event) {
  398. if (event.keyCode === 13) {
  399. var textarea = this;
  400. $(textarea).text($(this).text() + '\n').focus();
  401. setTimeout(function () {
  402. $(textarea).focus();
  403. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  404. }, 1);
  405. }
  406. };
  407. var changeReplacements = function () {
  408. settings.replacements = $(this).val();
  409. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  410. };
  411. var changePrimaryColor = function () {
  412. settings.primaryColor = $(this).val();
  413. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  414. applyPrimaryColor();
  415. };
  416. var changeTargetLanguage = function () {
  417. settings.targetLanguage = $(this).val();
  418. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  419. };
  420.  
  421. 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>');
  422. $modal.append('<h1>Miracle Scripts Settings</h1>');
  423.  
  424. if (GM_info) {
  425. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  426. }
  427.  
  428. var $element = $('<input name="key_animation" value="' + self.keyboardMap[settings.bindings.animation] + '"/>').keyup(changeKey);
  429. $modal.append('<br><br>Animation-Key:<br>', $element);
  430. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  431. $modal.append($element);
  432.  
  433. $element = $('<input name="key_paste" value="' + self.keyboardMap[settings.bindings.paste] + '"/>').keyup(changeKey);
  434. $modal.append('<br>Paste-Key:<br>', $element);
  435. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  436. $modal.append($element);
  437.  
  438. $element = $('<input name="key_dance" value="' + self.keyboardMap[settings.bindings.dance] + '"/>').keyup(changeKey);
  439. $modal.append('<br>Dance-Key:<br>', $element);
  440. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  441. $modal.append($element);
  442.  
  443. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[settings.bindings.chatLog] + '"/>').keyup(changeKey);
  444. $modal.append('<br>Chat-Log-Key:<br>', $element);
  445. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  446. $modal.append($element);
  447.  
  448. $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);
  449. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  450. $element.get(0).value = settings.targetLanguage;
  451.  
  452. $element = $('<input type="color" name="favcolor" value="' + settings.primaryColor + '"/>').change(changePrimaryColor);
  453. $modal.append('<br><br>User interface color:<br>', $element);
  454.  
  455. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(settings.replacements).keydown(addReturn).keyup(changeReplacements);
  456. $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>');
  457.  
  458. $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 () {
  459. $modal.hide();
  460. }));
  461. $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 () {
  462. download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  463. }));
  464. $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 () {
  465. var stringifiedSettings = prompt('Paste the settings here');
  466. if (stringifiedSettings !== null) {
  467. loadSettings(stringifiedSettings);
  468. localStorage.setItem('miracleScripts', stringifiedSettings);
  469. $modal.hide();
  470. self.message('Settings loaded! Reload Agma to refresh. 😄');
  471. }
  472. }));
  473. $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>'));
  474.  
  475. $('body').append($modal);
  476.  
  477. $settingsButton.click(function (event) {
  478. $modal.show();
  479.  
  480. event.preventDefault();
  481. });
  482. }, 500);
  483. },
  484.  
  485. animation: function () {
  486. var self = this;
  487.  
  488. var chatAnimate = function () {
  489. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  490. self.message('Cannot send animation commands in private chat. 😢', true);
  491. return;
  492. }
  493.  
  494. // All available commands and combinations
  495. var items = ['wacky',
  496. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  497. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  498. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake', 'wackyshakeshakeshake',
  499. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump',
  500. ];
  501.  
  502. // Super-combinations!!
  503. if (self.getRandomArbitrary(1, 3) === 1) {
  504. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  505. }
  506.  
  507. // Choose randomly an item of the items array
  508. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  509. var item = items[Math.floor(Math.random() * items.length)];
  510.  
  511. // Attempt to avoid triggering spam protection - probably useless :-/
  512. item += String.fromCharCode(8203).repeat(self.getRandomArbitrary(1, 5));
  513.  
  514. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  515. $('#chtbox').val($('#chtbox').val() + item).focus();
  516.  
  517. // Stop the event so that the pressed key won't be written into the chat box!
  518. event.preventDefault();
  519. };
  520.  
  521. window.addEventListener('keydown', function (event) {
  522. // Do nothing if a menu is open
  523. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  524. return;
  525. }
  526.  
  527. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  528.  
  529. if (event.keyCode == settings.bindings.animation) {
  530. chatAnimate();
  531. }
  532. });
  533. },
  534.  
  535. paste: function () {
  536. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  537. 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' +
  538. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  539.  
  540. var emojis = this.emojis.split(' ');
  541. var emojiCode = '';
  542.  
  543. emojis.forEach(function (emoji) {
  544. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  545. });
  546.  
  547. var addEmoji = function () {
  548. setTimeout(function () {
  549. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  550.  
  551. // Add text into the chatbox and focus it
  552. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  553. }, 200);
  554.  
  555. $modal.hide();
  556. };
  557.  
  558. 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>');
  559. $modal.append('<style>' + css + '</style>');
  560. $modal.append('<h1>Insert text or emoji</h1>');
  561. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  562. $modal.append('<br><br>Insert:<br>', $pasteInput);
  563. $modal.html($modal.html() + '<br><br>' + emojiCode);
  564. $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));
  565. $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 () {
  566. $modal.hide();
  567. }));
  568.  
  569. $modal.find('input[name=paste]').click(function () {
  570. var text = prompt('Please paste your text here!');
  571.  
  572. if (text !== null) {
  573. var $pasteInput = $modal.find('input[name=paste]');
  574.  
  575. // Add text into the paste input
  576. $pasteInput.val($pasteInput.val() + text);
  577. }
  578. });
  579.  
  580. $modal.click(function (event) {
  581. if (event.target.classList.contains('miracle-emoji')) {
  582. var $target = $(this).find('input[name=paste]');
  583. $target.val($target.val() + $(event.target).text());
  584.  
  585. event.preventDefault();
  586. }
  587. });
  588.  
  589. $modal.dblclick(function (event) {
  590. if (event.target.classList.contains('miracle-emoji')) {
  591. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  592. $(this).hide();
  593.  
  594. event.preventDefault();
  595. }
  596. });
  597.  
  598. $('body').append($modal);
  599.  
  600. window.addEventListener('keydown', function (event) {
  601. // Do nothing if a menu is open
  602. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  603. return;
  604. }
  605.  
  606. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  607.  
  608. if (event.keyCode == settings.bindings.paste) {
  609. $modal.find('input[name=paste]').val('');
  610. $modal.toggle();
  611. }
  612. });
  613. },
  614.  
  615. dance: function () {
  616. var angle = 0;
  617. var angleSpeed = 20;
  618. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  619. var dancing = false;
  620.  
  621. var dance = function () {
  622. angle += angleSpeed;
  623. if (angle > 360) {
  624. angle = 0;
  625. }
  626.  
  627. var x = window.innerWidth / 2 + Math.sin(angle * Math.PI / 180) * distance;
  628. var y = window.innerHeight / 2 + Math.cos(angle * Math.PI / 180) * distance;
  629. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  630.  
  631. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  632. if (document.getElementById('advert').style.display !== 'none') {
  633. dancing = false;
  634. }
  635. if (dancing) {
  636. window.requestAnimationFrame(dance);
  637. }
  638. };
  639.  
  640. window.addEventListener('keyup', function () {
  641. // Do nothing if a menu is open
  642. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  643. return;
  644. }
  645.  
  646. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  647.  
  648. if (event.keyCode == settings.bindings.dance) {
  649. dancing = !dancing;
  650.  
  651. if (dancing) {
  652. window.requestAnimationFrame(dance);
  653. }
  654. }
  655. });
  656. },
  657.  
  658. replacements: function () {
  659. $('#chtbox').keyup(function () {
  660. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  661.  
  662. var lines = settings.replacements.split('\n');
  663.  
  664. var text = $('#chtbox').val();
  665.  
  666. lines.forEach(function (line) {
  667. var replacement = line.split('|');
  668. if (replacement.length === 2) {
  669. text = text.replace(replacement[0], replacement[1]);
  670. $('#chtbox').val(text).focus();
  671. }
  672. });
  673. });
  674. },
  675.  
  676. chatLog: function () {
  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. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  768.  
  769. window.open('https://www.deepl.com/translator#en/' + settings.targetLanguage + '/' + message);
  770. });
  771.  
  772. window.addEventListener('keyup', function (event) {
  773. // Ignore text input field so typing in them is possible
  774. if (document.activeElement.type === 'text' || document.activeElement.type === 'password') {
  775. return;
  776. }
  777.  
  778. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  779.  
  780. if (event.keyCode == settings.bindings.chatLog) {
  781. $('#miracle-complete-chatlog').html(chatLogCode);
  782. $modal.toggle();
  783. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  784. }
  785. });
  786. },
  787.  
  788. favSkins: function () {
  789. // We need to have a delay, because the menu is not loaded right away
  790. setTimeout(function () {
  791. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  792.  
  793. var favIconClick = function () {
  794. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  795.  
  796. if (settings.favSkins.includes(id)) {
  797. $(this).addClass('skin-not-fav');
  798. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  799. var index = settings.favSkins.indexOf(id);
  800. settings.favSkins.splice(index, 1);
  801. } else {
  802. $(this).removeClass('skin-not-fav');
  803. settings.favSkins.push(id);
  804. }
  805. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  806. renderFavSkins();
  807. };
  808.  
  809. var renderFavSkins = function () {
  810. var $skins = null;
  811.  
  812. if ($('#fav-skins').length > 0) {
  813. $skins = $('#fav-skins');
  814. $skins.html('');
  815. } else {
  816. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  817. $skins.insertAfter('#publicSkinsHeader');
  818.  
  819. $('#fav-skins').click(function (event) {
  820. if (event.target.tagName.toLowerCase() == 'span') {
  821. favIconClick.apply(event.target);
  822. }
  823. });
  824. }
  825. settings.favSkins.forEach(function (id) {
  826. $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>');
  827. });
  828. $skins.append('<div style="clear: both"></div>');
  829. };
  830.  
  831. var addFavIcons = function () {
  832. var $skins = $('#publicSkinsPage');
  833. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  834.  
  835. $skins.find('h4').each(function () {
  836. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  837. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  838.  
  839. $favIcon.click(favIconClick);
  840.  
  841. $(this).append($favIcon);
  842.  
  843. if (!settings.favSkins.includes(id)) {
  844. $favIcon.addClass('skin-not-fav');
  845. }
  846. });
  847. };
  848. var initialized = false;
  849. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  850. if (!initialized) {
  851. var checkState = function () {
  852. if ($('#publicSkinsPage').html() !== '') {
  853. addFavIcons();
  854. renderFavSkins();
  855. } else {
  856. setTimeout(checkState, 30);
  857. }
  858. };
  859. checkState();
  860. initialized = true;
  861. }
  862. });
  863. $('#phpSkins').click(function (event) {
  864. if (event.target.classList.contains('publicskins-nav-btn')) {
  865. addFavIcons();
  866. }
  867. });
  868.  
  869. }, 500);
  870. },
  871.  
  872. lineSplit: function() {
  873. var self = this;
  874.  
  875. window.addEventListener('miracleCommand', function(commandEvent) {
  876. if (commandEvent.command === '/linesplit') {
  877. self.lineSplitAt = Date.now();
  878. self.message('Linesplit •••••');
  879.  
  880. var doSplit = function() {
  881. if (Date.now() - self.lineSplitAt < 1000) {
  882. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  883. var x = window.innerWidth / 2;
  884. var y = factor * (window.innerHeight / 2);
  885.  
  886. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  887.  
  888. window.requestAnimationFrame(doSplit);
  889. } else {
  890. if (Date.now() - self.lineSplitAt < 3000) {
  891. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  892. var hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  893. $('body').trigger($.Event('keydown', { keyCode: hotkeys.Space.c}));
  894. $('body').trigger($.Event('keyup', { keyCode: hotkeys.Space.c}));
  895. self.splitAt = Date.now();
  896. }
  897.  
  898. window.requestAnimationFrame(doSplit);
  899. }
  900. }
  901. };
  902. doSplit();
  903. $('#chtbox').val('');
  904. }
  905. });
  906. },
  907.  
  908. commands: function () {
  909. var self = this;
  910. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  911. var minutes;
  912.  
  913. var sessionStartedAt = Date.now();
  914.  
  915. var timeoutStartedAt = null;
  916. var timerMinutes = null;
  917. var timeoutId = null;
  918.  
  919. var originalToggleSkin = window.toggleSkin;
  920. window.toggleSkin = function () {
  921. self.message('Picked skin with ID ' + arguments[0]);
  922.  
  923. return originalToggleSkin.apply(this, arguments);
  924. };
  925.  
  926. $('#chtbox').keydown(function (event) {
  927. if (event.keyCode === 13) {
  928. var message = $('#chtbox').val();
  929. var command = message.split(' ')[0];
  930. var argument1 = message.split(' ')[1];
  931. var argument2 = message.split(' ')[2];
  932.  
  933. if (command === 'time' || command === '/time') {
  934. var now = new Date();
  935. $('#chtbox').val('Local time: ' + now.toLocaleString()).focus();
  936. }
  937.  
  938. if (command === 'minutes' || command === '/minutes') {
  939. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  940. if (minutes > 60) {
  941. minutes = '' + minutes;
  942. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  943. }
  944. $('#chtbox').val('has played for: ' + minutes + ' Minutes in the current session').focus();
  945. }
  946.  
  947. if (command === 'ping' || command === '/ping') {
  948. window.setFPS(1);
  949. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  950. if (parseInt(ping) > 0) {
  951. if (parseInt(ping) >= 0 && parseInt(ping) < 40) { pingRating = 'Perfect! ✔️'; }
  952. if (parseInt(ping) >= 40 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  953. if (parseInt(ping) >= 70 && parseInt(ping) < 110) { pingRating = 'Acceptable! ✔️'; }
  954. if (parseInt(ping) >= 110 && parseInt(ping) < 150) { pingRating = 'Bad! ❌'; }
  955. if (parseInt(ping) >= 150 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  956. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  957. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  958. } else {
  959. ping = '∞ (infinite) ';
  960. }
  961. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating).focus();
  962. }
  963. if (command === 'fps' || command === '/fps') {
  964. window.setFPS(1);
  965. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  966. if (parseInt(fps) > 0) {
  967. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  968. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  969. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  970. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  971. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  972. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  973. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  974. } else {
  975. fpsRating = '';
  976. }
  977.  
  978. $('#chtbox').val('has ' + fps + ' frames per second (fps). ' + fpsRating).focus();
  979. }
  980.  
  981. if (command === 'timer' || command === '/timer') {
  982. if (argument1) {
  983. timerMinutes = parseInt(argument1);
  984. if (argument2 === 'hours') {
  985. timerMinutes *= 60;
  986. }
  987. if (timeoutId !== null) {
  988. clearTimeout(timeoutId);
  989. }
  990.  
  991. if (argument1 == 0) {
  992. self.message('🗑️ Timer removed');
  993. } else {
  994. timeoutStartedAt = Date.now();
  995. timeoutId = setTimeout(function() {
  996. timeoutId = null;
  997. alert('🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.');
  998. }, timerMinutes * 60 * 1000);
  999.  
  1000. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  1001. }
  1002. } else {
  1003. if (timeoutId === null) {
  1004. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  1005. } else {
  1006. minutes = ((timeoutStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1007. self.message('🕒 ' + Math.round(minutes * 10) / 10 + ' minutes remaining.');
  1008. }
  1009. }
  1010. $('#chtbox').val('').focus();
  1011. }
  1012.  
  1013. var useSkin = function (skinSlot, skinId) {
  1014. if (skinId) {
  1015. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  1016. var skinUri = self.getSkinUrl();
  1017. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  1018. }
  1019.  
  1020. skinId = parseInt(skinId);
  1021. settings.quickSkins[skinSlot - 1] = skinId;
  1022. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  1023. } else {
  1024. skinId = settings.quickSkins[skinSlot - 1];
  1025. if (!skinId) {
  1026. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  1027. $('#chtbox').val('').focus();
  1028. return;
  1029. }
  1030. }
  1031.  
  1032. window.azad(true);
  1033.  
  1034. setTimeout(function () {
  1035. $('#skinExampleMenu').click();
  1036.  
  1037. var checkLoaded = function () {
  1038. var loaded = ($('#skinsFree tr').length > 1);
  1039. if (loaded) {
  1040. window.toggleSkin(skinId);
  1041.  
  1042. setTimeout(function () {
  1043. $('#shopModalDialog button.close').click();
  1044.  
  1045. setTimeout(function () {
  1046. window.setNick(document.getElementById('nick').value);
  1047. }, 200);
  1048. }, 200);
  1049. } else {
  1050. setTimeout(checkLoaded, 300);
  1051. }
  1052. };
  1053. checkLoaded();
  1054. }, 200);
  1055.  
  1056. $('#chtbox').val('').focus();
  1057. };
  1058. if (command === 'skin1' || command === '/skin1') {
  1059. useSkin(1, argument1);
  1060. }
  1061. if (command === 'skin2' || command === '/skin2') {
  1062. useSkin(2, argument1);
  1063. }
  1064. if (command === 'skin3' || command === '/skin3') {
  1065. useSkin(3, argument1);
  1066. }
  1067. if (command === 'skin4' || command === '/skin4') {
  1068. useSkin(4, argument1);
  1069. }
  1070. if (command === 'skin5' || command === '/skin5') {
  1071. useSkin(5, argument1);
  1072. }
  1073. if (command === 'skin6' || command === '/skin6') {
  1074. useSkin(6, argument1);
  1075. }
  1076. if (command === 'skin7' || command === '/skin7') {
  1077. useSkin(7, argument1);
  1078. }
  1079. if (command === 'skin8' || command === '/skin8') {
  1080. useSkin(8, argument1);
  1081. }
  1082. if (command === 'skin9' || command === '/skin9') {
  1083. useSkin(9, argument1);
  1084. }
  1085. if (command === 'skin10' || command === '/skin10') {
  1086. useSkin(10, argument1);
  1087. }
  1088. if (command === 'skin11' || command === '/skin11') {
  1089. useSkin(11, argument1);
  1090. }
  1091. if (command === 'skin12' || command === '/skin12') {
  1092. useSkin(12, argument1);
  1093. }
  1094. if (command === 'skin13' || command === '/skin13') {
  1095. useSkin(13, argument1);
  1096. }
  1097. if (command === 'skin14' || command === '/skin14') {
  1098. useSkin(14, argument1);
  1099. }
  1100. if (command === 'skin15' || command === '/skin15') {
  1101. useSkin(15, argument1);
  1102. }
  1103.  
  1104. if (command === '/solo') {
  1105. $('#chtbox').val('⚠️⚠️⚠️ SOLO SERVER ⚠️⚠️⚠️ No teaming!! No hay equipo!! Kein Teaming!! Pas d\'équipe!!').focus();
  1106. }
  1107.  
  1108. if (command === '/miracle') {
  1109. var miracleInfo = 'is using 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴, version ';
  1110.  
  1111. if (GM_info) {
  1112. miracleInfo += GM_info.script.version;
  1113. } else {
  1114. miracleInfo += 'unknown';
  1115. }
  1116.  
  1117. $('#chtbox').val(miracleInfo).focus();
  1118. }
  1119.  
  1120. if (command.substr(0, 4) === '/say') {
  1121. var fontIndex = command.charAt(4) - 1;
  1122. if (fontIndex == NaN || fontIndex < 0 || fontIndex > Object.getOwnPropertyNames(self.fonts).length - 1) {
  1123. fontIndex = 1;
  1124. }
  1125. $('#chtbox').val(self.useUnicodeFont(message.substr(message.indexOf(' ') + 1), Object.getOwnPropertyNames(self.fonts)[fontIndex])).focus();
  1126. }
  1127.  
  1128. var commandEvent = new Event('miracleCommand');
  1129. commandEvent.message = message;
  1130. commandEvent.command = command;
  1131. commandEvent.argument1 = argument1;
  1132. commandEvent.argument2 = argument2;
  1133. window.dispatchEvent(commandEvent);
  1134. }
  1135. });
  1136. },
  1137.  
  1138. /**
  1139. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  1140. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  1141. */
  1142. fonts: {
  1143. doubleStruck : function(charCode) {
  1144. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  1145. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  1146. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  1147. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  1148. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  1149. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  1150. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  1151. if (charCode >= 65 && charCode <= 90) {
  1152. return String.fromCodePoint(0x1D538 + charCode - 65);
  1153. }
  1154. if (charCode >= 97 && charCode <= 122) {
  1155. return String.fromCodePoint(0x1D552 + charCode - 97);
  1156. }
  1157. if (charCode >= 48 && charCode <= 57) {
  1158. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  1159. }
  1160. return String.fromCharCode(charCode);
  1161. },
  1162.  
  1163. monospace : function(charCode) {
  1164. if (charCode >= 65 && charCode <= 90) {
  1165. return String.fromCodePoint(0x1D670 + charCode - 65);
  1166. }
  1167. if (charCode >= 97 && charCode <= 122) {
  1168. return String.fromCodePoint(0x1D68A + charCode - 97);
  1169. }
  1170. if (charCode >= 48 && charCode <= 57) {
  1171. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  1172. }
  1173. return String.fromCharCode(charCode);
  1174. },
  1175.  
  1176. scriptBold : function(charCode) {
  1177. if (charCode >= 65 && charCode <= 90) {
  1178. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  1179. }
  1180. if (charCode >= 97 && charCode <= 122) {
  1181. return String.fromCodePoint(0x1D4EA + charCode - 97);
  1182. }
  1183. if (charCode >= 48 && charCode <= 57) {
  1184. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1185. }
  1186. return String.fromCharCode(charCode);
  1187. },
  1188.  
  1189. frakturBold : function(charCode) {
  1190. if (charCode >= 65 && charCode <= 90) {
  1191. return String.fromCodePoint(0x1D56C + charCode - 65);
  1192. }
  1193. if (charCode >= 97 && charCode <= 122) {
  1194. return String.fromCodePoint(0x1D586 + charCode - 97);
  1195. }
  1196. if (charCode >= 48 && charCode <= 57) {
  1197. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1198. }
  1199. return String.fromCharCode(charCode);
  1200. },
  1201.  
  1202. serifItalic: function(charCode) {
  1203. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  1204. if (charCode >= 65 && charCode <= 90) {
  1205. return String.fromCodePoint(0x1D434 + charCode - 65);
  1206. }
  1207. if (charCode >= 97 && charCode <= 122) {
  1208. return String.fromCodePoint(0x1D44E + charCode - 97);
  1209. }
  1210. return String.fromCharCode(charCode);
  1211. }
  1212. },
  1213.  
  1214. useUnicodeFont: function(text, font) {
  1215. var converted = '';
  1216. for (var i = 0; i < text.length; i++) {
  1217. converted += this.fonts[font](text.charCodeAt(i));
  1218. }
  1219.  
  1220. return converted;
  1221. },
  1222.  
  1223. /**
  1224. * Returns a random number between min (inclusive) and max (exclusive)
  1225. * Source: MDN
  1226. */
  1227. getRandomArbitrary: function (min, max) {
  1228. return Math.random() * (max - min) + min;
  1229. },
  1230.  
  1231. /**
  1232. * Use the curser div to display a message at the top of the screen.
  1233. *
  1234. * @param message
  1235. * @param isError
  1236. */
  1237. message: function (message, isError) {
  1238. var curser = document.querySelector('#curser');
  1239.  
  1240. curser.textContent = message;
  1241. curser.style.display = 'block';
  1242. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  1243.  
  1244. window.setTimeout(function () {
  1245. curser.style.display = 'none';
  1246. }, 5000);
  1247. },
  1248.  
  1249. /**
  1250. * Returns the URI of my skin or null if not skin has been set.
  1251. * Use this.skinUrl() to get it.
  1252. */
  1253. getSkinUrl: function() {
  1254. var skinUrlRaw = $('#skinExampleMenu').css('background-image');
  1255.  
  1256. var parts = skinUrlRaw.split('"');
  1257.  
  1258. if (parts.length != 3) {
  1259. return null;
  1260. } else {
  1261. return parts[1];
  1262. }
  1263. },
  1264.  
  1265. setupPolyfills: function() {
  1266. // Polyfill for old browser so they have String.fromCodePoint()
  1267. if (!String.fromCodePoint) (function(stringFromCharCode) {
  1268. var fromCodePoint = function(_) {
  1269. var codeUnits = [], codeLen = 0, result = "";
  1270. for (var index=0, len = arguments.length; index !== len; ++index) {
  1271. var codePoint = +arguments[index];
  1272. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  1273. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  1274. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  1275. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  1276. throw RangeError("Invalid code point: " + codePoint);
  1277. if (codePoint <= 0xFFFF) { // BMP code point
  1278. codeLen = codeUnits.push(codePoint);
  1279. } else { // Astral code point; split in surrogate halves
  1280. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  1281. codePoint -= 0x10000;
  1282. codeLen = codeUnits.push(
  1283. (codePoint >> 10) + 0xD800, // highSurrogate
  1284. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  1285. );
  1286. }
  1287. if (codeLen >= 0x3fff) {
  1288. result += stringFromCharCode.apply(null, codeUnits);
  1289. codeUnits.length = 0;
  1290. }
  1291. }
  1292. return result + stringFromCharCode.apply(null, codeUnits);
  1293. };
  1294. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  1295. Object.defineProperty(String, "fromCodePoint", {
  1296. "value": fromCodePoint, "configurable": true, "writable": true
  1297. });
  1298. } catch(e) {
  1299. String.fromCodePoint = fromCodePoint;
  1300. }
  1301. }(String.fromCharCode));
  1302. },
  1303. };
  1304.  
  1305. window.miracleScripts.init();
  1306. })();