Miracle Scripts

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

当前为 2020-02-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miracle Scripts
  3. // @namespace Miracle Scripts
  4. // @version 2.4.4
  5. // @description Bookmark your favorite skins! Use skin shortcuts! Go crazy with cell animations! Improved chat log! Dance! Use chat replacements! Display the time!
  6. // @homepage http://agarioforums.net/member.php?action=profile&uid=21263
  7. // @author You
  8. // @license MIT
  9. // @icon https://abload.de/img/mh3k8o.png
  10. // @match *://agma.io/
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. window.miracleScripts = {
  18.  
  19. // Source: http://stackoverflow.com/questions/1772179/get-character-value-from-keycode-in-javascript-then-trim#answer-23377822
  20. keyboardMap: [
  21. '', // [0]
  22. '', // [1]
  23. '', // [2]
  24. 'CANCEL', // [3]
  25. '', // [4]
  26. '', // [5]
  27. 'HELP', // [6]
  28. '', // [7]
  29. 'BACK_SPACE', // [8]
  30. 'TAB', // [9]
  31. '', // [10]
  32. '', // [11]
  33. 'CLEAR', // [12]
  34. 'ENTER', // [13]
  35. 'ENTER_SPECIAL', // [14]
  36. '', // [15]
  37. 'SHIFT', // [16]
  38. 'CONTROL', // [17]
  39. 'ALT', // [18]
  40. 'PAUSE', // [19]
  41. 'CAPS_LOCK', // [20]
  42. 'KANA', // [21]
  43. 'EISU', // [22]
  44. 'JUNJA', // [23]
  45. 'FINAL', // [24]
  46. 'HANJA', // [25]
  47. '', // [26]
  48. 'ESCAPE', // [27]
  49. 'CONVERT', // [28]
  50. 'NONCONVERT', // [29]
  51. 'ACCEPT', // [30]
  52. 'MODECHANGE', // [31]
  53. 'SPACE', // [32]
  54. 'PAGE_UP', // [33]
  55. 'PAGE_DOWN', // [34]
  56. 'END', // [35]
  57. 'HOME', // [36]
  58. 'LEFT', // [37]
  59. 'UP', // [38]
  60. 'RIGHT', // [39]
  61. 'DOWN', // [40]
  62. 'SELECT', // [41]
  63. 'PRINT', // [42]
  64. 'EXECUTE', // [43]
  65. 'PRINTSCREEN', // [44]
  66. 'INSERT', // [45]
  67. 'DELETE', // [46]
  68. '', // [47]
  69. '0', // [48]
  70. '1', // [49]
  71. '2', // [50]
  72. '3', // [51]
  73. '4', // [52]
  74. '5', // [53]
  75. '6', // [54]
  76. '7', // [55]
  77. '8', // [56]
  78. '9', // [57]
  79. 'COLON', // [58]
  80. 'SEMICOLON', // [59]
  81. 'LESS_THAN', // [60]
  82. 'EQUALS', // [61]
  83. 'GREATER_THAN', // [62]
  84. 'QUESTION_MARK', // [63]
  85. 'AT', // [64]
  86. 'A', // [65]
  87. 'B', // [66]
  88. 'C', // [67]
  89. 'D', // [68]
  90. 'E', // [69]
  91. 'F', // [70]
  92. 'G', // [71]
  93. 'H', // [72]
  94. 'I', // [73]
  95. 'J', // [74]
  96. 'K', // [75]
  97. 'L', // [76]
  98. 'M', // [77]
  99. 'N', // [78]
  100. 'O', // [79]
  101. 'P', // [80]
  102. 'Q', // [81]
  103. 'R', // [82]
  104. 'S', // [83]
  105. 'T', // [84]
  106. 'U', // [85]
  107. 'V', // [86]
  108. 'W', // [87]
  109. 'X', // [88]
  110. 'Y', // [89]
  111. 'Z', // [90]
  112. 'OS_KEY', // [91] Windows Key (Windows) or Command Key (Mac)
  113. '', // [92]
  114. 'CONTEXT_MENU', // [93]
  115. '', // [94]
  116. 'SLEEP', // [95]
  117. 'NUMPAD0', // [96]
  118. 'NUMPAD1', // [97]
  119. 'NUMPAD2', // [98]
  120. 'NUMPAD3', // [99]
  121. 'NUMPAD4', // [100]
  122. 'NUMPAD5', // [101]
  123. 'NUMPAD6', // [102]
  124. 'NUMPAD7', // [103]
  125. 'NUMPAD8', // [104]
  126. 'NUMPAD9', // [105]
  127. 'MULTIPLY', // [106]
  128. 'ADD', // [107]
  129. 'SEPARATOR', // [108]
  130. 'SUBTRACT', // [109]
  131. 'DECIMAL', // [110]
  132. 'DIVIDE', // [111]
  133. 'F1', // [112]
  134. 'F2', // [113]
  135. 'F3', // [114]
  136. 'F4', // [115]
  137. 'F5', // [116]
  138. 'F6', // [117]
  139. 'F7', // [118]
  140. 'F8', // [119]
  141. 'F9', // [120]
  142. 'F10', // [121]
  143. 'F11', // [122]
  144. 'F12', // [123]
  145. 'F13', // [124]
  146. 'F14', // [125]
  147. 'F15', // [126]
  148. 'F16', // [127]
  149. 'F17', // [128]
  150. 'F18', // [129]
  151. 'F19', // [130]
  152. 'F20', // [131]
  153. 'F21', // [132]
  154. 'F22', // [133]
  155. 'F23', // [134]
  156. 'F24', // [135]
  157. '', // [136]
  158. '', // [137]
  159. '', // [138]
  160. '', // [139]
  161. '', // [140]
  162. '', // [141]
  163. '', // [142]
  164. '', // [143]
  165. 'NUM_LOCK', // [144]
  166. 'SCROLL_LOCK', // [145]
  167. 'WIN_OEM_FJ_JISHO', // [146]
  168. 'WIN_OEM_FJ_MASSHOU', // [147]
  169. 'WIN_OEM_FJ_TOUROKU', // [148]
  170. 'WIN_OEM_FJ_LOYA', // [149]
  171. 'WIN_OEM_FJ_ROYA', // [150]
  172. '', // [151]
  173. '', // [152]
  174. '', // [153]
  175. '', // [154]
  176. '', // [155]
  177. '', // [156]
  178. '', // [157]
  179. '', // [158]
  180. '', // [159]
  181. 'CIRCUMFLEX', // [160]
  182. 'EXCLAMATION', // [161]
  183. 'DOUBLE_QUOTE', // [162]
  184. 'HASH', // [163]
  185. 'DOLLAR', // [164]
  186. 'PERCENT', // [165]
  187. 'AMPERSAND', // [166]
  188. 'UNDERSCORE', // [167]
  189. 'OPEN_PAREN', // [168]
  190. 'CLOSE_PAREN', // [169]
  191. 'ASTERISK', // [170]
  192. 'PLUS', // [171]
  193. 'PIPE', // [172]
  194. 'HYPHEN_MINUS', // [173]
  195. 'OPEN_CURLY_BRACKET', // [174]
  196. 'CLOSE_CURLY_BRACKET', // [175]
  197. 'TILDE', // [176]
  198. '', // [177]
  199. '', // [178]
  200. '', // [179]
  201. '', // [180]
  202. 'VOLUME_MUTE', // [181]
  203. 'VOLUME_DOWN', // [182]
  204. 'VOLUME_UP', // [183]
  205. '', // [184]
  206. '', // [185]
  207. 'SEMICOLON', // [186]
  208. 'EQUALS', // [187]
  209. 'COMMA', // [188]
  210. 'MINUS', // [189]
  211. 'PERIOD', // [190]
  212. 'SLASH', // [191]
  213. 'BACK_QUOTE', // [192]
  214. '', // [193]
  215. '', // [194]
  216. '', // [195]
  217. '', // [196]
  218. '', // [197]
  219. '', // [198]
  220. '', // [199]
  221. '', // [200]
  222. '', // [201]
  223. '', // [202]
  224. '', // [203]
  225. '', // [204]
  226. '', // [205]
  227. '', // [206]
  228. '', // [207]
  229. '', // [208]
  230. '', // [209]
  231. '', // [210]
  232. '', // [211]
  233. '', // [212]
  234. '', // [213]
  235. '', // [214]
  236. '', // [215]
  237. '', // [216]
  238. '', // [217]
  239. '', // [218]
  240. 'OPEN_BRACKET', // [219]
  241. 'BACK_SLASH', // [220]
  242. 'CLOSE_BRACKET', // [221]
  243. 'QUOTE', // [222]
  244. '', // [223]
  245. 'META', // [224]
  246. 'ALTGR', // [225]
  247. '', // [226]
  248. 'WIN_ICO_HELP', // [227]
  249. 'WIN_ICO_00', // [228]
  250. '', // [229]
  251. 'WIN_ICO_CLEAR', // [230]
  252. '', // [231]
  253. '', // [232]
  254. 'WIN_OEM_RESET', // [233]
  255. 'WIN_OEM_JUMP', // [234]
  256. 'WIN_OEM_PA1', // [235]
  257. 'WIN_OEM_PA2', // [236]
  258. 'WIN_OEM_PA3', // [237]
  259. 'WIN_OEM_WSCTRL', // [238]
  260. 'WIN_OEM_CUSEL', // [239]
  261. 'WIN_OEM_ATTN', // [240]
  262. 'WIN_OEM_FINISH', // [241]
  263. 'WIN_OEM_COPY', // [242]
  264. 'WIN_OEM_AUTO', // [243]
  265. 'WIN_OEM_ENLW', // [244]
  266. 'WIN_OEM_BACKTAB', // [245]
  267. 'ATTN', // [246]
  268. 'CRSEL', // [247]
  269. 'EXSEL', // [248]
  270. 'EREOF', // [249]
  271. 'PLAY', // [250]
  272. 'ZOOM', // [251]
  273. '', // [252]
  274. 'PA1', // [253]
  275. 'WIN_OEM_CLEAR', // [254]
  276. '' // [255]
  277. ],
  278.  
  279. // Don't remove the spaces, they are used as separators! Source: https://emojiterra.com/de/liste/
  280. emojis: '😀 😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😗 ☺️ 😚 😙 😋 😛 😜 😝 😐 😑 😶 😏 😒 😬 😌 😔 😪 😴 😷 😵 😎 😕 😟 😮 😯 😲 😳 😦 😧 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤 😡 😠 😈 👿 💀 💩 👹 👺 👻 👽 👾 😺 😸 😹 😻 😼 😽 🙀 😿 😾 🙈 🙉 🙊 💋 💌 💘 💝 💖 💗 💓 💞 💕 💟 💔 ❤️ 💛 💚 💙 💜 💯 💢 💥 💫 💦 💨 💣 💬 💭 💤 👋 ✋ 👌 ✌️ 👈 👉 👆 👇 ☝️ 👍 👎 ✊ 👊 👏 🙌 👐 🙏 💅 💪 👂 👃 👀 👅 👄 👶 👦 👧 👱 👨 👩 👴 👵 🙍 🙎 🙅 🙆 💁 🙋 🙇 👮 💂 👷 👸 👳 👲 👰 👼 🎅 💆 💇 🚶 🏃 💃 👯 🏇 🏂 🏄 🚣 🏊 🚴 🚵 🛀 👭 👫 👬 💏 💑 👪 👤 👥 👣 🐵 🐒 🐶 🐕 🐩 🐺 🐱 🐈 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇 🐻 🐨 🐼 🐾 🐔 🐓 🐣 🐤 🐥 🐦 🐧 🐸 🐊 🐢 🐍 🐲 🐉 🐳 🐋 🐬 🐟 🐠 🐡 🐙 🐚 🐌 🐛 🐜 🐝 🐞 💐 🌸 💮 🌹 🌺 🌻 🌼 🌷 🌱 🌲 🌳 🌴 🌵 🌾 🌿 🍀 🍁 🍂 🍃 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍅 🍆 🌽 🍄 🌰 🍞 🍖 🍗 🍔 🍟 🍕 🍳 🍲 🍱 🍘 🍙 🍚 🍛 🍜 🍝 🍠 🍢 🍣 🍤 🍥 🍡 🍦 🍧 🍨 🍩 🍪 🎂 🍰 🍫 🍬 🍭 🍮 🍯 🍼 ☕ 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍴 🔪 🌍 🌎 🌏 🌐 🗾 🌋 🗻 🏠 🏡 🏢 🏣 🏤 🏥 🏦 🏨 🏩 🏪 🏫 🏬 🏭 🏯 🏰 💒 🗼 🗽 ⛪ ⛲ ⛺ 🌁 🌃 🌄 🌅 🌆 🌇 🌉 ♨️ 🎠 🎡 🎢 💈 🎪 🚂 🚃 🚄 🚅 🚆 🚇 🚈 🚉 🚊 🚝 🚞 🚋 🚌 🚍 🚎 🚐 🚑 🚒 🚓 🚔 🚕 🚖 🚗 🚘 🚙 🚚 🚛 🚜 🚲 🚏 ⛽ 🚨 🚥 🚦 🚧 ⚓ ⛵ 🚤 🚢 ✈️ 💺 🚁 🚟 🚠 🚡 🚀 ⌛ ⏳ ⌚ ⏰ 🕛 🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 ☀️ 🌝 🌞 ⭐ 🌟 🌠 🌌 ☁️ ⛅ 🌀 🌈 🌂 ☔ ⚡ ❄️ ⛄ 🔥 💧 🌊 🎃 🎄 🎆 🎇 ✨ 🎈 🎉 🎊 🎋 🎍 🎎 🎏 🎐 🎑 🎀 🎁 🎫 🏆 ⚽ ⚾ 🏀 🏈 🏉 🎾 🎳 ⛳ 🎣 🎽 🎿 🎯 🎱 🔮 🎮 🎰 🎲 ♠️ ♥️ ♦️ ♣️ 🃏 🀄 🎴 🎭 🎨 👓 👔 👕 👖 👗 👘 👙 👚 👛 👜 👝 🎒 👞 👟 👠 👡 👢 👑 👒 🎩 🎓 💄 💍 💎 🔇 🔈 🔉 🔊 📢 📣 📯 🔔 🔕 🎼 🎵 🎶 🎤 🎧 📻 🎷 🎸 🎹 🎺 🎻 📱 📲 ☎️ 📞 📟 📠 🔋 🔌 💻 💽 💾 💿 📀 🎥 🎬 📺 📷 📹 📼 🔍 🔎 💡 🔦 🏮 📔 📕 📖 📗 📘 📙 📚 📓 📒 📃 📜 📄 📰 📑 🔖 💰 💴 💵 💶 💷 💸 💳 💹 💱 💲 ✉️ 📧 📨 📩 📤 📥 📦 📫 📪 📬 📭 📮 ✏️ ✒️ 📝 💼 📁 📂 📅 📆 📇 📈 📉 📊 📋 📌 📍 📎 📏 📐 ✂️ 🔒 🔓 🔏 🔐 🔑 🔨 🔫 🔧 🔩 🔗 🔬 🔭 📡 💉 💊 🚪 🚽 🚿 🛁 🚬 🗿 🏧 🚮 🚰 ♿ 🚹 🚺 🚻 🚼 🚾 🛂 🛃 🛄 🛅 ⚠️ 🚸 ⛔ 🚫 🚳 🚭 🚯 🚱 🚷 📵 🔞 ⬆️ ↗️ ➡️ ↘️ ⬇️ ↙️ ⬅️ ↖️ ↕️ ↔️ 🔃 🔄 🔙 🔚 🔛 🔜 🔝 🔯 ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ⛎ 🔀 🔁 🔂 ▶️ ◀️ 🔼 🔽 🎦 📶 📳 📴 ♻️ 🔱 📛 🔰 ⭕ ✅ ☑️ ✖️ ❌ ❎ ➕ ➖ ➗ ➰ ➿ 〽️ ✳️ ✴️ ❇️ ‼️ ⁉️ ❓ ❔ ❕ ❗ 〰️ ©️ ®️ ™️ 🔠 🔡 🔢 🔣 🔤 🅰️ 🆎 🅱️ 🆑 🆒 🆓 🆔 Ⓜ️ 🆕 🆖 🅾️ 🆗 🅿️ 🆘 🆙 🆚 🈁 🈂️ 🈷️ 🈶 🈯 🉐 🈹 🈚 🈲 🉑 🈸 🈴 🈳 ㊗️ ㊙️ 🈺 🈵 🔴 🔵 ⚫ ⚪ ⬛ ⬜ ◼️ ◻️ ◾ ◽ ▪️ ▫️ 🔶 🔷 🔸 🔹 🔺 🔻 💠 🔘 🔳 🔲 🏁 🚩 🎌',
  281.  
  282. init: function() {
  283. this.setupPolyfills();
  284.  
  285. this.config();
  286.  
  287. this.animation();
  288. this.chatLog();
  289. this.dance();
  290. this.favSkins();
  291. this.paste();
  292. this.replacements();
  293. this.fpsPing();
  294. this.timer();
  295. this.skinChanger();
  296. this.lineSplit();
  297. this.waste();
  298. this.nameColor();
  299. this.help();
  300. this.commands();
  301.  
  302. console.log('🌸 Miracle Scripts successfully loaded!');
  303. },
  304.  
  305. config: function() {
  306. var self = this;
  307. var settings;
  308.  
  309. var loadSettings = function (stringifiedSettings) {
  310. var defaultSettings = {
  311. // To get keycodes: https://keycode.info
  312. bindings: {
  313. animation: 17, // CTRL
  314. paste: 33, // PAGE UP
  315. dance: 34, // PAGE DOWN,
  316. chatLog: 76, // L
  317. },
  318. replacements: ":D|:smile:\n:*(|:sob:\n:'D|:sweat_smiley:\nxD|:joy:",
  319. primaryColor: '#FF69B4',
  320. targetLanguage: 'EN',
  321. favSkins: [],
  322. };
  323.  
  324. if (stringifiedSettings == null) {
  325. settings = defaultSettings;
  326. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  327. } else {
  328. settings = JSON.parse(stringifiedSettings);
  329.  
  330. // Update for settings:
  331. if (typeof settings.primaryColor === 'undefined') {
  332. settings.primaryColor = defaultSettings.primaryColor;
  333. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  334. }
  335. if (typeof settings.bindings.chatLog === 'undefined') {
  336. settings.bindings.chatLog = defaultSettings.bindings.chatLog;
  337. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  338. }
  339. if (typeof settings.favSkins === 'undefined') {
  340. settings.favSkins = defaultSettings.favSkins;
  341. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  342. }
  343. if (typeof settings.targetLanguage === 'undefined') {
  344. settings.targetLanguage = defaultSettings.targetLanguage;
  345. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  346. }
  347. if (typeof settings.quickSkins === 'undefined') {
  348. settings.quickSkins = [];
  349. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  350. }
  351. if (typeof settings.nameChangeDelay === 'undefined') {
  352. settings.nameChangeDelay = 1000;
  353. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  354. }
  355. if (typeof settings.installedVersion === 'undefined') {
  356. settings.installedVersion = 1;
  357. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  358. }
  359. }
  360. };
  361. loadSettings(localStorage.getItem('miracleScripts'));
  362.  
  363. if (settings.installedVersion < this.getVersionAsInt()) {
  364. if (settings.installedVersion < this.getVersionAsInt('2.4.3')) {
  365. window.alert('📢 Miracle Scripts Update: \n\n' +
  366. 'As of version 2.4.3 the nickname color change feature has been removed ' +
  367. 'according to an official decision of the Agma team.\n\n' +
  368. 'To avoid trouble for its users Miracle Scripts respects this decision. ' +
  369. 'Therefore Miracle Scripts is a legit extension for Agma and using it is safe.'
  370. );
  371. }
  372.  
  373. settings.installedVersion = this.getVersionAsInt();
  374. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  375. }
  376.  
  377. var applyPrimaryColor = function () {
  378. var primaryColorCss = '.miracle-primary-color-font { color: ' + settings.primaryColor + ' !important } .miracle-primary-color-background { background-color: ' + settings.primaryColor + ' !important }; ';
  379. $('body').append('<style>' + primaryColorCss + '</style>');
  380. };
  381. applyPrimaryColor();
  382.  
  383. // We need to have a delay, because the menu is not loaded right away
  384. setTimeout(function () {
  385. var $playButton = $('#playBtn');
  386. var $specateButton = $('#spectateBtn');
  387.  
  388. $playButton.get(0).style.width = '40%';
  389. $specateButton.get(0).style.width = '40%';
  390.  
  391. var $settingsButton = $('<button class="spec" style="width: 40px; margin-left: 7px; text-align: center; padding: 10px 0 20px 0" title="Miracle Scripts Settings">📜</button>');
  392. $settingsButton.insertAfter($playButton);
  393.  
  394. var changeKey = function (event) {
  395. var name = this.name.substr(4);
  396. $(this).val(self.keyboardMap[event.keyCode]);
  397. settings.bindings[name] = event.keyCode;
  398. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  399. };
  400.  
  401. var deleteKey = function () {
  402. var action = $(this).attr('data-action');
  403. $('#miracle-settings input[name=key_' + action + ']').val('undefined');
  404. settings.bindings[action] = null;
  405. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  406. };
  407.  
  408. // Weird Agma scripting... press enter in the replacements textarea and the chat box gets focused!
  409. // Therefore catch the keydown event (that happens earlier) and insert the linebreak manually,
  410. // focus again (delayed) and go to the end of the text where the linebreak is.
  411. // We can improve this later on...
  412. var addReturn = function (event) {
  413. if (event.keyCode === 13) {
  414. var textarea = this;
  415. $(textarea).text($(this).text() + '\n').focus();
  416. setTimeout(function () {
  417. $(textarea).focus();
  418. textarea.setSelectionRange(textarea.value.length, textarea.value.length);
  419. }, 1);
  420. }
  421. };
  422. var changeReplacements = function () {
  423. settings.replacements = $(this).val();
  424. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  425. };
  426. var changePrimaryColor = function () {
  427. settings.primaryColor = $(this).val();
  428. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  429. applyPrimaryColor();
  430. };
  431. var changeTargetLanguage = function () {
  432. settings.targetLanguage = $(this).val();
  433. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  434. };
  435.  
  436. 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>');
  437. $modal.append('<h1>Miracle Scripts Settings</h1>');
  438.  
  439. if (GM_info) {
  440. $modal.append('<small style="color: #717171">Version ' + GM_info.script.version + '</small>');
  441. }
  442.  
  443. var $element = $('<input name="key_animation" value="' + self.keyboardMap[settings.bindings.animation] + '"/>').keyup(changeKey);
  444. $modal.append('<br><br>Animation-Key:<br>', $element);
  445. $element = $('<a href="#" data-action="animation" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  446. $modal.append($element);
  447.  
  448. $element = $('<input name="key_paste" value="' + self.keyboardMap[settings.bindings.paste] + '"/>').keyup(changeKey);
  449. $modal.append('<br>Paste-Key:<br>', $element);
  450. $element = $('<a href="#" data-action="paste" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  451. $modal.append($element);
  452.  
  453. $element = $('<input name="key_dance" value="' + self.keyboardMap[settings.bindings.dance] + '"/>').keyup(changeKey);
  454. $modal.append('<br>Dance-Key:<br>', $element);
  455. $element = $('<a href="#" data-action="dance" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  456. $modal.append($element);
  457.  
  458. $element = $('<input name="key_chatLog" value="' + self.keyboardMap[settings.bindings.chatLog] + '"/>').keyup(changeKey);
  459. $modal.append('<br>Chat-Log-Key:<br>', $element);
  460. $element = $('<a href="#" data-action="chatLog" class="miracle-primary-color-background" style="display: inline-block; padding: 3px 10px; color: white">✖</a>').click(deleteKey);
  461. $modal.append($element);
  462.  
  463. $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);
  464. $modal.append('<br><br>Translate chat messages to:<br>', $element);
  465. $element.get(0).value = settings.targetLanguage;
  466.  
  467. $element = $('<input type="color" name="favcolor" value="' + settings.primaryColor + '"/>').change(changePrimaryColor);
  468. $modal.append('<br><br>User interface color:<br>', $element);
  469.  
  470. $element = $('<textarea rows="6" style="width: 100%; max-width: 500px" placeholder="search|replace">').text(settings.replacements).keydown(addReturn).keyup(changeReplacements);
  471. $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>');
  472.  
  473. $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 () {
  474. $modal.hide();
  475. }));
  476. $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 () {
  477. self.download('miracle_settings.txt', localStorage.getItem('miracleScripts'));
  478. }));
  479. $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 () {
  480. var stringifiedSettings = window.prompt('Paste the settings here');
  481. if (stringifiedSettings !== null) {
  482. loadSettings(stringifiedSettings);
  483. localStorage.setItem('miracleScripts', stringifiedSettings);
  484. $modal.hide();
  485. self.message('Settings loaded! Reload Agma to refresh. 😄');
  486. }
  487. }));
  488. $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>'));
  489. $modal.append($('<a href="#" class="miracle-primary-color-background" style="display: inline-block; margin-left: 20px; margin-top: 20px; padding: 10px; color: white">Help</a>').click(function () {
  490. $modal.hide();
  491. self.$helpModal.show();
  492. }));
  493.  
  494. $('body').append($modal);
  495.  
  496. $settingsButton.click(function (event) {
  497. $modal.show();
  498.  
  499. event.preventDefault();
  500. });
  501. }, 500);
  502. },
  503.  
  504. animation: function () {
  505. var self = this;
  506.  
  507. var chatAnimate = function () {
  508. if ($('#chtbox').val().substr(0, 4) === '/pm ') {
  509. $('#chtbox').val('');
  510. }
  511.  
  512. // All available commands and combinations
  513. var items = ['wacky',
  514. 'spin', 'spinspin', 'spinspinspin', 'wackyspin', 'wackyspinspin', 'wackyspinspinspin',
  515. 'flip', 'flipflip', 'flipflipflip', 'wackyflip', 'wackyflipflip', 'wackyflipflipfip',
  516. 'shake', 'shakeshake', 'shakeshakeshake', 'wackyshake', 'wackyshakeshake', 'wackyshakeshakeshake',
  517. 'jump', 'jumpjump', 'jumpjumpjump', 'wackyjump', 'wackyjumpjump', 'wackyjumpjumpjump',
  518. ];
  519.  
  520. // Super-combinations!!
  521. if (self.getRandomInt(1, 3) === 1) {
  522. items = ['jumpspinflip', 'jumpflipshake', 'jumpspinshake', 'spinshakeflip'];
  523. }
  524.  
  525. // Choose randomly an item of the items array
  526. // Source: https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array
  527. var item = items[Math.floor(Math.random() * items.length)];
  528.  
  529. // Attempt to avoid triggering spam protection - probably useless :-/
  530. item += String.fromCharCode(8203).repeat(self.getRandomInt(1, 5));
  531.  
  532. // Add text into the chat box and focus it (Note: actually "/" is no longer necessary)
  533. $('#chtbox').val($('#chtbox').val() + item).focus();
  534.  
  535. // Stop the event so that the pressed key won't be written into the chat box!
  536. event.preventDefault();
  537. };
  538.  
  539. window.addEventListener('keydown', function (event) {
  540. // Do nothing if a menu is open
  541. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  542. return;
  543. }
  544.  
  545. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  546.  
  547. if (event.keyCode == settings.bindings.animation) {
  548. chatAnimate();
  549. }
  550. });
  551. },
  552.  
  553. paste: function () {
  554. var emojiFontSize = (window.innerWidth * window.innerHeight > 2000000) ? 24 : 18;
  555. 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' +
  556. '#miracle-emojis .miracle-emoji:hover { background-color: #FF69B4 }';
  557.  
  558. var emojis = this.emojis.split(' ');
  559. var emojiCode = '';
  560.  
  561. emojis.forEach(function (emoji) {
  562. emojiCode += '<a href="#" class="miracle-emoji">' + emoji + '</a>';
  563. });
  564.  
  565. var addEmoji = function () {
  566. setTimeout(function () {
  567. var $pasteInput = $(document).find('#miracle-emojis input[name=paste]');
  568.  
  569. // Add text into the chatbox and focus it
  570. $('#chtbox').val($('#chtbox').val() + $pasteInput.val()).focus();
  571. }, 200);
  572.  
  573. $modal.hide();
  574. };
  575.  
  576. 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>');
  577. $modal.append('<style>' + css + '</style>');
  578. $modal.append('<h1>Insert text or emoji</h1>');
  579. var $pasteInput = $('<input name="paste" value="" placeholder="Click to paste text, or (double)click emoji!" style="width: 300px; max-width: 100%" />');
  580. $modal.append('<br><br>Insert:<br>', $pasteInput);
  581. $modal.html($modal.html() + '<br><br>' + emojiCode);
  582. $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));
  583. $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 () {
  584. $modal.hide();
  585. }));
  586.  
  587. $modal.find('input[name=paste]').click(function () {
  588. var text = window.prompt('Please paste your text here!');
  589.  
  590. if (text !== null) {
  591. var $pasteInput = $modal.find('input[name=paste]');
  592.  
  593. // Add text into the paste input
  594. $pasteInput.val($pasteInput.val() + text);
  595. }
  596. });
  597.  
  598. $modal.click(function (event) {
  599. if (event.target.classList.contains('miracle-emoji')) {
  600. var $target = $(this).find('input[name=paste]');
  601. $target.val($target.val() + $(event.target).text());
  602.  
  603. event.preventDefault();
  604. }
  605. });
  606.  
  607. $modal.dblclick(function (event) {
  608. if (event.target.classList.contains('miracle-emoji')) {
  609. $('#chtbox').val($('#chtbox').val() + $(event.target).text()).focus();
  610. $(this).hide();
  611.  
  612. event.preventDefault();
  613. }
  614. });
  615.  
  616. $('body').append($modal);
  617.  
  618. window.addEventListener('keydown', function (event) {
  619. // Do nothing if a menu is open
  620. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  621. return;
  622. }
  623.  
  624. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  625.  
  626. if (event.keyCode == settings.bindings.paste) {
  627. $modal.find('input[name=paste]').val('');
  628. $modal.toggle();
  629. }
  630. });
  631. },
  632.  
  633. replacements: function () {
  634. $('#chtbox').keyup(function () {
  635. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  636.  
  637. var lines = settings.replacements.split('\n');
  638.  
  639. var text = $('#chtbox').val();
  640.  
  641. lines.forEach(function (line) {
  642. var replacement = line.split('|');
  643. if (replacement.length === 2) {
  644. text = text.replace(replacement[0], replacement[1]);
  645. $('#chtbox').val(text).focus();
  646. }
  647. });
  648. });
  649. },
  650.  
  651. chatLog: function () {
  652. var self = this;
  653.  
  654. // We escape the message before we print them, so no one can inject JS code!
  655. var htmlEntities = function (str) {
  656. return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  657. };
  658.  
  659. var originalFillText = CanvasRenderingContext2D.prototype.fillText;
  660. var lastChatNickname = null;
  661. var lastChatNicknameColor = null;
  662. var chatLogCode = '';
  663. var chatLog = [];
  664. CanvasRenderingContext2D.prototype.fillText = function () {
  665. if (this.canvas.id !== 'leaderboard' && this.canvas.height === 23) {
  666. var text = arguments[0];
  667.  
  668. // Sometimes also numbers (int) are printed so we filter for strings
  669. if (typeof text === 'string' && (this.fillStyle !== '#f5f6ce' && this.fillStyle !== '#444444')) {
  670. // Dirty fix for the missing icon in the initial welcome messages
  671. if (text == '') {
  672. text = '📢';
  673. }
  674. lastChatNickname = text;
  675. lastChatNicknameColor = this.fillStyle;
  676. }
  677. if (typeof text === 'string' && (this.fillStyle === '#f5f6ce' || this.fillStyle === '#444444')) {
  678. // Unfortunately chat messages will be printed more than just once and I don't know
  679. // how to identify them, so for now all messages will be stored and only new messages will be shown.
  680. // Of course this means messages won't be shown if they are sent more than once (by the same nickname).
  681. var found = false;
  682. for (var i = 0; i < chatLog.length; i++) {
  683. if (chatLog[i].nickname === lastChatNickname && chatLog[i].nicknameColor === lastChatNicknameColor && chatLog[i].message === text) {
  684. found = true;
  685. break;
  686. }
  687. }
  688.  
  689. if (!found) {
  690. // NOTE: We might have to look for the coordinates of the text to find out the order of the messages (somehow)
  691. chatLogCode += '<div><span class="time">' + (new Date().toLocaleTimeString()) + '</span> <span class="nickname" style="color: ' + lastChatNicknameColor + '">' + htmlEntities(lastChatNickname) + '</span>';
  692. chatLogCode += '<span class="message" style="color: #f5f6ce">' + htmlEntities(text) + '</span></div>';
  693. chatLog.push({nickname: lastChatNickname, nicknameColor: lastChatNicknameColor, message: text});
  694. }
  695. }
  696. }
  697.  
  698. return originalFillText.apply(this, arguments);
  699. };
  700.  
  701. var performSearch = function (searchElement) {
  702. var subject = searchElement.value.toLowerCase();
  703.  
  704. $('#miracle-complete-chatlog div').each(function () {
  705. var $entry = $(this);
  706.  
  707. if ($entry.text().toLowerCase().indexOf(subject) === -1 && subject != '') {
  708. $entry.hide();
  709. } else {
  710. $entry.show();
  711. }
  712. });
  713. };
  714.  
  715. 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>');
  716. $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>');
  717. $modal.append('<h1>Complete chatlog</h1><br>');
  718. $modal.append('<div id="miracle-complete-chatlog"></div>');
  719. $modal.append($('<input type="text" style="display: inline-block; position: fixed; right: 20px; bottom: 20px;" placeholder="Type to search">').keyup(function () {
  720. performSearch(this);
  721. }));
  722. $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 () {
  723. $modal.hide();
  724. }));
  725. $('body').append($modal);
  726.  
  727. $('#miracle-complete-chatlog').dblclick(function (event) {
  728. var $clickTarget;
  729.  
  730. // Each chat message is a div with spans in it. Either the spans or the div might be clicked.
  731. if (event.target.tagName.toLowerCase() === 'span') {
  732. $clickTarget = $(event.target).parent();
  733. } else {
  734. $clickTarget = $(event.target);
  735. }
  736.  
  737. var message = $clickTarget.find('.message').text();
  738.  
  739. // Messages usually start with ': ' but we do not want to "translate" it, so we remove it
  740. if (message.substr(0, 2) === ': ') {
  741. message = message.substr(2);
  742. }
  743.  
  744. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  745.  
  746. window.open('https://www.deepl.com/translator#en/' + settings.targetLanguage + '/' + message);
  747. });
  748.  
  749. window.addEventListener('keyup', function (event) {
  750. // Ignore text input field so typing in them is possible
  751. if (self.isWritingText()) {
  752. return;
  753. }
  754.  
  755. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  756.  
  757. if (event.keyCode == settings.bindings.chatLog) {
  758. $('#miracle-complete-chatlog').html(chatLogCode);
  759. $modal.toggle();
  760. $modal.get(0).scrollTo(0, $modal.get(0).scrollHeight);
  761. }
  762. });
  763. },
  764.  
  765. favSkins: function () {
  766. // We need to have a delay, because the menu is not loaded right away
  767. setTimeout(function () {
  768. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  769.  
  770. var favIconClick = function () {
  771. var id = parseInt($(this).parent().parent().find('button').attr('onclick').substr(11));
  772.  
  773. if (settings.favSkins.includes(id)) {
  774. $(this).addClass('skin-not-fav');
  775. $('#skinUseBtn' + id).parent().find('span').addClass('skin-not-fav');
  776. var index = settings.favSkins.indexOf(id);
  777. settings.favSkins.splice(index, 1);
  778. } else {
  779. $(this).removeClass('skin-not-fav');
  780. settings.favSkins.push(id);
  781. }
  782. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  783. renderFavSkins();
  784. };
  785.  
  786. var renderFavSkins = function () {
  787. var $skins = null;
  788.  
  789. if ($('#fav-skins').length > 0) {
  790. $skins = $('#fav-skins');
  791. $skins.html('');
  792. } else {
  793. $skins = $('<div id="fav-skins" style="background-color: #4d4950"></div>');
  794. $skins.insertAfter('#publicSkinsHeader');
  795.  
  796. $('#fav-skins').click(function (event) {
  797. if (event.target.tagName.toLowerCase() === 'span') {
  798. favIconClick.apply(event.target);
  799. }
  800. });
  801. }
  802. settings.favSkins.forEach(function (id) {
  803. $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>');
  804. });
  805. $skins.append('<div style="clear: both"></div>');
  806. };
  807.  
  808. var addFavIcons = function () {
  809. var $skins = $('#publicSkinsPage');
  810. $skins.append('<style>.skin-not-fav { opacity: 0.3 }</style>');
  811.  
  812. $skins.find('h4').each(function () {
  813. var $favIcon = $('<span style="cursor: pointer">⭐</span>');
  814. var id = parseInt($(this).parent().find('button').attr('onclick').substr(11));
  815.  
  816. $favIcon.click(favIconClick);
  817.  
  818. $(this).append($favIcon);
  819.  
  820. if (!settings.favSkins.includes(id)) {
  821. $favIcon.addClass('skin-not-fav');
  822. }
  823. });
  824. };
  825. var initialized = false;
  826. $('#skinsCustomTab, #skinExampleMenu').click(function () {
  827. if (!initialized) {
  828. var checkState = function () {
  829. if ($('#publicSkinsPage').html() !== '') {
  830. addFavIcons();
  831. renderFavSkins();
  832. } else {
  833. setTimeout(checkState, 30);
  834. }
  835. };
  836. checkState();
  837. initialized = true;
  838. }
  839. });
  840. $('#phpSkins').click(function (event) {
  841. if (event.target.classList.contains('publicskins-nav-btn')) {
  842. addFavIcons();
  843. }
  844. });
  845.  
  846. }, 500);
  847. },
  848.  
  849. skinChanger: function() {
  850. var self = this;
  851.  
  852. // When the user changes the skin, display ID of the picked skin
  853. var originalToggleSkin = window.toggleSkin;
  854. window.toggleSkin = function () {
  855. self.message('Picked skin with ID ' + arguments[0]);
  856.  
  857. return originalToggleSkin.apply(this, arguments);
  858. };
  859.  
  860. window.addEventListener('miracleCommand', function(commandEvent) {
  861. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  862.  
  863. var useSkin = function (skinSlot, skinId) {
  864. if (skinId) {
  865. if (skinId === 'this' || skinId === 'current' || skinId === 'my' || skinId === 'me' || skinId === 'now' || skinId === 'here') {
  866. var skinUri = self.getSkinUrl();
  867. skinId = parseInt(skinUri.substr(skinUri.indexOf('skins/') + 6));
  868. }
  869.  
  870. skinId = parseInt(skinId);
  871. settings.quickSkins[skinSlot - 1] = skinId;
  872. localStorage.setItem('miracleScripts', JSON.stringify(settings));
  873. } else {
  874. skinId = settings.quickSkins[skinSlot - 1];
  875. if (!skinId) {
  876. self.message('Skin not set yet, set with /skin' + skinSlot + ' id 😊', true);
  877. $('#chtbox').val('').focus();
  878. return;
  879. }
  880. }
  881.  
  882. window.azad(true);
  883.  
  884. setTimeout(function () {
  885. $('#skinExampleMenu').click();
  886.  
  887. var checkLoaded = function () {
  888. var loaded = ($('#skinsFree tr').length > 1);
  889. if (loaded) {
  890. window.toggleSkin(skinId);
  891.  
  892. setTimeout(function () {
  893. $('#shopModalDialog button.close').click();
  894.  
  895. setTimeout(function () {
  896. window.setNick(document.getElementById('nick').value);
  897. }, 200);
  898. }, 200);
  899. } else {
  900. setTimeout(checkLoaded, 300);
  901. }
  902. };
  903. checkLoaded();
  904. }, 200);
  905.  
  906. $('#chtbox').val('').focus();
  907. };
  908.  
  909. if (commandEvent.command === 'skin1' || commandEvent.command === '/skin1') {
  910. useSkin(1, commandEvent.argument1);
  911. }
  912. if (commandEvent.command === 'skin2' || commandEvent.command === '/skin2') {
  913. useSkin(2, commandEvent.argument1);
  914. }
  915. if (commandEvent.command === 'skin3' || commandEvent.command === '/skin3') {
  916. useSkin(3, commandEvent.argument1);
  917. }
  918. if (commandEvent.command === 'skin4' || commandEvent.command === '/skin4') {
  919. useSkin(4, commandEvent.argument1);
  920. }
  921. if (commandEvent.command === 'skin5' || commandEvent.command === '/skin5') {
  922. useSkin(5, commandEvent.argument1);
  923. }
  924. if (commandEvent.command === 'skin6' || commandEvent.command === '/skin6') {
  925. useSkin(6, commandEvent.argument1);
  926. }
  927. if (commandEvent.command === 'skin7' || commandEvent.command === '/skin7') {
  928. useSkin(7, commandEvent.argument1);
  929. }
  930. if (commandEvent.command === 'skin8' || commandEvent.command === '/skin8') {
  931. useSkin(8, commandEvent.argument1);
  932. }
  933. if (commandEvent.command === 'skin9' || commandEvent.command === '/skin9') {
  934. useSkin(9, commandEvent.argument1);
  935. }
  936. if (commandEvent.command === 'skin10' || commandEvent.command === '/skin10') {
  937. useSkin(10, commandEvent.argument1);
  938. }
  939. if (commandEvent.command === 'skin11' || commandEvent.command === '/skin11') {
  940. useSkin(11, commandEvent.argument1);
  941. }
  942. if (commandEvent.command === 'skin12' || commandEvent.command === '/skin12') {
  943. useSkin(12, commandEvent.argument1);
  944. }
  945. if (commandEvent.command === 'skin13' || commandEvent.command === '/skin13') {
  946. useSkin(13, commandEvent.argument1);
  947. }
  948. if (commandEvent.command === 'skin14' || commandEvent.command === '/skin14') {
  949. useSkin(14, commandEvent.argument1);
  950. }
  951. if (commandEvent.command === 'skin15' || commandEvent.command === '/skin15') {
  952. useSkin(15, commandEvent.argument1);
  953. }
  954. });
  955. },
  956.  
  957. lineSplit: function() {
  958. var self = this;
  959.  
  960. window.addEventListener('miracleCommand', function(commandEvent) {
  961. if (commandEvent.command === '/linesplit') {
  962. self.lineSplitAt = Date.now();
  963. self.message('Linesplit •••••');
  964.  
  965. var doSplit = function() {
  966. if (Date.now() - self.lineSplitAt < 1000) {
  967. var factor = Math.min((Date.now() - self.lineSplitAt) / 700, 1);
  968. var x = window.innerWidth / 2;
  969. var y = factor * (window.innerHeight / 2);
  970.  
  971. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  972.  
  973. window.requestAnimationFrame(doSplit);
  974. } else {
  975. if (Date.now() - self.lineSplitAt < 3000) {
  976. if (self.splitAt === undefined || Date.now() - self.splitAt > 200) {
  977. var hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  978. $('body').trigger($.Event('keydown', { keyCode: hotkeys.Space.c}));
  979. $('body').trigger($.Event('keyup', { keyCode: hotkeys.Space.c}));
  980. self.splitAt = Date.now();
  981. }
  982.  
  983. window.requestAnimationFrame(doSplit);
  984. }
  985. }
  986. };
  987. doSplit();
  988. $('#chtbox').val('');
  989. }
  990. });
  991. },
  992.  
  993. dance: function () {
  994. var self = this;
  995. var hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  996.  
  997. window.addEventListener('keydown', function (event) {
  998. if (event.keyCode == hotkeys.M.c && ! self.isWritingText()) {
  999. self.dancing = false;
  1000. }
  1001. });
  1002.  
  1003. window.addEventListener('keyup', function () {
  1004. // Do nothing if a menu is open
  1005. if (document.getElementById('overlays').style.display !== 'none' || document.getElementById('advert').style.display !== 'none') {
  1006. return;
  1007. }
  1008.  
  1009. var settings = JSON.parse(localStorage.getItem('miracleScripts'));
  1010.  
  1011. if (event.keyCode == settings.bindings.dance) {
  1012. self.dancing = ! self.dancing;
  1013.  
  1014. if (self.dancing) {
  1015. self.performDance.apply(self);
  1016. }
  1017. }
  1018. });
  1019. },
  1020.  
  1021. performDance: function () {
  1022. var self = this ? this : window.miracleScripts;
  1023.  
  1024. if (self.danceAngle === undefined) {
  1025. self.danceAngle = 0;
  1026. }
  1027.  
  1028. self.danceAngle += 20;
  1029.  
  1030. if (self.danceAngle > 360) {
  1031. self.danceAngle = 0;
  1032. }
  1033.  
  1034. var distance = Math.floor(Math.min(window.innerWidth, window.innerHeight) / 2);
  1035. var x = window.innerWidth / 2 + Math.sin(self.danceAngle * Math.PI / 180) * distance;
  1036. var y = window.innerHeight / 2 + Math.cos(self.danceAngle * Math.PI / 180) * distance;
  1037. $('canvas').trigger($.Event('mousemove', {clientX: x, clientY: y}));
  1038.  
  1039. // Stop dancing if dead ... to avoid continuing dancing after next respawn
  1040. if (document.getElementById('advert').style.display !== 'none') {
  1041. self.dancing = false;
  1042. }
  1043. if (self.dancing) {
  1044. window.requestAnimationFrame(self.performDance);
  1045. }
  1046. },
  1047.  
  1048. waste: function() {
  1049. var self = this;
  1050. var hotkeys = JSON.parse(localStorage.getItem('hotkeys'));
  1051.  
  1052. window.addEventListener('keydown', function (event) {
  1053. if (event.keyCode == hotkeys.M.c && ! self.isWritingText()) {
  1054. self.wasting = false;
  1055. }
  1056. });
  1057.  
  1058. window.addEventListener('miracleCommand', function(commandEvent) {
  1059. if (commandEvent.command === '/waste') {
  1060. if (self.wasting) {
  1061. self.wasting = false;
  1062. self.message('Stopped wasting all mass.');
  1063. self.dancing = false;
  1064. } else {
  1065. self.wasting = true;
  1066. self.message('Wasting all mass...');
  1067. if (! self.dancing) {
  1068. self.dancing = true;
  1069. self.performDance.apply(self);
  1070. }
  1071. $('#chtbox').val('spinshakeflip').focus();
  1072. }
  1073.  
  1074. var doWaste = function() {
  1075. // Stop wasting mass if dead ... to avoid continuing wasting after next respawn
  1076. if (document.getElementById('advert').style.display !== 'none') {
  1077. self.wasting = false;
  1078. }
  1079. if (! self.wasting) {
  1080. return;
  1081. }
  1082. $('body').trigger($.Event('keydown', { keyCode: hotkeys.W.c}));
  1083. $('body').trigger($.Event('keyup', { keyCode: hotkeys.W.c}));
  1084. window.requestAnimationFrame(doWaste);
  1085. };
  1086. doWaste();
  1087. }
  1088. });
  1089. },
  1090.  
  1091. fpsPing: function () {
  1092. window.addEventListener('miracleCommand', function(commandEvent) {
  1093. if (commandEvent.command === 'ping' || commandEvent.command === '/ping') {
  1094. window.setFPS(1);
  1095. var pingRating = 'Extremely bad! ❌', ping = $('#ping').text();
  1096. if (parseInt(ping) > 0) {
  1097. if (parseInt(ping) >= 0 && parseInt(ping) < 40) { pingRating = 'Perfect! ✔️'; }
  1098. if (parseInt(ping) >= 40 && parseInt(ping) < 70) { pingRating = 'Good! ✔️'; }
  1099. if (parseInt(ping) >= 70 && parseInt(ping) < 120) { pingRating = 'Acceptable! ✔️'; }
  1100. if (parseInt(ping) >= 120 && parseInt(ping) < 150) { pingRating = 'Bad! ❌'; }
  1101. if (parseInt(ping) >= 150 && parseInt(ping) < 990) { pingRating = 'Insanity! ❌'; }
  1102. if (parseInt(ping) >= 990 && parseInt(ping) < 4900) { pingRating = 'THIS IS MADNESS! ❌'; }
  1103. if (parseInt(ping) > 4900) { pingRating = 'M M M M M M M M M MONSTERPING! ❌'; }
  1104. } else {
  1105. ping = '∞ (infinite) ';
  1106. }
  1107. $('#chtbox').val('has a ping of: ' + ping + '. ' + pingRating).focus();
  1108. }
  1109. if (commandEvent.command === 'fps' || commandEvent.command === '/fps') {
  1110. window.setFPS(1);
  1111. var fpsRating = 'Perfect! ✔️', fps = $('#fps').text();
  1112. if (parseInt(fps) > 0) {
  1113. if (fps >= 0 && fps < 10) { fpsRating = 'Extremely bad! ❌'; }
  1114. if (fps >= 10 && fps < 30) { fpsRating = 'Bad! ❌'; }
  1115. if (fps >= 30 && fps < 40) { fpsRating = 'Acceptable! ✔️'; }
  1116. if (fps >= 40 && fps < 57) { fpsRating = 'Good! ✔️'; }
  1117. if (fps > 73) { fpsRating = 'Outstanding! ✔️'; }
  1118. if (fps > 97) { fpsRating = 'Fantastic! ✔️'; }
  1119. if (fps > 117) { fpsRating = 'GODLIKE! ✔️'; }
  1120. } else {
  1121. fpsRating = '';
  1122. }
  1123.  
  1124. $('#chtbox').val('has ' + fps + ' frames per second (fps). ' + fpsRating).focus();
  1125. }
  1126. });
  1127. },
  1128.  
  1129. timer: function() {
  1130. var self = this;
  1131.  
  1132. var timerStartedAt = null;
  1133. var timerMinutes = null;
  1134. var timeoutId = null;
  1135. var updateId = null;
  1136.  
  1137. var $countdownUi = $('<div style="position: fixed; right: 20px; bottom: 225px; z-index: 9999; color: #3e3e3e; pointer-events: none"></div>');
  1138. $('body').append($countdownUi);
  1139.  
  1140. window.addEventListener('miracleCommand', function(commandEvent) {
  1141. if (commandEvent.command === 'timer' || commandEvent.command === '/timer') {
  1142. var argument1 = commandEvent.argument1;
  1143. var argument2 = commandEvent.argument2;
  1144.  
  1145. if (argument1) {
  1146. timerMinutes = parseInt(argument1);
  1147. if (argument2 === 'h' || argument2 === 'hour' || argument2 === 'hours') {
  1148. timerMinutes *= 60;
  1149. }
  1150. if (timeoutId !== null) {
  1151. clearTimeout(timeoutId);
  1152. }
  1153.  
  1154. if (argument1 === '0' || argument1 === 'reset' || argument1 === 'stop') {
  1155. self.message('🗑️ Timer removed');
  1156. } else {
  1157. timerStartedAt = Date.now();
  1158. var updateUi = function () {
  1159. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1160. $countdownUi.text('🕒 ' + Math.ceil(remaining) + 'm');
  1161. };
  1162. updateId = setInterval(updateUi, 10000);
  1163. updateUi();
  1164. timeoutId = setTimeout(function () {
  1165. timeoutId = null;
  1166. window.clearInterval(updateId);
  1167. $countdownUi.text('');
  1168. var message = '🕒 Alert! Timer has expired after ' + timerMinutes + ' minutes.';
  1169. this.message(message);
  1170. window.alert(message);
  1171. }, timerMinutes * 60 * 1000);
  1172.  
  1173. self.message('🕒 Timer set to ' + timerMinutes + ' minutes');
  1174. }
  1175. } else {
  1176. if (timeoutId === null) {
  1177. self.message('🕒 No timer has been set. Set with: /timer minutes', true);
  1178. } else {
  1179. var remaining = ((timerStartedAt + timerMinutes * 60 * 1000) - Date.now()) / 1000 / 60;
  1180. self.message('🕒 ' + Math.round(remaining * 10) / 10 + ' minutes remaining.');
  1181. }
  1182. }
  1183. $('#chtbox').val('').focus();
  1184. }
  1185. });
  1186. },
  1187.  
  1188. nameColor: function() {
  1189. var self = this;
  1190.  
  1191. window.addEventListener('miracleCommand', function(commandEvent) {
  1192. if (commandEvent.command === '/namecolor' || commandEvent.command === '/colorname' || commandEvent.command === '/colorchange') {
  1193. self.message('This feature has been removed since the Agma staff does not allow it.');
  1194. $('#chtbox').val('');
  1195. }
  1196. });
  1197. },
  1198.  
  1199. help: function() {
  1200. var $modal = $('<div 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>');
  1201. $modal.append('<h1>Miracle Scripts Help</h1>');
  1202.  
  1203. var helpText = '<br><span style="color: #717171">Available chat commands are: </span><br><br><table>' +
  1204. '<tr><th style="padding-right: 50px"><i>Command</i></th><th><i>Description</i></th></tr>' +
  1205. '<tr><td><code>/miraclehelp</code></td><td>show this help</td></tr>' +
  1206. '<tr><td><code>/miracle</code></td><td>show version info</td></tr>' +
  1207. '<tr><td><code>/skin<n></code></td><td>change to skin &lt;n></td></tr>' +
  1208. '<tr><td><code>/skin<n> this</code></td><td>store current skin as skin <n></td></tr>' +
  1209. '<tr><td><code>/skin<n> <id></code></td><td>store skin with ID &lt;id> as skin &lt;n></td></tr>' +
  1210. '<tr><td><code>/say &lt;text></code></td><td>send chat message with fancy font</td></tr>' +
  1211. '<tr><td><code>/say&lt;n> &lt;text></code></td><td>send chat message with fancy font number &lt;n></td></tr>' +
  1212. '<tr><td><code>/timer &lt;n></code></td><td>set time for &lt;n> minutes</td></tr>' +
  1213. '<tr><td><code>/timer &lt;n> h</code></td><td>set time for &lt;n> hours</td></tr>' +
  1214. '<tr><td><code>/timer stop</code></td><td>stop timer</td></tr>' +
  1215. '<tr><td><code>/fps</code></td><td>send chat message with current fps</td></tr>' +
  1216. '<tr><td><code>/ping</code></td><td>send chat message with current ping</td></tr>' +
  1217. '<tr><td><code>/solo</code></td><td>show solo server message</td></tr>' +
  1218. '<tr><td><code>/dice</code></td><td>roll a dice with 6 sides</td></tr>' +
  1219. '<tr><td><code>/dice &lt;n></code></td><td>roll a dice with &lt;n> sides</td></tr>' +
  1220. '<tr><td><code>/linesplit</code></td><td>let your cell make a linesplit</td></tr>' +
  1221. '<tr><td><code>/waste</code></td><td>waste all your mass</td></tr>' +
  1222. '</table>';
  1223.  
  1224. $modal.append(helpText);
  1225.  
  1226. $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 () {
  1227. $modal.hide();
  1228. }));
  1229.  
  1230. $('body').append($modal);
  1231.  
  1232. this.$helpModal = $modal;
  1233.  
  1234. window.addEventListener('miracleCommand', function(commandEvent) {
  1235. if (commandEvent.command === '/miraclehelp') {
  1236. $('#chtbox').val('').focus();
  1237. $modal.show();
  1238. }
  1239. });
  1240. },
  1241.  
  1242. commands: function () {
  1243. var self = this;
  1244. var minutes;
  1245.  
  1246. var sessionStartedAt = Date.now();
  1247.  
  1248. $('#chtbox').keydown(function (event) {
  1249. if (event.keyCode === 13) {
  1250. var message = $('#chtbox').val();
  1251. var command = message.split(' ')[0];
  1252. var argument1 = message.split(' ')[1];
  1253. var argument2 = message.split(' ')[2];
  1254.  
  1255. if (message === 'time' || command === '/time') {
  1256. var now = new Date();
  1257. $('#chtbox').val('Local time: ' + now.toLocaleString()).focus();
  1258. }
  1259.  
  1260. if (message === 'minutes' || command === '/minutes' || message === 'online' || command === '/online') {
  1261. minutes = parseInt((Date.now() - sessionStartedAt) / 1000 / 60);
  1262. if (minutes > 60) {
  1263. minutes = '' + minutes;
  1264. minutes = parseInt(minutes / 60) + ' Hours & ' + (minutes % 60);
  1265. }
  1266. $('#chtbox').val('has played for: ' + minutes + ' Minutes in the current session').focus();
  1267. }
  1268.  
  1269. if (command === '/solo') {
  1270. $('#chtbox').val('⚠️⚠️⚠️ SOLO SERVER ⚠️⚠️⚠️ No teaming!! No hay equipo!! Pas d\'équipe!! Kein Teaming!!').focus();
  1271. }
  1272.  
  1273. if (command === '/miracle') {
  1274. var miracleInfo = 'is using 𝘔𝘪𝘳𝘢𝘤𝘭𝘦 𝘚𝘤𝘳𝘪𝘱𝘵𝘴, version ';
  1275.  
  1276. if (GM_info) {
  1277. miracleInfo += GM_info.script.version;
  1278. } else {
  1279. miracleInfo += 'unknown';
  1280. }
  1281.  
  1282. $('#chtbox').val(miracleInfo).focus();
  1283. }
  1284.  
  1285. if (command.substr(0, 4) === '/say' || (command === '/party' && argument1.substr(0, 4) === '/say') || (command === '/pm' && argument2.substr(0, 4) === '/say')) {
  1286. var prefix = '';
  1287. if (command === '/party' && argument1.substr(0, 4) === '/say') {
  1288. prefix = '/party ';
  1289. message = message.substr(7);
  1290. }
  1291. if (command === '/pm' && argument2.substr(0, 4) === '/say') {
  1292. var spacePos = message.indexOf(' ', 5);
  1293. prefix = message.substr(0, spacePos + 1);
  1294. message = message.substr(spacePos + 1);
  1295. }
  1296.  
  1297. var fontIndex = message.charAt(4) - 1;
  1298. if (fontIndex === NaN || fontIndex < 0 || fontIndex > Object.getOwnPropertyNames(self.fonts).length - 1) {
  1299. fontIndex = 1;
  1300. }
  1301.  
  1302. $('#chtbox').val(prefix + self.useUnicodeFont(message.substr(message.indexOf(' ') + 1), Object.getOwnPropertyNames(self.fonts)[fontIndex])).focus();
  1303. }
  1304.  
  1305. if (command === '/dice') {
  1306. var max = (argument1 > 0) ? parseInt(argument1) : 6;
  1307. var number = self.getRandomInt(1, max);
  1308. $('#chtbox').val('rolled a dice with ' + max + ' sides. Result: ' + number);
  1309. }
  1310.  
  1311. var commandEvent = new Event('miracleCommand');
  1312. commandEvent.message = message;
  1313. commandEvent.command = command;
  1314. commandEvent.argument1 = argument1;
  1315. commandEvent.argument2 = argument2;
  1316. window.dispatchEvent(commandEvent);
  1317. }
  1318. });
  1319. },
  1320.  
  1321. /**
  1322. * This object is a container for functions that convert english letters and digits to fancy Unicode characters
  1323. * @see https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
  1324. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumerics
  1325. * @see https://en.wikipedia.org/wiki/Enclosed_Alphanumeric_Supplement
  1326. */
  1327. fonts: {
  1328. doubleStruck : function(charCode) {
  1329. if (charCode === 67) { return String.fromCodePoint(0x2102); } // C
  1330. if (charCode === 72) { return String.fromCodePoint(0x210D); } // H
  1331. if (charCode === 78) { return String.fromCodePoint(0x2115); } // N
  1332. if (charCode === 80) { return String.fromCodePoint(0x2119); } // P
  1333. if (charCode === 81) { return String.fromCodePoint(0x211A); } // Q
  1334. if (charCode === 82) { return String.fromCodePoint(0x211D); } // R
  1335. if (charCode === 90) { return String.fromCodePoint(0x2124); } // Z
  1336. if (charCode >= 65 && charCode <= 90) {
  1337. return String.fromCodePoint(0x1D538 + charCode - 65);
  1338. }
  1339. if (charCode >= 97 && charCode <= 122) {
  1340. return String.fromCodePoint(0x1D552 + charCode - 97);
  1341. }
  1342. if (charCode >= 48 && charCode <= 57) {
  1343. return String.fromCodePoint(0x1D7D8 + charCode - 48);
  1344. }
  1345. return String.fromCharCode(charCode);
  1346. },
  1347.  
  1348. monospace : function(charCode) {
  1349. if (charCode >= 65 && charCode <= 90) {
  1350. return String.fromCodePoint(0x1D670 + charCode - 65);
  1351. }
  1352. if (charCode >= 97 && charCode <= 122) {
  1353. return String.fromCodePoint(0x1D68A + charCode - 97);
  1354. }
  1355. if (charCode >= 48 && charCode <= 57) {
  1356. return String.fromCodePoint(0x1D7F6 + charCode - 48);
  1357. }
  1358. return String.fromCharCode(charCode);
  1359. },
  1360.  
  1361. scriptBold : function(charCode) {
  1362. if (charCode >= 65 && charCode <= 90) {
  1363. return String.fromCodePoint(0x1D4D0 + charCode - 65);
  1364. }
  1365. if (charCode >= 97 && charCode <= 122) {
  1366. return String.fromCodePoint(0x1D4EA + charCode - 97);
  1367. }
  1368. if (charCode >= 48 && charCode <= 57) {
  1369. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1370. }
  1371. return String.fromCharCode(charCode);
  1372. },
  1373.  
  1374. frakturBold : function(charCode) {
  1375. if (charCode === 121) { return '𝐲'; } // y
  1376. if (charCode >= 65 && charCode <= 90) {
  1377. return String.fromCodePoint(0x1D56C + charCode - 65);
  1378. }
  1379. if (charCode >= 97 && charCode <= 122) {
  1380. return String.fromCodePoint(0x1D586 + charCode - 97);
  1381. }
  1382. if (charCode >= 48 && charCode <= 57) {
  1383. return String.fromCodePoint(0x1D7CE + charCode - 48);
  1384. }
  1385. return String.fromCharCode(charCode);
  1386. },
  1387.  
  1388. serifItalic: function(charCode) {
  1389. if (charCode === 104) { return String.fromCodePoint(0x1D629); } // h
  1390. if (charCode >= 65 && charCode <= 90) {
  1391. return String.fromCodePoint(0x1D434 + charCode - 65);
  1392. }
  1393. if (charCode >= 97 && charCode <= 122) {
  1394. return String.fromCodePoint(0x1D44E + charCode - 97);
  1395. }
  1396. return String.fromCharCode(charCode);
  1397. },
  1398.  
  1399. circled: function(charCode) {
  1400. if (charCode >= 65 && charCode <= 90) {
  1401. return String.fromCodePoint(0x24B6 + charCode - 65);
  1402. }
  1403. if (charCode >= 97 && charCode <= 122) {
  1404. return String.fromCodePoint(0x24D0 + charCode - 97);
  1405. }
  1406. if (charCode >= 49 && charCode <= 57) {
  1407. return String.fromCodePoint(0x2460 + charCode - 49);
  1408. }
  1409. return String.fromCharCode(charCode);
  1410. },
  1411.  
  1412. boxed: function(charCode) {
  1413. if (charCode >= 65 && charCode <= 90) {
  1414. return String.fromCodePoint(0x1F130 + charCode - 65);
  1415. }
  1416. if (charCode >= 97 && charCode <= 122) {
  1417. return String.fromCodePoint(0x1F130 + charCode - 97);
  1418. }
  1419. if (charCode >= 49 && charCode <= 57) {
  1420. return String.fromCodePoint(0x2460 + charCode - 49);
  1421. }
  1422. return String.fromCharCode(charCode);
  1423. }
  1424. },
  1425.  
  1426. useUnicodeFont: function(text, font) {
  1427. var converted = '';
  1428. for (var i = 0; i < text.length; i++) {
  1429. converted += this.fonts[font](text.charCodeAt(i));
  1430. }
  1431.  
  1432. return converted;
  1433. },
  1434.  
  1435. isWritingText: function() {
  1436. return document.activeElement.type === 'text' || document.activeElement.type === 'password' || document.activeElement.type === 'textarea';
  1437. },
  1438.  
  1439. download: function (filename, text) {
  1440. var element = document.createElement('a');
  1441. element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  1442. element.setAttribute('download', filename);
  1443.  
  1444. element.style.display = 'none';
  1445. document.body.appendChild(element);
  1446.  
  1447. element.click();
  1448.  
  1449. document.body.removeChild(element);
  1450. },
  1451.  
  1452. getVersionAsInt: function(stringVersion) {
  1453. if (stringVersion === undefined) {
  1454. stringVersion = typeof GM_info !== 'undefined' ? GM_info.script.version : '0';
  1455. }
  1456.  
  1457. var parts = stringVersion.split('.');
  1458. if (parts.length === 1) {
  1459. parts.push('0');
  1460. }
  1461. if (parts.length === 2) {
  1462. parts.push('0');
  1463. }
  1464.  
  1465. return parseInt(parts[0]) * 1000000 + parseInt(parts[1]) * 1000 + parseInt(parts[2]);
  1466. },
  1467.  
  1468. /**
  1469. * Returns a random number between min and max (both inclusive)
  1470. * Source: MDN
  1471. */
  1472. getRandomInt: function (min, max) {
  1473. return Math.round(Math.random() * (max - min) + min);
  1474. },
  1475.  
  1476. /**
  1477. * Use the curser div to display a message at the top of the screen.
  1478. *
  1479. * @param message
  1480. * @param isError
  1481. */
  1482. message: function (message, isError) {
  1483. var curser = document.querySelector('#curser');
  1484.  
  1485. curser.textContent = message;
  1486. curser.style.display = 'block';
  1487. curser.style.color = isError ? 'rgb(255, 0, 0)' : 'rgb(0, 192, 0)';
  1488.  
  1489. window.setTimeout(function () {
  1490. curser.style.display = 'none';
  1491. }, 5000);
  1492. },
  1493.  
  1494. /**
  1495. * Returns the URI of my skin or null if not skin has been set.
  1496. * Use this.skinUrl() to get it.
  1497. */
  1498. getSkinUrl: function() {
  1499. var skinUrlRaw = $('#skinExampleMenu').css('background-image');
  1500.  
  1501. var parts = skinUrlRaw.split('"');
  1502.  
  1503. if (parts.length !== 3) {
  1504. return null;
  1505. } else {
  1506. return parts[1];
  1507. }
  1508. },
  1509.  
  1510. setupPolyfills: function() {
  1511. // Polyfill for old browser so they have String.fromCodePoint()
  1512. if (!String.fromCodePoint) (function(stringFromCharCode) {
  1513. var fromCodePoint = function(_) {
  1514. var codeUnits = [], codeLen = 0, result = "";
  1515. for (var index=0, len = arguments.length; index !== len; ++index) {
  1516. var codePoint = +arguments[index];
  1517. // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
  1518. // The surrounding `!(...)` is required to correctly handle `NaN` cases
  1519. // The (codePoint>>>0) === codePoint clause handles decimals and negatives
  1520. if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
  1521. throw RangeError("Invalid code point: " + codePoint);
  1522. if (codePoint <= 0xFFFF) { // BMP code point
  1523. codeLen = codeUnits.push(codePoint);
  1524. } else { // Astral code point; split in surrogate halves
  1525. // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  1526. codePoint -= 0x10000;
  1527. codeLen = codeUnits.push(
  1528. (codePoint >> 10) + 0xD800, // highSurrogate
  1529. (codePoint % 0x400) + 0xDC00 // lowSurrogate
  1530. );
  1531. }
  1532. if (codeLen >= 0x3fff) {
  1533. result += stringFromCharCode.apply(null, codeUnits);
  1534. codeUnits.length = 0;
  1535. }
  1536. }
  1537. return result + stringFromCharCode.apply(null, codeUnits);
  1538. };
  1539. try { // IE 8 only supports `Object.defineProperty` on DOM elements
  1540. Object.defineProperty(String, "fromCodePoint", {
  1541. "value": fromCodePoint, "configurable": true, "writable": true
  1542. });
  1543. } catch(e) {
  1544. String.fromCodePoint = fromCodePoint;
  1545. }
  1546. }(String.fromCharCode));
  1547. },
  1548. };
  1549.  
  1550. window.miracleScripts.init();
  1551. })();

QingJ © 2025

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