From 03275b1af14b85380bee668ad42516a14cd1e6a2 Mon Sep 17 00:00:00 2001 From: foxster-mp4 Date: Fri, 24 Nov 2023 18:04:02 -0800 Subject: [PATCH] Improve source editing --- index.js | 25 ++++++++++++------------- view/index.html | 2 +- view/view.js | 7 ++++++- 3 files changed, 19 insertions(+), 15 deletions(-) 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

altsource-v2

- EDIT + EDIT
diff --git a/view/view.js b/view/view.js index df6d217..be8402b 100644 --- a/view/view.js +++ b/view/view.js @@ -7,12 +7,17 @@ // import { sourceURL } from "../common/modules/constants.js"; -import { formatString } from "../common/modules/utilities.js"; +import { formatString, open } from "../common/modules/utilities.js"; import { NewsItem } from "../common/components/NewsItem.js"; import { AppHeader } from "../common/components/AppHeader.js"; import { main } from "../common/modules/main.js"; main(json => { + document.getElementById("edit").addEventListener("click", e => { + e.preventDefault(); + open(`../?source=${sourceURL}`); + }); + // Set "View All News" link document.querySelector("#news a").href = `./news/?source=${sourceURL}`; // Set "View All Apps" link