From 7612a6ad05a4016c5c1105dcc5f0e0f0aa8309c8 Mon Sep 17 00:00:00 2001 From: foxster-mp4 Date: Fri, 24 Nov 2023 19:20:17 -0800 Subject: [PATCH] Add go button --- index.css | 13 ++++++++++++- index.html | 3 ++- index.js | 35 ++++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/index.css b/index.css index 194e907..9b137d8 100644 --- a/index.css +++ b/index.css @@ -19,12 +19,15 @@ width: 95%; font-size: 1em; padding: 0.5rem 0.8rem; - margin-bottom: 1rem; border: none; border-radius: 10px; background-color: rgba(0, 0, 0, 0.07); } +/* input:focus { + outline: none; +} */ + .suggestion { padding: 1rem 1rem 1rem 0; margin-left: 1rem; @@ -57,4 +60,12 @@ align-items: center; justify-content: center; padding: 0 1rem; + gap: 0.85rem; + margin-bottom: 1rem; +} + +#go { + font-size: 1.1rem; + display: none; + transition: opacity 0.25s ease-in-out; } \ No newline at end of file diff --git a/index.html b/index.html index 0121f6e..8a1df1a 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,8 @@

AltSource Viewer

- + + Go
diff --git a/index.js b/index.js index cddc427..5f38eda 100644 --- a/index.js +++ b/index.js @@ -11,27 +11,48 @@ import { isValidHTTPURL, open } from "./common/modules/utilities.js"; const { default: sources } = await import("./common/assets/sources.json", { assert: { type: "json" } }); (function main() { - const textField = document.querySelector("input"); - for (const url of sources) insertSource(url); + const textField = document.querySelector("input"); + const goButton = document.getElementById("go"); + const viewSource = () => { + const sourceURL = textField.value; + if (!isValidHTTPURL(sourceURL)) + alert("Invalid HTTP URL."); + else open(`./view/?source=${sourceURL}`); + }; + // If source provided if (urlSearchParams.has('source')) { textField.value = urlSearchParams.get("source"); textField.focus(); } - textField.addEventListener("keypress", function (event) { + textField.addEventListener("keypress", event => { if (event.key === "Enter") { event.preventDefault(); - const sourceURL = textField.value; - if (!isValidHTTPURL(sourceURL)) - alert("Invalid HTTP URL."); - else open(`./view/?source=${sourceURL}`); + viewSource(); } }); + const toggleGoButton = () => { + if (textField.value.length) { + goButton.style.display = "block"; + setTimeout(() => { + goButton.style.opacity = 1; + }, 5); + } else { + goButton.style.opacity = 0; + setTimeout(() => { + goButton.style.display = "none"; + }, 125); + } + }; toggleGoButton(); + textField.addEventListener("input", toggleGoButton); + + goButton.addEventListener("click", viewSource); + async function insertSource(url) { fetch(url).then(data => data.json()).then(source => { document.getElementById("source-code").insertAdjacentHTML("beforebegin",`