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