mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-20 03:13:57 +00:00
Improve source editing
This commit is contained in:
25
index.js
25
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}`))
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user