mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-19 11:03:32 +00:00
Refactor
This commit is contained in:
27
js/index.js
27
js/index.js
@@ -1,4 +1,17 @@
|
||||
function main(json) {
|
||||
//
|
||||
// index.js
|
||||
// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
|
||||
//
|
||||
// Copyright (c) 2023 Foxster.
|
||||
// MIT License.
|
||||
//
|
||||
|
||||
import { sourceURL, formatString } from "./utilities.js";
|
||||
import { NewsItem } from "./components/NewsItem.js";
|
||||
import { AppHeader } from "./components/AppHeader.js";
|
||||
import { main } from "./main.js";
|
||||
|
||||
main((json) => {
|
||||
// Set "View All News" link
|
||||
document.querySelector("#news a").href = `news.html?source=${sourceURL}`;
|
||||
// Set "View All Apps" link
|
||||
@@ -17,15 +30,15 @@ function main(json) {
|
||||
(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").insertAdjacentHTML("beforeend", NewsItem(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));
|
||||
document.getElementById("news-items").insertAdjacentHTML("beforeend", NewsItem(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;
|
||||
@@ -39,7 +52,7 @@ function main(json) {
|
||||
// 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));
|
||||
document.getElementById("apps").insertAdjacentHTML("beforeend", AppHeader(app));
|
||||
|
||||
count++;
|
||||
});
|
||||
@@ -51,6 +64,6 @@ function main(json) {
|
||||
<div class="item">
|
||||
<p>${description}</p>
|
||||
</div>
|
||||
`);
|
||||
`);
|
||||
else document.getElementById("about").remove();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user