diff --git a/index.js b/index.js index 0d36ec6..6df914e 100644 --- a/index.js +++ b/index.js @@ -7,29 +7,28 @@ // import { urlSearchParams, sourceURL } from "./common/modules/constants.js"; -import { isValidHTTPURL } from "./common/modules/utilities.js"; +import { isValidHTTPURL, open } from "./common/modules/utilities.js"; const { default: sources } = await import("./common/assets/sources.json", { assert: { type: "json" } }); (function main() { - const success = url => window.location.replace(`./view/?source=${url}`); - - for (const url of sources) { + const textField = document.querySelector("input"); + + for (const url of sources) insertSource(url); + + // If source provided + if (urlSearchParams.has('source')) { + textField.value = urlSearchParams.get("source"); + textField.focus(); } - // If valid source provided - if (urlSearchParams.has('source') && isValidHTTPURL(sourceURL)) - success(sourceURL); - - const textField = document.querySelector("input"); textField.addEventListener("keypress", function (event) { if (event.key === "Enter") { event.preventDefault(); - - const url = textField.value; - if (!isValidHTTPURL(url)) + const sourceURL = textField.value; + if (!isValidHTTPURL(sourceURL)) alert("Invalid HTTP URL."); - else success(url); + else open((`./view/?source=${sourceURL}`)) } }); diff --git a/view/index.html b/view/index.html index d179e6c..7ae630e 100644 --- a/view/index.html +++ b/view/index.html @@ -25,7 +25,7 @@
AltSource Viewer