Setting homeservers

This commit is contained in:
Tracker-Friendly 2024-03-12 17:09:34 +00:00
parent d37608fb54
commit 7fe0a4fbad
5 changed files with 105 additions and 3 deletions

51
static/js/homeserver.js Normal file
View File

@ -0,0 +1,51 @@
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 (username == "") {
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() {
let responseData = await response.json()
if (response.status == 200) {
localStorage.setItem("homeserverURL", remote)
history.back()
}
else if (response.status == 404) {
statusBox.innerText = "Not a valid homeserver!"
}
else {
statusBox.innerText = "Something went wrong!"
showElements(true)
}
}
doStuff()
});
}
doStuff()
});

View File

@ -9,7 +9,11 @@ if (localStorage.getItem("DONOTSHARE-password") !== null) {
throw new Error();
}
let remote = "https://notes.hectabit.org"
let remote = localStorage.getItem("homeserverURL")
if (remote == null) {
localStorage.setItem("homeserverURL", "https://notes.hectabit.org")
remote = "https://notes.hectabit.org"
}
let usernameBox = document.getElementById("usernameBox")
let passwordBox = document.getElementById("passwordBox")

View File

@ -13,7 +13,11 @@ if (localStorage.getItem("CACHE-username") !== null) {
document.getElementById("usernameBox").innerText = localStorage.getItem("CACHE-username")
}
let remote = "https://notes.hectabit.org"
let remote = localStorage.getItem("homeserverURL")
if (remote == null) {
localStorage.setItem("homeserverURL", "https://notes.hectabit.org")
remote = "https://notes.hectabit.org"
}
function formatBytes(a, b = 2) { if (!+a) return "0 Bytes"; const c = 0 > b ? 0 : b, d = Math.floor(Math.log(a) / Math.log(1000)); return `${parseFloat((a / Math.pow(1000, d)).toFixed(c))} ${["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]}` }

View File

@ -9,7 +9,11 @@ if (localStorage.getItem("DONOTSHARE-password") !== null) {
throw new Error();
}
let remote = "https://notes.hectabit.org"
let remote = localStorage.getItem("homeserverURL")
if (remote == null) {
localStorage.setItem("homeserverURL", "https://notes.hectabit.org")
remote = "https://notes.hectabit.org"
}
let usernameBox = document.getElementById("usernameBox")
let passwordBox = document.getElementById("passwordBox")

39
templates/homeserver.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Signup - Burgernotes</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="../static/css/style.css">
<script src="../static/js/hash-wasm.js"></script>
<style>
body {
background-color: #d9d9d9;
background-image: url("/static/svg/grid.svg");
background-repeat: repeat;
background-size: 312px
}
.inoutdiv {
background-color: #fff;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="inoutdiv">
<h2 class="w300">Homeserver</h2>
<p>Change your Burgernotes homeserver</p>
<p id="statusBox"></p>
<input type="text" value="https://" id="homeserverBox"><br>
<button id="changeButton">Change</button><br><br>
<p>Please put in the URL in standard format; https://, http://, etc.</p>
</div>
<script type="text/javascript" src="../static/js/signup.js"></script>
</body>
</html>