crafatar.js 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var valid_user_id = /^[0-9a-f-A-F-]{32,36}$/; // uuid
  2. var quotes = [
  3. ["Crafatar is the best at what it does.", "Shotbow Network", "https://twitter.com/ShotbowNetwork/status/565201303555829762"],
  4. ["Crafatar seems to stand out from others", "Dabsunter", "https://github.com/crafatar/crafatar/wiki/What-people-say-about-Crafatar"],
  5. ["I can’t tell you how much Crafatar helped me along the way! You guys do some amazing work.", "Luke Chatton", "https://github.com/lukechatton"],
  6. ["It's just awesome! Keep up the good work", "Dannyps", "https://forums.spongepowered.org/t/title-cant-be-empty/4964/22"],
  7. ["It's one of the few services that actually does HTTP header caching correctly", "confuser", "https://github.com/BanManagement/BanManager-WebUI/issues/16#issuecomment-73230674"],
  8. ["It's so beautiful. <3", "FerusGrim", "https://twitter.com/FerusGrim/status/642824817683656704"],
  9. ["Love it! It's great!", "Reddit User", "https://reddit.com/comments/2nth0j/-/cmh5771"],
  10. ["Such a useful service!", "Tim Z, NameMC", "https://twitter.com/CoderTimZ/status/602682146793349120"],
  11. ["Thanks for providing us with such a reliable service :)", "BeanBlockz", "https://twitter.com/BeanBlockz/status/743927789422845952"],
  12. ["This is excellent for my website! Good work.", "cyanide43", "https://reddit.com/comments/2nth0j/-/cmgpq85"],
  13. ["This is really cool!", "AlexWebber", "https://forums.spongepowered.org/t/crafatar-a-new-minecraft-avatar-service/4964/19"],
  14. ["This really is looking amazing. Absolutely love it!", "Enter_", "https://forums.spongepowered.org/t/crafatar-a-new-minecraft-avatar-service/4964/21"],
  15. ["We couldn't believe how flawless your API is, Good job!", "SenceServers", "https://twitter.com/SenceServers/status/697132506626265089"],
  16. ["WOW, Crafatar is FAST", "Rileriscool", "https://twitter.com/rileriscool/status/562057234986065921"],
  17. ["You deserve way more popularity", "McSlushie", "https://github.com/crafatar/crafatar/wiki/Credit/a8f37373531b1d2c2cb3557ba809542a2ed81626"],
  18. ["You do excellent work on Crafatar and are awesome! A very polished, concise & clean project.", "DrCorporate", "https://reddit.com/comments/2r1ns6/-/cnbq5f1"]
  19. ];
  20. // shuffle quotes
  21. for (i = quotes.length -1; i > 0; i--) {
  22. var a = Math.floor(Math.random() * i);
  23. var b = quotes[i];
  24. quotes[i] = quotes[a];
  25. quotes[a] = b;
  26. }
  27. var current_quote = 0;
  28. function changeQuote() {
  29. var elem = document.querySelector("#quote");
  30. var quote = quotes[current_quote];
  31. elem.innerHTML = "<b>“" + quote[0] + "”</b><br>― <i>" + quote[1] + "</i>";
  32. elem.href = quote[2];
  33. current_quote = (current_quote + 1) % quotes.length;
  34. }
  35. fetch('https://mc-heads.net/json/mc_status').then(r => r.json()).then(data => {
  36. var textures_err = data.report.skins.status !== "up";
  37. var session_err = data.report.session.status !== "up";
  38. if (textures_err || session_err) {
  39. var warn = document.createElement("div");
  40. warn.setAttribute("class", "alert alert-warning");
  41. warn.setAttribute("role", "alert");
  42. warn.innerHTML = "<h5>Mojang issues</h5> Mojang's servers are having trouble <i>right now</i>, this may affect requests at Crafatar. <small><a href=\"https://mc-heads.net/mcstatus\" target=\"_blank\">check status</a>";
  43. document.querySelector("#alerts").appendChild(warn);
  44. }
  45. });
  46. document.addEventListener("DOMContentLoaded", function(event) {
  47. var avatars = document.querySelector("#avatar-wrapper");
  48. // shuffle avatars
  49. for (var i = 0; i < avatars.children.length; i++) {
  50. avatars.appendChild(avatars.children[Math.random() * i | 0]);
  51. }
  52. setInterval(changeQuote, 5000);
  53. changeQuote();
  54. var tryit = document.querySelector("#tryit");
  55. var tryname = document.querySelector("#tryname");
  56. var images = document.querySelectorAll(".tryit");
  57. tryit.onsubmit = function(e) {
  58. e.preventDefault();
  59. tryname.value = tryname.value.trim();
  60. var value = tryname.value || "853c80ef3c3749fdaa49938b674adae6";
  61. if (!valid_user_id.test(value)) {
  62. tryname.value = "";
  63. return;
  64. }
  65. for (var j = 0; j < images.length; j++) {
  66. images[j].src = images[j].dataset.src.replace("$", value);
  67. }
  68. };
  69. });