Miracle Scripts

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

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

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