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
  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. // All available commands and combinations
  487. var items = ['wacky',
  488. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  489. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  490. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake', 'wackyshakeshakeshake',
  491. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump',
  492. ];
  493.  
  494. // Super-combinations!!
  495. if (self.getRandomArbitrary(1, 3) === 1) {
  496. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  497. }
  498.  
  499. // Choose randomly an item of the items array
  500. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  501. var item = items[Math.floor(Math.random() * items.length)];
  502.  
  503. // Attempt to avoid triggering spam protection - probably useless :-/
  504. item += String.fromCharCode(8203).repeat(self.getRandomArbitrary(1, 5));
  505.  
  506. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  507. $('#chtbox').val($('#chtbox').val() + item).focus();
  508.  
  509. // Stop the event so that the pressed key won't be written into the chat box!
  510. event.preventDefault();
  511. };
  512.  
  513. window.addEventListener('keydown', function (event) {
  514. // Do nothing if a menu is open
  515. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  516. return;
  517. }
  518.  
  519. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  520.  
  521. if (event.keyCode == settings.bindings.animation) {
  522. chatAnimate();
  523. }
  524. });
  525. },
  526.  
  527. paste: function () {
  528. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  529. 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' +
  530. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  531.  
  532. var emojis = this.emojis.split(' ');
  533. var emojiCode = '';
  534.  
  535. emojis.forEach(function (emoji) {
  536. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  537. });
  538.  
  539. var addEmoji = function () {
  540. setTimeout(function () {
  541. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  542.  
  543. // Add text into the chatbox and focus it
  544. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  545. }, 200);
  546.  
  547. $modal.hide();
  548. };
  549.  
  550. 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>');
  551. $modal.append('<style>' + css + '</style>');
  552. $modal.append('<h1>Insert text or emoji</h1>');
  553. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  554. $modal.append('<br><br>Insert:<br>', $pasteInput);
  555. $modal.html($modal.html() + '<br><br>' + emojiCode);
  556. $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));
  557. $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 () {
  558. $modal.hide();
  559. }));
  560.  
  561. $modal.find('input[name=paste]').click(function () {
  562. var text = prompt('Please paste your text here!');
  563.  
  564. if (text !== null) {
  565. var $pasteInput = $modal.find('input[name=paste]');
  566.  
  567. // Add text into the paste input
  568. $pasteInput.val($pasteInput.val() + text);
  569. }
  570. });
  571.  
  572. $modal.click(function (event) {
  573. if (event.target.classList.contains('miracle-emoji')) {
  574. var $target = $(this).find('input[name=paste]');
  575. $target.val($target.val() + $(event.target).text());
  576.  
  577. event.preventDefault();
  578. }
  579. });
  580.  
  581. $modal.dblclick(function (event) {
  582. if (event.target.classList.contains('miracle-emoji')) {
  583. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  584. $(this).hide();
  585.  
  586. event.preventDefault();
  587. }
  588. });
  589.  
  590. $('body').append($modal);
  591.  
  592. window.addEventListener('keydown', function (event) {
  593. // Do nothing if a menu is open
  594. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  595. return;
  596. }
  597.  
  598. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  599.  
  600. if (event.keyCode == settings.bindings.paste) {
  601. $modal.find('input[name=paste]').val('');
  602. $modal.toggle();
  603. }
  604. });
  605. },
  606.  
  607. dance: function () {
  608. var angle = 0;
  609. var angleSpeed = 20;
  610. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  611. var dancing = false;
  612.  
  613. var dance = function () {
  614. angle += angleSpeed;
  615. if (angle > 360) {
  616. angle = 0;
  617. }
  618.  
  619. var x = window.innerWidth / 2 + Math.sin(angle * Math.PI / 180) * distance;
  620. var y = window.innerHeight / 2 + Math.cos(angle * Math.PI / 180) * distance;
  621. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  622.  
  623. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  624. if (document.getElementById('advert').style.display !== 'none') {
  625. dancing = false;
  626. }
  627. if (dancing) {
  628. window.requestAnimationFrame(dance);
  629. }
  630. }
  631.  
  632. window.addEventListener('keyup', function () {
  633. // Do nothing if a menu is open
  634. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  635. return;
  636. }
  637.  
  638. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  639.  
  640. if (event.keyCode == settings.bindings.dance) {
  641. dancing = !dancing;
  642.  
  643. if (dancing) {
  644. window.requestAnimationFrame(dance);
  645. }
  646. }
  647. });
  648. },
  649.  
  650. replacements: function () {
  651. $('#chtbox').keyup(function () {
  652. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  653.  
  654. var lines = settings.replacements.split('\n');
  655.  
  656. var text = $('#chtbox').val();
  657.  
  658. lines.forEach(function (line) {
  659. var replacement = line.split('|');
  660. if (replacement.length === 2) {
  661. text = text.replace(replacement[0], replacement[1]);
  662. $('#chtbox').val(text).focus();
  663. }
  664. });
  665. });
  666. },
  667.  
  668. chatLog: function () {
  669. // We escape the message before we print them, so no one can inject JS code!
  670. var htmlEntities = function (str) {
  671. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  672. };
  673.  
  674. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  675. var lastChatNickname = null;
  676. var lastChatNicknameColor = null;
  677. var chatLogCode = '';
  678. var chatLog = [];
  679. CanvasRenderingContext2D.prototype.fillText = function () {
  680. if (this.canvas.id !== 'leaderboard' && this.canvas.height == 23) {
  681. var text = arguments[0];
  682.  
  683. // Sometimes also numbers (int) are printed so we filter for strings
  684. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  685. // Dirty fix for the missing icon in the initial welcome messages
  686. if (text == '') {
  687. text = '📢';
  688. }
  689. lastChatNickname = text;
  690. lastChatNicknameColor = this.fillStyle;
  691. }
  692. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  693. // Unfortunately chat messages will be printed more than just once and I don't know
  694. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  695. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  696. var found = false;
  697. for (var i = 0; i < chatLog.length; i++) {
  698. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  699. found = true;
  700. break;
  701. }
  702. }
  703.  
  704. if (!found) {
  705. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  706. chatLogCode += '<div><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  707. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  708. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  709. }
  710. }
  711. }
  712.  
  713. return originalFillText.apply(this, arguments);
  714. };
  715.  
  716. var performSearch = function (searchElement) {
  717. var subject = searchElement.value.toLowerCase();
  718.  
  719. $('#miracle-complete-chatlog div').each(function () {
  720. var $entry = $(this);
  721.  
  722. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  723. $entry.hide();
  724. } else {
  725. $entry.show();
  726. }
  727. });
  728. };
  729.  
  730. 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>');
  731. $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>');
  732. $modal.append('<h1>Complete chatlog</h1><br>');
  733. $modal.append('<div id="miracle-complete-chatlog"></div>');
  734. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  735. performSearch(this);
  736. }));
  737. $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 () {
  738. $modal.hide();
  739. }));
  740. $('body').append($modal);
  741.  
  742. $('#miracle-complete-chatlog').dblclick(function (event) {
  743. var $clickTarget;
  744.  
  745. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  746. if (event.target.tagName.toLowerCase() === 'span') {
  747. $clickTarget = $(event.target).parent();
  748. } else {
  749. $clickTarget = $(event.target);
  750. }
  751.  
  752. var message = $clickTarget.find('.message').text();
  753.  
  754. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  755. if (message.substr(0, 2) === ': ') {
  756. message = message.substr(2);
  757. }
  758.  
  759. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  760.  
  761. window.open('https://www.deepl.com/translator#en/' + settings.targetLanguage + '/' + message);
  762. });
  763.  
  764. window.addEventListener('keyup', function (event) {
  765. // Ignore text input field so typing in them is possible
  766. if (document.activeElement.type === 'text' || document.activeElement.type === 'password') {
  767. return;
  768. }
  769.  
  770. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  771.  
  772. if (event.keyCode == settings.bindings.chatLog) {
  773. $('#miracle-complete-chatlog').html(chatLogCode);
  774. $modal.toggle();
  775. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  776. }
  777. });
  778. },
  779.  
  780. favSkins: function () {
  781. // We need to have a delay, because the menu is not loaded right away
  782. setTimeout(function () {
  783. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  784.  
  785. var favIconClick = function () {
  786. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  787.  
  788. if (settings.favSkins.includes(id)) {
  789. $(this).addClass('skin-not-fav');
  790. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  791. var index = settings.favSkins.indexOf(id);
  792. settings.favSkins.splice(index, 1);
  793. } else {
  794. $(this).removeClass('skin-not-fav');
  795. settings.favSkins.push(id);
  796. }
  797. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  798. renderFavSkins();
  799. };
  800.  
  801. var renderFavSkins = function () {
  802. var $skins = null;
  803.  
  804. if ($('#fav-skins').length > 0) {
  805. $skins = $('#fav-skins');
  806. $skins.html('');
  807. } else {
  808. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  809. $skins.insertAfter('#publicSkinsHeader');
  810.  
  811. $('#fav-skins').click(function (event) {
  812. if (event.target.tagName.toLowerCase() == 'span') {
  813. favIconClick.apply(event.target);
  814. }
  815. });
  816. }
  817. settings.favSkins.forEach(function (id) {
  818. $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>');
  819. });
  820. $skins.append('<div style="clear: both"></div>');
  821. };
  822.  
  823. var addFavIcons = function () {
  824. var $skins = $('#publicSkinsPage');
  825. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  826.  
  827. $skins.find('h4').each(function () {
  828. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  829. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  830.  
  831. $favIcon.click(favIconClick);
  832.  
  833. $(this).append($favIcon);
  834.  
  835. if (!settings.favSkins.includes(id)) {
  836. $favIcon.addClass('skin-not-fav');
  837. }
  838. });
  839. };
  840. var initialized = false;
  841. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  842. if (!initialized) {
  843. var checkState = function () {
  844. if ($('#publicSkinsPage').html() !== '') {
  845. addFavIcons();
  846. renderFavSkins();
  847. } else {
  848. setTimeout(checkState, 30);
  849. }
  850. };
  851. checkState();
  852. initialized = true;
  853. }
  854. });
  855. $('#phpSkins').click(function (event) {
  856. if (event.target.classList.contains('publicskins-nav-btn')) {
  857. addFavIcons();
  858. }
  859. });
  860.  
  861. }, 500);
  862. },
  863.  
  864. commands: function () {
  865. var self = this;
  866. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  867. var minutes;
  868.  
  869. var sessionStartedAt = Date.now();
  870.  
  871. var timeoutStartedAt = null;
  872. var timerMinutes = null;
  873. var timeoutId = null;
  874.  
  875. var originalToggleSkin = window.toggleSkin;
  876. window.toggleSkin = function () {
  877. self.message('Picked skin with ID ' + arguments[0]);
  878.  
  879. return originalToggleSkin.apply(this, arguments);
  880. };
  881.  
  882. $('#chtbox').keydown(function (event) {
  883. if (event.keyCode === 13) {
  884. var message = $('#chtbox').val()
  885. var command = message.split(' ')[0];
  886. var argument1 = message.split(' ')[1];
  887. var argument2 = message.split(' ')[2];
  888.  
  889. if (command === 'time' || command === '/time') {
  890. var now = new Date();
  891. $('#chtbox').val('Local time: ' + now.toLocaleString()).focus();
  892. }
  893.  
  894. if (command === 'minutes' || command === '/minutes') {
  895. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  896. if (minutes > 60) {
  897. minutes = '' + minutes;
  898. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  899. }
  900. $('#chtbox').val('has played for: ' + minutes + ' Minutes in the current session').focus();
  901. }
  902.  
  903. if (command === 'ping' || command === '/ping') {
  904. window.setFPS(1);
  905. var pingRating = 'Extremely bad!', ping = $('#ping').text();
  906. if (parseInt(ping) > 0) {
  907. if (parseInt(ping) < 40) { pingRating = 'Perfect!'; }
  908. if (parseInt(ping) < 70) { pingRating = 'Good!'; }
  909. if (parseInt(ping) < 110) { pingRating = 'Acceptable!'; }
  910. if (parseInt(ping) < 150) { pingRating = 'Bad!'; }
  911. } else {
  912. ping = '∞ (infinite) ';
  913. }
  914. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating).focus();
  915. }
  916. if (command === 'fps' || command === '/fps') {
  917. window.setFPS(1);
  918. var fpsRating = 'Perfect!', fps = $('#fps').text();
  919. if (parseInt(fps) > 0) {
  920. if (fps < 10) { fpsRating = 'Extremely bad!'; }
  921. if (fps < 30) { fpsRating = 'Bad!'; }
  922. if (fps < 40) { fpsRating = 'Acceptable!'; }
  923. if (fps < 57) { fpsRating = 'Good!'; }
  924. } else {
  925. fpsRating = '';
  926. }
  927.  
  928. $('#chtbox').val('has ' + fps + ' frames per second (fps). ' + fpsRating).focus();
  929. }
  930.  
  931. if (command === 'timer' || command === '/timer') {
  932. if (argument1) {
  933. timerMinutes = parseInt(argument1);
  934. if (argument2 === 'hours') {
  935. timerMinutes *= 60;
  936. }
  937. if (timeoutId !== null) {
  938. clearTimeout(timeoutId);
  939. }
  940.  
  941. timeoutStartedAt = Date.now();
  942. timeoutId = setTimeout(function() {
  943. timeoutId = null;
  944. alert('Alert! Timer has expired after ' + timerMinutes + ' minutes.');
  945. }, timerMinutes * 60 * 1000);
  946.  
  947. self.message('Timer set to ' + timerMinutes + ' minutes');
  948. } else {
  949. if (timeoutId === null) {
  950. self.message('No timer has been set. Set with: /timer minutes', true);
  951. } else {
  952. minutes = ((timeoutStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  953. self.message(Math.round(minutes * 10) / 10 + ' minutes remaining.');
  954. }
  955. }
  956. $('#chtbox').val('').focus();
  957. }
  958.  
  959. var useSkin = function (skinSlot, skinId) {
  960. if (skinId) {
  961. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  962. var skinUri = self.getSkinUrl();
  963. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  964. }
  965.  
  966. skinId = parseInt(skinId);
  967. settings.quickSkins[skinSlot - 1] = skinId;
  968. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  969. } else {
  970. skinId = settings.quickSkins[skinSlot - 1];
  971. if (!skinId) {
  972. self.message('Skin not set yet, set with /skin' + skinSlot + ' id', true);
  973. $('#chtbox').val('').focus();
  974. return;
  975. }
  976. }
  977.  
  978. window.azad(true);
  979.  
  980. setTimeout(function () {
  981. $('#skinExampleMenu').click();
  982.  
  983. var checkLoaded = function () {
  984. var loaded = ($('#skinsFree tr').length > 1);
  985. if (loaded) {
  986. toggleSkin(skinId);
  987.  
  988. setTimeout(function () {
  989. $('#shopModalDialog button.close').click();
  990.  
  991. setTimeout(function () {
  992. setNick(document.getElementById('nick').value);
  993. }, 200);
  994. }, 200);
  995. } else {
  996. setTimeout(checkLoaded, 300);
  997. }
  998. };
  999. checkLoaded();
  1000. }, 200);
  1001.  
  1002. $('#chtbox').val('').focus();
  1003. };
  1004. if (command === 'skin1' || command === '/skin1') {
  1005. useSkin(1, argument1);
  1006. }
  1007. if (command === 'skin2' || command === '/skin2') {
  1008. useSkin(2, argument1);
  1009. }
  1010. if (command === 'skin3' || command === '/skin3') {
  1011. useSkin(3, argument1);
  1012. }
  1013. if (command === 'skin4' || command === '/skin4') {
  1014. useSkin(4, argument1);
  1015. }
  1016. if (command === 'skin5' || command === '/skin5') {
  1017. useSkin(5, argument1);
  1018. }
  1019. if (command === 'skin6' || command === '/skin6') {
  1020. useSkin(6, argument1);
  1021. }
  1022. if (command === 'skin7' || command === '/skin7') {
  1023. useSkin(7, argument1);
  1024. }
  1025. if (command === 'skin8' || command === '/skin8') {
  1026. useSkin(8, argument1);
  1027. }
  1028. if (command === 'skin9' || command === '/skin9') {
  1029. useSkin(9, argument1);
  1030. }
  1031. }
  1032. });
  1033. },
  1034.  
  1035. /**
  1036. * Returns a random number between min (inclusive) and max (exclusive)
  1037. * Source: MDN
  1038. */
  1039. getRandomArbitrary: function (min, max) {
  1040. return Math.random() * (max - min) + min;
  1041. },
  1042.  
  1043. message: function (message, isError) {
  1044. var curser = document.querySelector('#curser');
  1045.  
  1046. curser.textContent = message;
  1047. curser.style.display = 'block';
  1048. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  1049.  
  1050. window.setTimeout(function () {
  1051. curser.style.display = 'none';
  1052. }, 5000);
  1053. },
  1054.  
  1055. /**
  1056. * Returns the URI of my skin or null if not skin has been set.
  1057. * Use this.skinUrl() to get it.
  1058. */
  1059. getSkinUrl: function() {
  1060. var skinUrlRaw = $('#skinExampleMenu').css('background-image');
  1061.  
  1062. var parts = skinUrlRaw.split('"');
  1063.  
  1064. if (parts.length != 3) {
  1065. return null;
  1066. } else {
  1067. return parts[1];
  1068. }
  1069. },
  1070. };
  1071.  
  1072. window.miracleScripts.init();
  1073. })();