crafatar.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var valid_user_id = /^[0-9a-f-A-F-]{32,36}$/; // uuid
  2. var xhr = new XMLHttpRequest();
  3. var quotes = [
  4. ["Crafatar is the best at what it does.", "Shotbow Network", "https://twitter.com/ShotbowNetwork/status/565201303555829762"],
  5. ["Crafatar seems to stand out from others", "Dabsunter", "https://github.com/crafatar/crafatar/wiki/What-people-say-about-Crafatar"],
  6. ["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"],
  7. ["It's just awesome! Keep up the good work", "Dannyps", "https://forums.spongepowered.org/t/title-cant-be-empty/4964/22"],
  8. ["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"],
  9. ["It's so beautiful. <3", "FerusGrim", "https://twitter.com/FerusGrim/status/642824817683656704"],
  10. ["Love it! It's great!", "Reddit User", "https://reddit.com/comments/2nth0j/-/cmh5771"],
  11. ["Such a useful service!", "Tim Z, NameMC", "https://twitter.com/CoderTimZ/status/602682146793349120"],
  12. ["Thanks for providing us with such a reliable service :)", "BeanBlockz", "https://twitter.com/BeanBlockz/status/743927789422845952"],
  13. ["This is excellent for my website! Good work.", "cyanide43", "https://reddit.com/comments/2nth0j/-/cmgpq85"],
  14. ["This is really cool!", "AlexWebber", "https://forums.spongepowered.org/t/crafatar-a-new-minecraft-avatar-service/4964/19"],
  15. ["This really is looking amazing. Absolutely love it!", "Enter_", "https://forums.spongepowered.org/t/crafatar-a-new-minecraft-avatar-service/4964/21"],
  16. ["We couldn't believe how flawless your API is, Good job!", "SenceServers", "https://twitter.com/SenceServers/status/697132506626265089"],
  17. ["WOW, Crafatar is FAST", "Rileriscool", "https://twitter.com/rileriscool/status/562057234986065921"],
  18. ["You deserve way more popularity", "McSlushie", "https://github.com/crafatar/crafatar/wiki/Credit/a8f37373531b1d2c2cb3557ba809542a2ed81626"],
  19. ["You do excellent work on Crafatar and are awesome! A very polished, concise & clean project.", "DrCorporate", "https://reddit.com/comments/2r1ns6/-/cnbq5f1"]
  20. ];
  21. // shuffle quotes
  22. for (i = quotes.length -1; i > 0; i--) {
  23. var a = Math.floor(Math.random() * i);
  24. var b = quotes[i];
  25. quotes[i] = quotes[a];
  26. quotes[a] = b;
  27. }
  28. var current_quote = 0;
  29. function changeQuote() {
  30. var elem = document.querySelector("#quote");
  31. var quote = quotes[current_quote];
  32. elem.innerHTML = "<b>“" + quote[0] + "”</b><br>― <i>" + quote[1] + "</i>";
  33. elem.href = quote[2];
  34. current_quote = (current_quote + 1) % quotes.length;
  35. }
  36. xhr.onload = function() {
  37. var response = JSON.parse(xhr.responseText);
  38. var status = {};
  39. response.map(function(elem) {
  40. var key = Object.keys(elem)[0];
  41. status[key] = elem[key];
  42. });
  43. var textures_err = status["textures.minecraft.net"] !== "green";
  44. var session_err = status["sessionserver.mojang.com"] !== "green";
  45. if (textures_err || session_err) {
  46. var warn = document.createElement("div");
  47. warn.setAttribute("class", "alert alert-warning");
  48. warn.setAttribute("role", "alert");
  49. 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://help.mojang.com\" target=\"_blank\">check status</a>";
  50. document.querySelector("#alerts").appendChild(warn);
  51. }
  52. };
  53. document.addEventListener("DOMContentLoaded", function(event) {
  54. var avatars = document.querySelector("#avatar-wrapper");
  55. // shuffle avatars
  56. for (var i = 0; i < avatars.children.length; i++) {
  57. avatars.appendChild(avatars.children[Math.random() * i | 0]);
  58. }
  59. setInterval(changeQuote, 5000);
  60. changeQuote();
  61. var tryit = document.querySelector("#tryit");
  62. var tryname = document.querySelector("#tryname");
  63. var images = document.querySelectorAll(".tryit");
  64. tryit.onsubmit = function(e) {
  65. e.preventDefault();
  66. tryname.value = tryname.value.trim();
  67. var value = tryname.value || "853c80ef3c3749fdaa49938b674adae6";
  68. if (!valid_user_id.test(value)) {
  69. tryname.value = "";
  70. return;
  71. }
  72. for (var j = 0; j < images.length; j++) {
  73. images[j].src = images[j].dataset.src.replace("$", value);
  74. }
  75. };
  76. xhr.open("GET", "https://status.mojang.com/check", true);
  77. xhr.send();
  78. });