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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址