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

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