diff --git a/lib/main.js b/lib/main.js index b3b46ed..bbbe886 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,9 +27,7 @@ */ const LOCAL_STORAGE_KEY = "recentInstances"; -const RECENT_INSTANCES_SIZE = 5; -const $form = document.querySelector("#js-s2f-form"); const $instance = document.querySelector("#instance"); /** @@ -54,31 +52,6 @@ function getRecentInstances() { return JSON.parse(storedValue); } -function rememberInstance(instance) { - const recentInstances = getRecentInstances(); - - const index = recentInstances.indexOf(instance); - if (index >= 0) { - recentInstances.splice(index, 1); - } - recentInstances.unshift(instance); - recentInstances.length = RECENT_INSTANCES_SIZE; - - window.localStorage.setItem( - LOCAL_STORAGE_KEY, - JSON.stringify(recentInstances), - ); -} - -function onFormSubmit(event) { - const formData = new FormData(event.target); - - if (formData.get("remember")) { - rememberInstance(formData.get("instance")); - } - return true; -} - let prefillInstance = getRecentInstances()[0]; const URLParameters = window.location.search.slice(1).split("&"); @@ -96,5 +69,3 @@ for (const URLParameter of URLParameters) { if (prefillInstance != undefined) { $instance.value = normalizeUrl(prefillInstance); } - -$form.addEventListener("submit", onFormSubmit); diff --git a/src/components/instance-select.astro b/src/components/instance-select.astro index de97d21..10f72d1 100644 --- a/src/components/instance-select.astro +++ b/src/components/instance-select.astro @@ -12,7 +12,7 @@ try { {instances.map((instance) => )} - + Mastodon, Pleroma, or GNU Social instance https:// @@ -38,12 +38,19 @@ try { diff --git a/src/util.ts b/src/util.ts index 74e4395..5b7a2b1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,3 +1,19 @@ +/** + * Adds missing "https://" and ending slash to the URL + * + * @param url URL to normalize + * @return normalized URL + */ +export const normalizeURL = (url: string): string => { + if (!(url.startsWith("https://") || url.startsWith("http://"))) { + url = "https://" + url; + } + if (!url.endsWith("/")) { + url += "/"; + } + return url; +}; + export const extractHost = (url: string): string => { if (!(url.startsWith("https://") || url.startsWith("http://"))) { url = "https://" + url;