burgernotes-client-web/static/js/homeserver.js

58 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-06-22 14:58:29 +01:00
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
2024-03-12 18:34:05 +00:00
let homeserverBox = document.getElementById("homeserverBox")
let statusBox = document.getElementById("statusBox")
let changeButton = document.getElementById("changeButton")
function showElements(yesorno) {
if (!yesorno) {
homeserverBox.classList.add("hidden")
changeButton.classList.add("hidden")
}
else {
homeserverBox.classList.remove("hidden")
changeButton.classList.remove("hidden")
}
}
changeButton.addEventListener("click", (event) => {
async function doStuff() {
let remote = homeserverBox.value
if (remote == "") {
statusBox.innerText = "A homeserver is required!"
return
}
showElements(false)
statusBox.innerText = "Connecting to homeserver..."
fetch(remote + "/api/version")
.then((response) => response)
.then((response) => {
async function doStuff() {
if (response.status == 200) {
localStorage.setItem("homeserverURL", remote)
2024-03-15 17:01:55 +00:00
if (document.referrer !== "") {
window.location.href = document.referrer;
}
else {
window.location.href = "https://notes.hectabit.org/login";
}
2024-03-12 18:34:05 +00:00
}
else if (response.status == 404) {
statusBox.innerText = "Not a valid homeserver!"
}
else {
statusBox.innerText = "Something went wrong!"
showElements(true)
}
}
doStuff()
});
}
doStuff()
});
2024-06-22 14:58:29 +01:00
// @license-end