Miracle Scripts

Let your cell spin, jump, shake, flip and wacky! Copy & paste custom emojis to the chatbox! Dance! Use Chat replacements! Display the time!

目前为 2019-12-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 1.5.0
  5. // @description Let your cell spin, jump, shake, flip and wacky! Copy & paste custom emojis to the chatbox! Dance! Use Chat replacements! Display the time!
  6. // @homepage http://agarioforums.net/member.php?action=profile&uid=21263
  7. // @author You
  8. // @license MIT
  9. // @icon https://abload.de/img/mh3k8o.png
  10. // @match http://agma.io/
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Source: http://stackoverflow.com/questions/1772179/get-character-value-from-keycode-in-javascript-then-trim#answer-23377822
  15. window.keyboardMap = [
  16. "", // [0]
  17. "", // [1]
  18. "", // [2]
  19. "CANCEL", // [3]
  20. "", // [4]
  21. "", // [5]
  22. "HELP", // [6]
  23. "", // [7]
  24. "BACK_SPACE", // [8]
  25. "TAB", // [9]
  26. "", // [10]
  27. "", // [11]
  28. "CLEAR", // [12]
  29. "ENTER", // [13]
  30. "ENTER_SPECIAL", // [14]
  31. "", // [15]
  32. "SHIFT", // [16]
  33. "CONTROL", // [17]
  34. "ALT", // [18]
  35. "PAUSE", // [19]
  36. "CAPS_LOCK", // [20]
  37. "KANA", // [21]
  38. "EISU", // [22]
  39. "JUNJA", // [23]
  40. "FINAL", // [24]
  41. "HANJA", // [25]
  42. "", // [26]
  43. "ESCAPE", // [27]
  44. "CONVERT", // [28]
  45. "NONCONVERT", // [29]
  46. "ACCEPT", // [30]
  47. "MODECHANGE", // [31]
  48. "SPACE", // [32]
  49. "PAGE_UP", // [33]
  50. "PAGE_DOWN", // [34]
  51. "END", // [35]
  52. "HOME", // [36]
  53. "LEFT", // [37]
  54. "UP", // [38]
  55. "RIGHT", // [39]
  56. "DOWN", // [40]
  57. "SELECT", // [41]
  58. "PRINT", // [42]
  59. "EXECUTE", // [43]
  60. "PRINTSCREEN", // [44]
  61. "INSERT", // [45]
  62. "DELETE", // [46]
  63. "", // [47]
  64. "0", // [48]
  65. "1", // [49]
  66. "2", // [50]
  67. "3", // [51]
  68. "4", // [52]
  69. "5", // [53]
  70. "6", // [54]
  71. "7", // [55]
  72. "8", // [56]
  73. "9", // [57]
  74. "COLON", // [58]
  75. "SEMICOLON", // [59]
  76. "LESS_THAN", // [60]
  77. "EQUALS", // [61]
  78. "GREATER_THAN", // [62]
  79. "QUESTION_MARK", // [63]
  80. "AT", // [64]
  81. "A", // [65]
  82. "B", // [66]
  83. "C", // [67]
  84. "D", // [68]
  85. "E", // [69]
  86. "F", // [70]
  87. "G", // [71]
  88. "H", // [72]
  89. "I", // [73]
  90. "J", // [74]
  91. "K", // [75]
  92. "L", // [76]
  93. "M", // [77]
  94. "N", // [78]
  95. "O", // [79]
  96. "P", // [80]
  97. "Q", // [81]
  98. "R", // [82]
  99. "S", // [83]
  100. "T", // [84]
  101. "U", // [85]
  102. "V", // [86]
  103. "W", // [87]
  104. "X", // [88]
  105. "Y", // [89]
  106. "Z", // [90]
  107. "OS_KEY", // [91] Windows Key (Windows) or Command Key (Mac)
  108. "", // [92]
  109. "CONTEXT_MENU", // [93]
  110. "", // [94]
  111. "SLEEP", // [95]
  112. "NUMPAD0", // [96]
  113. "NUMPAD1", // [97]
  114. "NUMPAD2", // [98]
  115. "NUMPAD3", // [99]
  116. "NUMPAD4", // [100]
  117. "NUMPAD5", // [101]
  118. "NUMPAD6", // [102]
  119. "NUMPAD7", // [103]
  120. "NUMPAD8", // [104]
  121. "NUMPAD9", // [105]
  122. "MULTIPLY", // [106]
  123. "ADD", // [107]
  124. "SEPARATOR", // [108]
  125. "SUBTRACT", // [109]
  126. "DECIMAL", // [110]
  127. "DIVIDE", // [111]
  128. "F1", // [112]
  129. "F2", // [113]
  130. "F3", // [114]
  131. "F4", // [115]
  132. "F5", // [116]
  133. "F6", // [117]
  134. "F7", // [118]
  135. "F8", // [119]
  136. "F9", // [120]
  137. "F10", // [121]
  138. "F11", // [122]
  139. "F12", // [123]
  140. "F13", // [124]
  141. "F14", // [125]
  142. "F15", // [126]
  143. "F16", // [127]
  144. "F17", // [128]
  145. "F18", // [129]
  146. "F19", // [130]
  147. "F20", // [131]
  148. "F21", // [132]
  149. "F22", // [133]
  150. "F23", // [134]
  151. "F24", // [135]
  152. "", // [136]
  153. "", // [137]
  154. "", // [138]
  155. "", // [139]
  156. "", // [140]
  157. "", // [141]
  158. "", // [142]
  159. "", // [143]
  160. "NUM_LOCK", // [144]
  161. "SCROLL_LOCK", // [145]
  162. "WIN_OEM_FJ_JISHO", // [146]
  163. "WIN_OEM_FJ_MASSHOU", // [147]
  164. "WIN_OEM_FJ_TOUROKU", // [148]
  165. "WIN_OEM_FJ_LOYA", // [149]
  166. "WIN_OEM_FJ_ROYA", // [150]
  167. "", // [151]
  168. "", // [152]
  169. "", // [153]
  170. "", // [154]
  171. "", // [155]
  172. "", // [156]
  173. "", // [157]
  174. "", // [158]
  175. "", // [159]
  176. "CIRCUMFLEX", // [160]
  177. "EXCLAMATION", // [161]
  178. "DOUBLE_QUOTE", // [162]
  179. "HASH", // [163]
  180. "DOLLAR", // [164]
  181. "PERCENT", // [165]
  182. "AMPERSAND", // [166]
  183. "UNDERSCORE", // [167]
  184. "OPEN_PAREN", // [168]
  185. "CLOSE_PAREN", // [169]
  186. "ASTERISK", // [170]
  187. "PLUS", // [171]
  188. "PIPE", // [172]
  189. "HYPHEN_MINUS", // [173]
  190. "OPEN_CURLY_BRACKET", // [174]
  191. "CLOSE_CURLY_BRACKET", // [175]
  192. "TILDE", // [176]
  193. "", // [177]
  194. "", // [178]
  195. "", // [179]
  196. "", // [180]
  197. "VOLUME_MUTE", // [181]
  198. "VOLUME_DOWN", // [182]
  199. "VOLUME_UP", // [183]
  200. "", // [184]
  201. "", // [185]
  202. "SEMICOLON", // [186]
  203. "EQUALS", // [187]
  204. "COMMA", // [188]
  205. "MINUS", // [189]
  206. "PERIOD", // [190]
  207. "SLASH", // [191]
  208. "BACK_QUOTE", // [192]
  209. "", // [193]
  210. "", // [194]
  211. "", // [195]
  212. "", // [196]
  213. "", // [197]
  214. "", // [198]
  215. "", // [199]
  216. "", // [200]
  217. "", // [201]
  218. "", // [202]
  219. "", // [203]
  220. "", // [204]
  221. "", // [205]
  222. "", // [206]
  223. "", // [207]
  224. "", // [208]
  225. "", // [209]
  226. "", // [210]
  227. "", // [211]
  228. "", // [212]
  229. "", // [213]
  230. "", // [214]
  231. "", // [215]
  232. "", // [216]
  233. "", // [217]
  234. "", // [218]
  235. "OPEN_BRACKET", // [219]
  236. "BACK_SLASH", // [220]
  237. "CLOSE_BRACKET", // [221]
  238. "QUOTE", // [222]
  239. "", // [223]
  240. "META", // [224]
  241. "ALTGR", // [225]
  242. "", // [226]
  243. "WIN_ICO_HELP", // [227]
  244. "WIN_ICO_00", // [228]
  245. "", // [229]
  246. "WIN_ICO_CLEAR", // [230]
  247. "", // [231]
  248. "", // [232]
  249. "WIN_OEM_RESET", // [233]
  250. "WIN_OEM_JUMP", // [234]
  251. "WIN_OEM_PA1", // [235]
  252. "WIN_OEM_PA2", // [236]
  253. "WIN_OEM_PA3", // [237]
  254. "WIN_OEM_WSCTRL", // [238]
  255. "WIN_OEM_CUSEL", // [239]
  256. "WIN_OEM_ATTN", // [240]
  257. "WIN_OEM_FINISH", // [241]
  258. "WIN_OEM_COPY", // [242]
  259. "WIN_OEM_AUTO", // [243]
  260. "WIN_OEM_ENLW", // [244]
  261. "WIN_OEM_BACKTAB", // [245]
  262. "ATTN", // [246]
  263. "CRSEL", // [247]
  264. "EXSEL", // [248]
  265. "EREOF", // [249]
  266. "PLAY", // [250]
  267. "ZOOM", // [251]
  268. "", // [252]
  269. "PA1", // [253]
  270. "WIN_OEM_CLEAR", // [254]
  271. "" // [255]
  272. ];
  273.  
  274. // Don't remove the spaces, they are used as seperators! Source: https://emojiterra.com/de/liste/
  275. window.emojis = '😀 😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😗 ☺️ 😚 😙 😋 😛 😜 😝 😐 😑 😶 😏 😒 😬 😌 😔 😪 😴 😷 😵 😎 😕 😟 😮 😯 😲 😳 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤 😡 😠 😈 👿 💀 💩 👹 👺 👻 👽 👾 😺 😸 😹 😻 😼 😽 🙀 😿 😾 🙈 🙉 🙊 💋 💌 💘 💝 💖 💗 💓 💞 💕 💟 💔 ❤️ 💛 💚 💙 💜 💯 💢 💥 💫 💦 💨 💣 💬 💭 💤 👋 ✋ 👌 ✌️ 👈 👉 👆 👇 ☝️ 👍 👎 ✊ 👊 👏 🙌 👐 🙏 💅 💪 👂 👃 👀 👅 👄 👶 👦 👧 👱 👨 👩 👴 👵 🙍 🙎 🙅 🙆 💁 🙋 🙇 👮 💂 👷 👸 👳 👲 👰 👼 🎅 💆 💇 🚶 🏃 💃 👯 🏇 🏂 🏄 🚣 🏊 🚴 🚵 🛀 👭 👫 👬 💏 💑 👪 👤 👥 👣 🐵 🐒 🐶 🐕 🐩 🐺 🐱 🐈 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇 🐻 🐨 🐼 🐾 🐔 🐓 🐣 🐤 🐥 🐦 🐧 🐸 🐊 🐢 🐍 🐲 🐉 🐳 🐋 🐬 🐟 🐠 🐡 🐙 🐚 🐌 🐛 🐜 🐝 🐞 💐 🌸 💮 🌹 🌺 🌻 🌼 🌷 🌱 🌲 🌳 🌴 🌵 🌾 🌿 🍀 🍁 🍂 🍃 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍅 🍆 🌽 🍄 🌰 🍞 🍖 🍗 🍔 🍟 🍕 🍳 🍲 🍱 🍘 🍙 🍚 🍛 🍜 🍝 🍠 🍢 🍣 🍤 🍥 🍡 🍦 🍧 🍨 🍩 🍪 🎂 🍰 🍫 🍬 🍭 🍮 🍯 🍼 ☕ 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍴 🔪 🌍 🌎 🌏 🌐 🗾 🌋 🗻 🏠 🏡 🏢 🏣 🏤 🏥 🏦 🏨 🏩 🏪 🏫 🏬 🏭 🏯 🏰 💒 🗼 🗽 ⛪ ⛲ ⛺ 🌁 🌃 🌄 🌅 🌆 🌇 🌉 ♨️ 🎠 🎡 🎢 💈 🎪 🚂 🚃 🚄 🚅 🚆 🚇 🚈 🚉 🚊 🚝 🚞 🚋 🚌 🚍 🚎 🚐 🚑 🚒 🚓 🚔 🚕 🚖 🚗 🚘 🚙 🚚 🚛 🚜 🚲 🚏 ⛽ 🚨 🚥 🚦 🚧 ⚓ ⛵ 🚤 🚢 ✈️ 💺 🚁 🚟 🚠 🚡 🚀 ⌛ ⏳ ⌚ ⏰ 🕛 🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 ☀️ 🌝 🌞 ⭐ 🌟 🌠 🌌 ☁️ ⛅ 🌀 🌈 🌂 ☔ ⚡ ❄️ ⛄ 🔥 💧 🌊 🎃 🎄 🎆 🎇 ✨ 🎈 🎉 🎊 🎋 🎍 🎎 🎏 🎐 🎑 🎀 🎁 🎫 🏆 ⚽ ⚾ 🏀 🏈 🏉 🎾 🎳 ⛳ 🎣 🎽 🎿 🎯 🎱 🔮 🎮 🎰 🎲 ♠️ ♥️ ♦️ ♣️ 🃏 🀄 🎴 🎭 🎨 👓 👔 👕 👖 👗 👘 👙 👚 👛 👜 👝 🎒 👞 👟 👠 👡 👢 👑 👒 🎩 🎓 💄 💍 💎 🔇 🔈 🔉 🔊 📢 📣 📯 🔔 🔕 🎼 🎵 🎶 🎤 🎧 📻 🎷 🎸 🎹 🎺 🎻 📱 📲 ☎️ 📞 📟 📠 🔋 🔌 💻 💽 💾 💿 📀 🎥 🎬 📺 📷 📹 📼 🔍 🔎 💡 🔦 🏮 📔 📕 📖 📗 📘 📙 📚 📓 📒 📃 📜 📄 📰 📑 🔖 💰 💴 💵 💶 💷 💸 💳 💹 💱 💲 ✉️ 📧 📨 📩 📤 📥 📦 📫 📪 📬 📭 📮 ✏️ ✒️ 📝 💼 📁 📂 📅 📆 📇 📈 📉 📊 📋 📌 📍 📎 📏 📐 ✂️ 🔒 🔓 🔏 🔐 🔑 🔨 🔫 🔧 🔩 🔗 🔬 🔭 📡 💉 💊 🚪 🚽 🚿 🛁 🚬 🗿 🏧 🚮 🚰 ♿ 🚹 🚺 🚻 🚼 🚾 🛂 🛃 🛄 🛅 ⚠️ 🚸 ⛔ 🚫 🚳 🚭 🚯 🚱 🚷 📵 🔞 ⬆️ ↗️ ➡️ ↘️ ⬇️ ↙️ ⬅️ ↖️ ↕️ ↔️ 🔃 🔄 🔙 🔚 🔛 🔜 🔝 🔯 ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ⛎ 🔀 🔁 🔂 ▶️ ◀️ 🔼 🔽 🎦 📶 📳 📴 ♻️ 🔱 📛 🔰 ⭕ ✅ ☑️ ✖️ ❌ ❎ ➕ ➖ ➗ ➰ ➿ 〽️ ✳️ ✴️ ❇️ ‼️ ⁉️ ❓ ❔ ❕ ❗ 〰️ ©️ ®️ ™️ 🔠 🔡 🔢 🔣 🔤 🅰️ 🆎 🅱️ 🆑 🆒 🆓 🆔 Ⓜ️ 🆕 🆖 🅾️ 🆗 🅿️ 🆘 🆙 🆚 🈁 🈂️ 🈷️ 🈶 🈯 🉐 🈹 🈚 🈲 🉑 🈸 🈴 🈳 ㊗️ ㊙️ 🈺 🈵 🔴 🔵 ⚫ ⚪ ⬛ ⬜ ◼️ ◻️ ◾ ◽ ▪️ ▫️ 🔶 🔷 🔸 🔹 🔺 🔻 💠 🔘 🔳 🔲 🏁 🚩 🎌';
  276.  
  277. (function() {
  278. 'use strict';
  279.  
  280. var settings = localStorage.getItem('miracleScripts');
  281.  
  282. var defaultSettings = {
  283. // To get keycodes: https://keycode.info
  284. bindings: {
  285. animation: 17, // CRTL
  286. paste: 33, // PAGE UP
  287. dance: 34, // PAGE DOWN,
  288. chatLog: 76, // L
  289. },
  290. replacements: ":D|:smile:\n:*(|:sob:\n:'D|:sweat_smiley:",
  291. primaryColor: "#FF69B4",
  292. favSkins: [],
  293. };
  294.  
  295. if (settings == null) {
  296. settings = defaultSettings;
  297. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  298. } else {
  299. settings = JSON.parse(settings);
  300.  
  301. // Update for settigns:
  302. if (typeof settings.primaryColor === 'undefined') {
  303. settings.primaryColor = defaultSettings.primaryColor;
  304. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  305. }
  306. if (typeof settings.bindings.chatLog === 'undefined') {
  307. settings.bindings.chatLog = defaultSettings.bindings.chatLog;
  308. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  309. }
  310. if (typeof settings.favSkins === 'undefined') {
  311. settings.favSkins = defaultSettings.favSkins;
  312. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  313. }
  314. }
  315.  
  316. var applyPrimaryColor = function() {
  317. var primaryColorCss = '.miracle-primary-color-font { color: ' + settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + settings.primaryColor + ' !important }; ';
  318. $('body').append('<style>' + primaryColorCss + '</style>');
  319. };
  320. applyPrimaryColor();
  321.  
  322. // We need to have a delay, because the menu is not laoded right away
  323. setTimeout(function() {
  324. var $playButton = $('#playBtn');
  325. var $specateButton = $('#spectateBtn');
  326.  
  327. $playButton.get(0).style.width = '40%';
  328. $specateButton.get(0).style.width = '40%';
  329.  
  330. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">⚙️</button>');
  331. $settingsButton.insertAfter($playButton);
  332.  
  333. var changeKey = function(event) {
  334. var name = this.name.substr(4);
  335. $(this).val(window.keyboardMap[event.keyCode]);
  336. settings.bindings[name] = event.keyCode;
  337. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  338. };
  339.  
  340. // Weird Agma scripting... press enter in the replacements textarea and the chatbox gets focused!
  341. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  342. // focus again (delayed) and go to the end of the text where the linebreak is.
  343. // We can improve this later on...
  344. var addReturn = function(event) {
  345. if (event.keyCode == 13) {
  346. var textarea = this;
  347. $(textarea).text($(this).text() + '\n').focus();
  348. setTimeout(function(){
  349. $(textarea).focus();
  350. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  351. }, 1);
  352. }
  353. };
  354. var changeReplacements = function(event) {
  355. settings.replacements = $(this).val();
  356. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  357. };
  358. var changePrimaryColor = function(event) {
  359. settings.primaryColor = $(this).val();
  360. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  361. applyPrimaryColor();
  362. };
  363.  
  364. 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>');
  365. $modal.append('<h1>Miracle Scripts Settings</h1>');
  366. $modal.append('<small style="color: #717171">This script does not work on mobile devices! Support: <a href="http://agarioforums.net/showthread.php?tid=61388" target="_blank" style="color: #717171">agarioforums.net</small>');
  367. var $element = $('<input name="key_animation" value="' + window.keyboardMap[settings.bindings.animation] + '"/>').keyup(changeKey);
  368. $modal.append('<br><br>Animation-Key:<br>', $element);
  369. $element = $('<input name="key_paste" value="' + window.keyboardMap[settings.bindings.paste] + '"/>').keyup(changeKey);
  370. $modal.append('<br>Paste-Key:<br>', $element);
  371. $element = $('<input name="key_dance" value="' + window.keyboardMap[settings.bindings.dance] + '"/>').keyup(changeKey);
  372. $modal.append('<br>Dance-Key:<br>', $element);
  373. $element = $('<input name="key_chatLog" value="' + window.keyboardMap[settings.bindings.chatLog] + '"/>').keyup(changeKey);
  374. $modal.append('<br>Chat-Log-Key:<br>', $element);
  375. $element = $('<input type="color" name="favcolor" value="' + settings.primaryColor + '"/>').change(changePrimaryColor);
  376. $modal.append('<br><br>Primary color:<br>', $element);
  377. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" palceholder="search|replace">').text(settings.replacements).keydown(addReturn).keyup(changeReplacements);
  378. $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>');
  379. $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() { $modal.hide() }));
  380.  
  381. $('body').append($modal);
  382.  
  383. $settingsButton.click(function(event)
  384. {
  385. $modal.show();
  386.  
  387. event.preventDefault();
  388. });
  389. }, 500);
  390. })();
  391.  
  392.  
  393. (function() {
  394. 'use strict';
  395.  
  396. /**
  397. * Returns a random number between min (inclusive) and max (exclusive)
  398. * Source: MDN
  399. */
  400. var getRandomArbitrary = function(min, max) {
  401. return Math.random() * (max - min) + min;
  402. }
  403.  
  404. var chatAnimate = function()
  405. {
  406. // The available commands
  407. var items = ['wacky',
  408. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  409. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  410. 'shake', 'shakeshake','shakeshakeshake','wackyshake','wackyshakeshake','wackyshakeshakeshake',
  411. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump'];
  412.  
  413. // Choose randomly an item of the items array
  414. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  415. var item = items[Math.floor(Math.random() * items.length)];
  416.  
  417. item += String.fromCharCode(8203).repeat(getRandomArbitrary(1, 5));
  418.  
  419. // Add text into the chatbox and focus it (Note: acutally "/" is no longer necessary)
  420. $('#chtbox').val($('#chtbox').val() + item).focus();
  421.  
  422. // Stop the event so that the pressed key won't be written into the chatbox!
  423. event.preventDefault();
  424. }
  425.  
  426. window.addEventListener('keydown', function(event)
  427. {
  428. // Do nothing if a menu is open
  429. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  430. return;
  431. }
  432.  
  433. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  434.  
  435. if (event.keyCode == settings.bindings.animation) {
  436. chatAnimate();
  437.  
  438. event.keyCode = 13;
  439.  
  440. }
  441. });
  442. })();
  443.  
  444.  
  445. (function() {
  446. 'use strict';
  447.  
  448. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  449. 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' +
  450. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  451.  
  452. var emojis = window.emojis.split(' ');
  453. var emojiCode = '';
  454.  
  455. emojis.forEach(function(emoji) {
  456. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  457. });
  458.  
  459. var addEmoji = function()
  460. {
  461. setTimeout(function(){
  462. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  463.  
  464. // Add text into the chatbox and focus it
  465. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  466. }, 200);
  467.  
  468. $modal.hide();
  469. };
  470.  
  471. 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>');
  472. $modal.append('<style>' + css + '</style>');
  473. $modal.append('<h1>Insert text or emoji</h1>');
  474. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  475. $modal.append('<br><br>Insert:<br>', $pasteInput);
  476. $modal.html($modal.html() + '<br><br>' + emojiCode);
  477. $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));
  478. $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() { $modal.hide() }));
  479.  
  480. $modal.find('input[name=paste]').click(function(event)
  481. {
  482. var text = prompt('Please paste your text here!');
  483.  
  484. if (text !== null) {
  485. var $pasteInput = $modal.find('input[name=paste]');
  486. // Add text into the paste input
  487. $pasteInput.val($pasteInput.val() + text);
  488. }
  489. });
  490.  
  491. $modal.click(function(event)
  492. {
  493. if (event.target.classList.contains('miracle-emoji')) {
  494. var $target = $(this).find('input[name=paste]');
  495. $target.val($target.val() + $(event.target).text());
  496.  
  497. event.preventDefault();
  498. }
  499. });
  500.  
  501. $modal.dblclick(function(event)
  502. {
  503. if (event.target.classList.contains('miracle-emoji')) {
  504. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  505. $(this).hide();
  506.  
  507. event.preventDefault();
  508. }
  509. });
  510.  
  511. $('body').append($modal);
  512.  
  513. window.addEventListener('keydown', function(event)
  514. {
  515. // Do nothing if a menu is open
  516. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  517. return;
  518. }
  519.  
  520. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  521.  
  522. if (event.keyCode == settings.bindings.paste) {
  523. $modal.find('input[name=paste]').val('');
  524. $modal.show();
  525. }
  526. });
  527. })();
  528.  
  529.  
  530. (function() {
  531. 'use strict';
  532.  
  533. var angle = 0;
  534. var angleSpeed = 20;
  535. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  536. var dancing = false;
  537.  
  538. //window.$mousePointer = $('<div style="background-color: red; width: 10px; height: 10px; position: fixed; z-index: 9999">');
  539. //$('body').append(window.$mousePointer);
  540.  
  541. var dance = function()
  542. {
  543. angle += angleSpeed;
  544. if (angle > 360) {
  545. angle = 0;
  546. }
  547.  
  548. var x = window.innerWidth/2 + Math.sin(angle * Math.PI / 180) * distance;
  549. var y = window.innerHeight/2 + Math.cos(angle * Math.PI / 180) * distance;
  550. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  551.  
  552. //window.$mousePointer.css({
  553. // left: x, top: y
  554. //});
  555.  
  556. // Stop dancing if dying ... to avoid continuing dancing after next respawn
  557. if (document.getElementById('advert').style.display != 'none') {
  558. dancing = false;
  559. }
  560. if (dancing) {
  561. window.requestAnimationFrame(dance);
  562. }
  563. }
  564.  
  565. window.addEventListener('keyup', function()
  566. {
  567. // Do nothing if a menu is open
  568. if (document.getElementById('overlays').style.display != 'none' || document.getElementById('advert').style.display != 'none') {
  569. return;
  570. }
  571.  
  572. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  573.  
  574. if (event.keyCode == settings.bindings.dance) {
  575. dancing = ! dancing;
  576.  
  577. if (dancing) {
  578. window.requestAnimationFrame(dance);
  579. }
  580. }
  581. });
  582. })();
  583.  
  584.  
  585. (function() {
  586. 'use strict';
  587.  
  588. $('#chtbox').keyup(function(event)
  589. {
  590. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  591.  
  592. var lines = settings.replacements.split('\n');
  593.  
  594. var text = $('#chtbox').val();
  595.  
  596. lines.forEach(function(line) {
  597. var replacement = line.split('|');
  598. if (replacement.length == 2) {
  599. text = text.replace(replacement[0], replacement[1]);
  600. $('#chtbox').val(text).focus();
  601. }
  602. });
  603. });
  604. })();
  605.  
  606.  
  607. (function() {
  608. 'use strict';
  609.  
  610. // We escape the message before we print them, so no one can inject JS code!
  611. var htmlEntities = function(str) {
  612. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  613. }
  614.  
  615. var originalFillText = CanvasRenderingContext2D.prototype.fillText
  616. var lastChatNickname = null;
  617. var lastChatNicknameColor = null;
  618. var chatLogCode = '';
  619. var chatLog = [];
  620. CanvasRenderingContext2D.prototype.fillText = function () {
  621. if (this.canvas.id != 'leaderboard' && this.canvas.height == 23) {
  622. var text = arguments[0];
  623.  
  624. // Sometimes also numbers (int) are printed so we filter for strings
  625. if (typeof text == "string" && (this.fillStyle != "#f5f6ce" && this.fillStyle !== "#444444")) {
  626. // Dirty fix for the missing icon in the initial welcome messages
  627. if (text == '') {
  628. text = '📢';
  629. }
  630. lastChatNickname = text;
  631. lastChatNicknameColor = this.fillStyle;
  632. }
  633. if (typeof text == "string" && (this.fillStyle == "#f5f6ce" || this.fillStyle == "#444444")) {
  634. // Unfortunately chat messages will be printed more than just once and I don't know
  635. // how to identifiy them, so for now all messages will be stored and only new messages will be shown.
  636. // Ofcourse this means messages won't be shown if they are sned more than once (by the same nickname).
  637. var found = false;
  638. for (var i = 0; i < chatLog.length; i++) {
  639. if (chatLog[i].nickname == lastChatNickname && chatLog[i].nicknameColor == lastChatNicknameColor && chatLog[i].message == text) {
  640. found = true;
  641. break;
  642. };
  643. }
  644.  
  645. if (! found) {
  646. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  647. chatLogCode += '<div><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  648. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  649. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  650. }
  651. }
  652. }
  653.  
  654. return originalFillText.apply(this, arguments);
  655. }
  656.  
  657. var performSearch = function(searchElement) {
  658. var subject = searchElement.value.toLowerCase();
  659.  
  660. $('#miracle-complete-chatlog div').each(function(a,b,c) {
  661. var $entry = $(this);
  662.  
  663. if ($entry.text().toLowerCase().indexOf(subject) == -1 && subject != '') {
  664. $entry.hide()
  665. } else {
  666. $entry.show()
  667. }
  668. });
  669. }
  670.  
  671. 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>');
  672. $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>');
  673. $modal.append('<h1>Complete chatlog</h1><br>');
  674. $modal.append('<div id="miracle-complete-chatlog"></div>');
  675. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function(event) { performSearch(this) }));
  676. $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() { $modal.hide() }));
  677. $('body').append($modal);
  678.  
  679. $('#miracle-complete-chatlog').dblclick(function() {
  680. var $clickTarget = null;
  681.  
  682. // Each chat message is a div with spans in it. Eitehr the spans or the div might be clicked.
  683. if (event.target.tagName.toLowerCase() == 'span') {
  684. $clickTarget = $(event.target).parent();
  685. } else {
  686. $clickTarget = $(event.target);
  687. }
  688.  
  689. var message = $clickTarget.find('.message').text();
  690.  
  691. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  692. if (message.substr(0, 2) == ': ') {
  693. message = message.substr(2);
  694. }
  695.  
  696. window.open('https://www.deepl.com/translator#en/en/' + message);
  697. });
  698.  
  699. window.addEventListener('keyup', function()
  700. {
  701. // Ignore text input field so typing in them is possible
  702. if (document.activeElement.type == 'text') {
  703. return;
  704. }
  705.  
  706. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  707.  
  708. if (event.keyCode == settings.bindings.chatLog) {
  709. $('#miracle-complete-chatlog').html(chatLogCode);
  710. $modal.toggle();
  711. $modal.get(0).scrollTo(0,$modal.get(0).scrollHeight);
  712. }
  713. });
  714. })();
  715.  
  716.  
  717. (function() {
  718. 'use strict';
  719.  
  720. // We need to have a delay, because the menu is not laoded right away
  721. setTimeout(function() {
  722. console.log('Fav Skin module started.');
  723.  
  724. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  725.  
  726. var favIconClick = function() {
  727. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  728.  
  729. if (settings.favSkins.includes(id)) {
  730. $(this).addClass('skin-not-fav');
  731. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  732. var index = settings.favSkins.indexOf(id);
  733. settings.favSkins.splice(index, 1);
  734. } else {
  735. $(this).removeClass('skin-not-fav');
  736. settings.favSkins.push(id);
  737. }
  738. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  739. renderFavSkins();
  740. };
  741.  
  742. var renderFavSkins = function() {
  743. var $skins = null;
  744.  
  745. if ($('#fav-skins').length > 0) {
  746. $skins = $('#fav-skins');
  747. $skins.html('');
  748. } else {
  749. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  750. $skins.insertAfter('#publicSkinsHeader');
  751.  
  752. $('#fav-skins').click(function(event) {
  753. if (event.target.tagName.toLowerCase() == 'span') {
  754. favIconClick.apply(event.target);
  755. }
  756. });
  757. }
  758. settings.favSkins.forEach(function(id) {
  759. $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>⭐</span></h4><button class="btn btn-primary skinuse-btn" onclick="toggleSkin(' + id + ');">Use</button></div>');
  760. });
  761. $skins.append('<div style="clear: both"></div>');
  762. };
  763.  
  764. var addFavIcons = function() {
  765. var $skins = $('#publicSkinsPage');
  766. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  767.  
  768. $skins.find('h4').each(function() {
  769. var $favIcon = $('<span>⭐</span>');
  770. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  771.  
  772. $favIcon.click(favIconClick);
  773.  
  774. $(this).append($favIcon);
  775.  
  776. if (! settings.favSkins.includes(id)) {
  777. $favIcon.addClass('skin-not-fav');
  778. }
  779. });
  780. }
  781. var initialized = false;
  782. $('#skinsCustomTab').click(function() {
  783. if (! initialized) {
  784. var checkState = function() {
  785. if ($('#publicSkinsPage').html() != '') {
  786. addFavIcons();
  787. renderFavSkins();
  788. } else {
  789. setTimeout(checkState, 30);
  790. }
  791. };
  792. checkState();
  793. initialized = true;
  794. }
  795. });
  796. $('#phpSkins').click(function(event) {
  797. if (event.target.classList.contains('publicskins-nav-btn')) {
  798. addFavIcons();
  799. }
  800. });
  801.  
  802. }, 500);
  803. })();
  804.  
  805.  
  806. (function() {
  807. 'use strict';
  808.  
  809. $('#chtbox').keydown(function(event)
  810. {
  811. if (event.keyCode == 13 && $('#chtbox').val() == 'time') {
  812. var now = new Date();
  813. $('#chtbox').val('Local time: '+ now.toLocaleString()).focus();
  814. }
  815. });
  816. })();
  817.  
  818.  
  819. console.log('🌸 Miracle Scripts successfully loaded!');