Add usimp.js

This commit is contained in:
2021-05-09 15:57:15 +02:00
parent f77882baf7
commit 7bb9c67f52
4 changed files with 88 additions and 38 deletions

View File

@ -9,7 +9,7 @@ function createWelcomeWindow() {
win.innerHTML = `
<h1>Welcome to Locutus!</h1>
<a href="#/login">Login</a>`;
<a href="#/login" class="button">Login</a>`;
while (windows.lastChild) windows.removeChild(windows.lastChild);
windows.appendChild(win);
@ -22,11 +22,22 @@ function createLoginWindow() {
win.innerHTML = `
<h1>Login to USIMP Account</h1>
<form>
<input name="account" placeholder="Account name" type="text"/>
<input name="domain" placeholder="Domain" type="text"/>
<input name="password" placeholder="Password" type="password"/>
<input name="account" placeholder="Account name" type="text" required/>
<input name="domain" placeholder="Domain" type="text" pattern="([a-zA-Z0-9_-]+\\.)+[a-zA-Z]{2,}" required/>
<input name="password" placeholder="Password" type="password" required/>
<button type="submit">Login</button>
</form>`;
win.getElementsByTagName('form')[0].addEventListener("submit", function (evt) {
evt.preventDefault();
let form = evt.target;
usimp.lookup(form.domain.value)
.then(res => res.json()
.then(data => console.log(data))
.catch(reason => console.error(reason)))
.catch(reason => console.error(reason));
});
while (windows.lastChild) windows.removeChild(windows.lastChild);
windows.appendChild(win);
}
@ -53,7 +64,7 @@ function handleUrl(url) {
handleHash(new URL(url).hash);
}
window.addEventListener("load", function () {
window.addEventListener("DOMContentLoaded", function () {
main = document.getElementsByTagName("main")[0];
windows = document.getElementById("windows");

9
www/res/js/usimp.js Normal file
View File

@ -0,0 +1,9 @@
"use strict";
let usimp = {};
usimp.lookup = function (domain_name) {
return fetch(`https://${domain_name}/.well-known/usimp.json`, {
redirect: "manual",
});
}