`;
\ No newline at end of file
diff --git a/js/index.js b/js/index.js
index c6e6eac..337caad 100644
--- a/js/index.js
+++ b/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) {
${description}
- `);
+ `);
else document.getElementById("about").remove();
-}
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/js/main.js b/js/main.js
index 68663b5..46e3863 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,54 +1,75 @@
-(function () {
- // If no source
- if (!urlSearchParams.has('source'))
- search();
- // If source is not a valid HTTP URL
- else if (!isValidHTTPURL(sourceURL)) {
- alert("Invalid HTTP URL.");
- search();
- }
-})();
+//
+// main.js
+// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
+//
+// Copyright (c) 2023 Foxster.
+// MIT License.
+//
-fetch(sourceURL)
- .then(response => response.json())
- .then(json => {
- // Set tint color
- const tintColor = json.tintColor?.replaceAll("#", "");
- if (tintColor) setTintColor(tintColor);
+import { urlSearchParams, sourceURL, search, isValidHTTPURL, setTintColor, insertAltStoreBanner, setUpBackButton } from "./utilities.js";
- insertAddToAltStoreBanner(json.name);
+export function main(callback) {
+ (() => {
+ // If no source
+ if (!urlSearchParams.has('source'))
+ search();
+ // If source is not a valid HTTP URL
+ else if (!isValidHTTPURL(sourceURL)) {
+ alert("Invalid HTTP URL.");
+ search();
+ }
- setApps(json.apps);
- main(json);
- waitForAllImagesToLoad();
- })
- .catch(error => console.error("An error occurred.", error));
+ var apps;
+ window.setApps = array =>
+ apps = array;
+ window.getAppWithBundleId = bundleId =>
+ apps?.find(app => app.bundleIdentifier == bundleId) ?? undefined;
-function waitForAllImagesToLoad() {
- const allImages = document.querySelectorAll("img");
- var count = 0;
+ setUpBackButton();
+ })();
- allImages.forEach(image => {
- // New img element that won't be rendered to the DOM
- var newImage = document.createElement("img");
- // Attach load listener
- newImage.addEventListener("load", loaded);
- // Set src
- newImage.src = image.src;
+ fetch(sourceURL)
+ .then(response => response.json())
+ .then(json => {
+ // Set tint color
+ const tintColor = json.tintColor?.replaceAll("#", "");
+ if (tintColor) setTintColor(tintColor);
- // Unable to load image
- image.addEventListener("error", (event) => {
- if (event.target.id == "app-icon") {
- event.target.src = "img/generic_app.jpeg";
- } else event.target.remove()
- loaded();
+ insertAltStoreBanner(json.name);
+
+ setApps(json.apps);
+ // main(json);
+ callback(json);
+ waitForAllImagesToLoad();
+ })
+ .catch(error => console.error("An error occurred.", error));
+
+ function waitForAllImagesToLoad() {
+ const allImages = document.querySelectorAll("img");
+ var count = 0;
+
+ allImages.forEach(image => {
+ // New img element that won't be rendered to the DOM
+ var newImage = document.createElement("img");
+ // Attach load listener
+ newImage.addEventListener("load", loaded);
+ // Set src
+ newImage.src = image.src;
+
+ // Unable to load image
+ image.addEventListener("error", (event) => {
+ if (event.target.id == "app-icon") {
+ event.target.src = "img/generic_app.jpeg";
+ } else event.target.remove()
+ loaded();
+ });
});
- });
- function loaded() {
- if (++count == allImages.length) {
- document.querySelector("body").classList.remove("loading");
- document.getElementById("loading").remove();
+ function loaded() {
+ if (++count == allImages.length) {
+ document.querySelector("body").classList.remove("loading");
+ document.getElementById("loading").remove();
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/js/news.js b/js/news.js
index 87ec0df..e0ae2d5 100644
--- a/js/news.js
+++ b/js/news.js
@@ -1,6 +1,18 @@
+//
+// news.js
+// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
+//
+// Copyright (c) 2023 Foxster.
+// MIT License.
+//
+
+import { insertNavigationBar } from "./utilities.js";
+import { NewsItem } from "./components/NewsItem.js";
+import { main } from "./main.js";
+
insertNavigationBar("All News");
-function main(json) {
+main((json) => {
// Set tab title
document.title = `News - ${json.name}`;
@@ -8,5 +20,5 @@ function main(json) {
json.news.sort((a, b) => (new Date(b.date)).valueOf() - (new Date(a.date)).valueOf());
// Create & insert news items
- json.news.forEach(news => document.getElementById("news").insertAdjacentHTML("beforeend", newsItemHTML(news)));
-}
\ No newline at end of file
+ json.news.forEach(news => document.getElementById("news").insertAdjacentHTML("beforeend", NewsItem(news)));
+});
\ No newline at end of file
diff --git a/js/search.js b/js/search.js
index 015127a..2e45913 100644
--- a/js/search.js
+++ b/js/search.js
@@ -1,3 +1,13 @@
+//
+// search.js
+// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
+//
+// Copyright (c) 2023 Foxster.
+// MIT License.
+//
+
+import { urlSearchParams, sourceURL } from "./utilities.js";
+
(function main() {
const success = url => window.location.replace(`index.html?source=${url}`);
diff --git a/js/shared.js b/js/shared.js
deleted file mode 100644
index df357ee..0000000
--- a/js/shared.js
+++ /dev/null
@@ -1,135 +0,0 @@
-const urlSearchParams = new URLSearchParams(window.location.search);
-const sourceURL = urlSearchParams.get('source')?.replaceAll("+", "%2B");
-// https://stackoverflow.com/a/8943487
-const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
-
-(function (global) {
- var apps;
- global.setApps = array =>
- apps = array;
- global.getAppWithBundleId = bundleId =>
- apps?.find(app => app.bundleIdentifier == bundleId) ?? undefined;
-
- setUpBackButton();
-})(this);
-
-const newsItemHTML = (news, minimal = false) => `
-