Miracle Scripts

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

目前为 2020-02-09 提交的版本。查看 最新版本

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