Re-implement pre-filling instances

This commit is contained in:
Nikita Karamov 2023-03-17 23:08:15 +01:00
parent 43d36bd6d7
commit 49a489d532
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD
2 changed files with 28 additions and 0 deletions

View file

@ -59,3 +59,25 @@ try {
}
}
</style>
<script>
import { extractHost } from "../util";
const LOCAL_STORAGE_KEY = "recentInstances";
const $instance: HTMLInputElement = document.querySelector("#instance");
const getSavedInstances = (): Array<string> => {
const storageValue = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (!storageValue) {
return [];
}
return JSON.parse(storageValue);
};
const savedInstance = getSavedInstances()[0];
if (savedInstance) {
$instance.value = extractHost(savedInstance);
}
</script>

6
src/util.ts Normal file
View file

@ -0,0 +1,6 @@
export const extractHost = (url: string): string => {
if (!(url.startsWith("https://") || url.startsWith("http://"))) {
url = "https://" + url;
}
return new URL(url).host;
};