Improve source editing

This commit is contained in:
foxster-mp4
2023-11-24 18:04:02 -08:00
parent d9be8d9461
commit 03275b1af1
3 changed files with 19 additions and 15 deletions

View File

@@ -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}`))
}
});