From 703de7188aa75c4010b4738007b361a2cb96efac Mon Sep 17 00:00:00 2001 From: foxster-mp4 Date: Sun, 30 Apr 2023 11:00:33 -0700 Subject: [PATCH] Rename home.js -> index.js --- js/index.js | 67 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/js/index.js b/js/index.js index ecc16dd..7f67bfb 100644 --- a/js/index.js +++ b/js/index.js @@ -1,17 +1,56 @@ -(function main() { - // If source specified, go straight to home page - if (urlSearchParams.has('source') && sourceURL.match(urlRegex)) - window.location.replace(`home.html?source=${sourceURL}`); +function main(json) { + // Set "View All News" link + document.querySelector("#news a").href = `news.html?source=${sourceURL}`; + // Set "View All Apps" link + document.querySelector("#apps a").href = `apps.html?source=${sourceURL}`; - const textField = document.querySelector("input"); - textField.addEventListener("keypress", function (event) { - if (event.key === "Enter") { - event.preventDefault(); + // Set tab title + document.title = json.name; + // Set page title + document.getElementById("title").innerText = json.name; - const url = textField.value; - if (!url.match(urlRegex)) - alert("Invalid URL."); - else window.location.replace(`home.html?source=${url}`); - } + // + // News + if (json.news && json.news.length >= 1) { + // Sort news in decending order of date (latest first) + json.news.sort((a, b) => // If b < a + (new Date(b.date)).valueOf() - (new Date(a.date)).valueOf()); + + if (json.news.length == 1) { + document.getElementById("news-items").insertAdjacentHTML("beforeend", newsItemHTML(json.news[0], true)); + document.getElementById("news-items").classList.add("one"); + } else for (let i = 0; i < 5 && i < json.news.length; i++) + document.getElementById("news-items").insertAdjacentHTML("beforeend", newsItemHTML(json.news[i], true)); + } else document.getElementById("news").remove(); + + // Sort apps in descending order of version date + json.apps.sort((a, b) => (new Date(b.versionDate)).valueOf() - (new Date(a.versionDate)).valueOf()); + + // + // Featured apps + let count = 1; + json.apps.forEach(app => { + // Max: 3 featured apps if not specified + if (count > 3) return; + + // Ignore beta apps + if (app.beta) return; + + // If there are featured apps, ignore non-featured apps + if (json.featuredApps && !json.featuredApps.includes(app.bundleIdentifier)) return; + + document.getElementById("apps").insertAdjacentHTML("beforeend", appHeaderHTML(app)); + + count++; }); -})(); \ No newline at end of file + + // + // About + var description = formatString(json.description); + if (description) document.getElementById("about").insertAdjacentHTML("beforeend", ` +
+

${description}

+
+ `); + else document.getElementById("about").remove(); +} \ No newline at end of file