From 29955a1765f2f2f52150d3590cd16baded3a80a8 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 10 Sep 2020 22:32:23 +0200 Subject: [PATCH] improve mojang status message as Mojang has removed their status page and their status API is no longer updating, status information is now fetched from https://mc-heads.net/json/mc_status and the warning message links to https://mc-heads.net/mcstatus see #271, closes #272 --- lib/public/javascript/crafatar.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/public/javascript/crafatar.js b/lib/public/javascript/crafatar.js index 8b21262..243112f 100644 --- a/lib/public/javascript/crafatar.js +++ b/lib/public/javascript/crafatar.js @@ -1,5 +1,4 @@ var valid_user_id = /^[0-9a-f-A-F-]{32,36}$/; // uuid -var xhr = new XMLHttpRequest(); var quotes = [ ["Crafatar is the best at what it does.", "Shotbow Network", "https://twitter.com/ShotbowNetwork/status/565201303555829762"], @@ -37,25 +36,18 @@ function changeQuote() { current_quote = (current_quote + 1) % quotes.length; } -xhr.onload = function() { - var response = JSON.parse(xhr.responseText); - var status = {}; - response.map(function(elem) { - var key = Object.keys(elem)[0]; - status[key] = elem[key]; - }); - - var textures_err = status["textures.minecraft.net"] !== "green"; - var session_err = status["sessionserver.mojang.com"] !== "green"; +fetch('https://mc-heads.net/json/mc_status').then(r => r.json()).then(data => { + var textures_err = data.report.skins.status !== "up"; + var session_err = data.report.session.status !== "up"; if (textures_err || session_err) { var warn = document.createElement("div"); warn.setAttribute("class", "alert alert-warning"); warn.setAttribute("role", "alert"); - warn.innerHTML = "
Mojang issues
Mojang's servers are having trouble right now, this may affect requests at Crafatar. check status"; + warn.innerHTML = "
Mojang issues
Mojang's servers are having trouble right now, this may affect requests at Crafatar. check status"; document.querySelector("#alerts").appendChild(warn); } -}; +}); document.addEventListener("DOMContentLoaded", function(event) { var avatars = document.querySelector("#avatar-wrapper"); @@ -82,7 +74,4 @@ document.addEventListener("DOMContentLoaded", function(event) { images[j].src = images[j].dataset.src.replace("$", value); } }; - - xhr.open("GET", "https://status.mojang.com/check", true); - xhr.send(); }); \ No newline at end of file