diff --git a/static/js/homeserver.js b/static/js/homeserver.js new file mode 100644 index 0000000..a275639 --- /dev/null +++ b/static/js/homeserver.js @@ -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() +}); diff --git a/static/js/login.js b/static/js/login.js index 7f08d9d..53f9238 100644 --- a/static/js/login.js +++ b/static/js/login.js @@ -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") diff --git a/static/js/main.js b/static/js/main.js index 29dbc2e..7007b94 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -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]}` } diff --git a/static/js/signup.js b/static/js/signup.js index 41ef00b..5c983c8 100644 --- a/static/js/signup.js +++ b/static/js/signup.js @@ -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") diff --git a/templates/homeserver.html b/templates/homeserver.html new file mode 100644 index 0000000..270ad69 --- /dev/null +++ b/templates/homeserver.html @@ -0,0 +1,39 @@ + + + + + Signup - Burgernotes + + + + + + + + + +
+

Homeserver

+

Change your Burgernotes homeserver

+

+ +
+

+

Please put in the URL in standard format; https://, http://, etc.

+
+ + + + +