mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-19 19:13:33 +00:00
Improve source editing
This commit is contained in:
23
index.js
23
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}`);
|
||||
const textField = document.querySelector("input");
|
||||
|
||||
for (const url of sources) {
|
||||
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}`))
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<p>AltSource Viewer</p>
|
||||
<div class="header">
|
||||
<h1 id="title">altsource-v2</h1>
|
||||
<a href="../" style="font-size: 0.75em; font-weight: 750;">EDIT</a>
|
||||
<a id="edit" href="../" style="font-size: 0.75em; font-weight: 750;">EDIT</a>
|
||||
</div>
|
||||
<div id="news" class="section">
|
||||
<div class="header">
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user