Re-implement pre-filling instances
This commit is contained in:
parent
43d36bd6d7
commit
49a489d532
2 changed files with 28 additions and 0 deletions
|
@ -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
6
src/util.ts
Normal 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;
|
||||
};
|
Reference in a new issue