mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-23 12:33:40 +00:00
Update directory structure
This commit is contained in:
129
common/modules/constants.js
Normal file
129
common/modules/constants.js
Normal file
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// constants.js
|
||||
// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
|
||||
//
|
||||
// Copyright (c) 2023 Foxster.
|
||||
// MIT License.
|
||||
//
|
||||
|
||||
export const urlSearchParams = new URLSearchParams(window.location.search);
|
||||
|
||||
export const sourceURL = urlSearchParams.get('source')?.replaceAll("+", "%2B");
|
||||
|
||||
// https://stackoverflow.com/a/8943487
|
||||
export const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
|
||||
export const entitlements = {
|
||||
"com.apple.security.application-groups": {
|
||||
name: "App Groups",
|
||||
description: "Allow app to share files with other apps and app extensions in the same App Group.",
|
||||
icon: "columns-gap"
|
||||
},
|
||||
"com.apple.developer.associated-domains": {
|
||||
name: "Associated Domains",
|
||||
description: "The associated domains for specific services, such as shared web credentials, universal links, and App Clips.",
|
||||
icon: "globe2"
|
||||
},
|
||||
"com.apple.developer.carplay-audio": {
|
||||
name: "CarPlay Audio",
|
||||
description: "Allows the app the provide audio content for CarPlay.",
|
||||
icon: "car-front-fill"
|
||||
},
|
||||
"get-task-allow": {
|
||||
name: "Debuggable",
|
||||
description: "Allow developers to attach a debugger to this app. This permission is required for JIT to work.",
|
||||
icon: "tools"
|
||||
},
|
||||
"com.apple.developer.device-information.user-assigned-device-name": {
|
||||
name: "Device Name",
|
||||
description: "Grants access to the user-assigned device name instead of a generic device name.",
|
||||
icon: "phone-fill"
|
||||
},
|
||||
"keychain-access-groups": {
|
||||
name: "Keychain",
|
||||
description: "Allows app to read and write secure data to the system's keychain.",
|
||||
icon: "key-fill"
|
||||
},
|
||||
"com.apple.developer.networking.multicast": {
|
||||
name: "Multicast",
|
||||
description: "App can send or receive IP multicast traffic.",
|
||||
icon: "globe2"
|
||||
},
|
||||
"aps-environment": {
|
||||
name: "Push Notifications",
|
||||
description: "App can send push notifications.",
|
||||
icon: "app-indicator"
|
||||
},
|
||||
"com.apple.developer.applesignin": {
|
||||
name: "Sign in with Apple",
|
||||
description: "Allows sign in with Apple.",
|
||||
icon: "apple"
|
||||
},
|
||||
"com.apple.developer.siri": {
|
||||
name: "Siri",
|
||||
description: "Allows app to handle Siri requests.",
|
||||
icon: "mic-fill"
|
||||
},
|
||||
"com.apple.developer.networking.wifi-info": {
|
||||
name: "Wi-Fi Information Access",
|
||||
description: "Allows app to access information about the connected Wi-Fi network.",
|
||||
icon: "wifi"
|
||||
}
|
||||
};
|
||||
|
||||
export const privacy = {
|
||||
"AppleMusic": {
|
||||
icon: "music-note-beamed"
|
||||
},
|
||||
"BluetoothAlways": {
|
||||
name: "Bluetooth",
|
||||
icon: "bluetooth"
|
||||
},
|
||||
"BluetoothPeripheral": {
|
||||
name: "Bluetooth (Peripherals)",
|
||||
icon: "bluetooth"
|
||||
},
|
||||
"Contacts": {
|
||||
icon: "person-circle"
|
||||
},
|
||||
"Camera": {
|
||||
icon: "camera-fill"
|
||||
},
|
||||
"FaceID": {
|
||||
name: "Face ID",
|
||||
icon: "person-bounding-box"
|
||||
},
|
||||
"LocalNetwork": {
|
||||
icon: "globe2"
|
||||
},
|
||||
"LocationWhenInUse": {
|
||||
name: "Location (When Using)",
|
||||
icon: "cursor-fill"
|
||||
},
|
||||
"Microphone": {
|
||||
icon: "mic-fill"
|
||||
},
|
||||
"PhotoLibrary": {
|
||||
name: "Photos",
|
||||
icon: "images"
|
||||
},
|
||||
"PhotoLibraryAdd": {
|
||||
name: "Photos (Add)",
|
||||
icon: "image"
|
||||
},
|
||||
"UserTracking": {
|
||||
icon: "person-vcard-fill"
|
||||
},
|
||||
};
|
||||
|
||||
export const legacyPermissions = {
|
||||
"background-audio": {
|
||||
icon: "volume-up-fill"
|
||||
},
|
||||
"background-fetch": {
|
||||
icon: "arrow-repeat"
|
||||
},
|
||||
"photos": {
|
||||
icon: "images"
|
||||
}
|
||||
};
|
||||
77
common/modules/main.js
Normal file
77
common/modules/main.js
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// main.js
|
||||
// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
|
||||
//
|
||||
// Copyright (c) 2023 Foxster.
|
||||
// MIT License.
|
||||
//
|
||||
|
||||
import { urlSearchParams, sourceURL } from "./constants.js";
|
||||
import { isValidHTTPURL, setTintColor, insertAltStoreBanner, setUpBackButton, open } from "./utilities.js";
|
||||
|
||||
export function main(callback, fallbackURL = "../../") {
|
||||
// If no source
|
||||
if (!urlSearchParams.has('source')) {
|
||||
open(fallbackURL);
|
||||
return;
|
||||
}
|
||||
// If source is not a valid HTTP URL
|
||||
else if (!isValidHTTPURL(sourceURL)) {
|
||||
alert("Invalid HTTP URL.");
|
||||
open(fallbackURL);
|
||||
return;
|
||||
}
|
||||
|
||||
var apps;
|
||||
window.setApps = array =>
|
||||
apps = array;
|
||||
window.getAppWithBundleId = bundleId =>
|
||||
apps?.find(app => app.bundleIdentifier == bundleId) ?? undefined;
|
||||
|
||||
setUpBackButton();
|
||||
|
||||
fetch(sourceURL)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
// Set tint color
|
||||
const tintColor = json.tintColor?.replaceAll("#", "");
|
||||
if (tintColor) setTintColor(tintColor);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
96
common/modules/utilities.js
Normal file
96
common/modules/utilities.js
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// utilities.js
|
||||
// altsource-viewer (https://github.com/therealFoxster/altsource-viewer)
|
||||
//
|
||||
// Copyright (c) 2023 Foxster.
|
||||
// MIT License.
|
||||
//
|
||||
|
||||
import { AltStoreBanner } from "../components/AltStoreBanner.js";
|
||||
import { NavigationBar } from "../components/NavigationBar.js";
|
||||
import { urlRegex, sourceURL } from "./constants.js";
|
||||
|
||||
export function formatVersionDate(arg) {
|
||||
const versionDate = new Date(arg),
|
||||
month = versionDate.toUTCString().split(" ")[2],
|
||||
date = versionDate.getDate();
|
||||
const today = new Date();
|
||||
const msPerDay = 60 * 60 * 24 * 1000;
|
||||
const msDifference = today.valueOf() - versionDate.valueOf();
|
||||
|
||||
let dateString = versionDate.valueOf() ? `${month} ${date}, ${versionDate.getFullYear()}` : arg.split("T")[0];
|
||||
if (msDifference <= msPerDay && today.getDate() == versionDate.getDate())
|
||||
dateString = "Today";
|
||||
else if (msDifference <= msPerDay * 2)
|
||||
dateString = "Yesterday";
|
||||
|
||||
return dateString;
|
||||
}
|
||||
|
||||
export function insertSpaceInSnakeString(string) {
|
||||
return string.split(".").slice(-1)[0].split("-").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
||||
}
|
||||
|
||||
export function insertSpaceInCamelString(string) {
|
||||
// https://stackoverflow.com/a/38388188/19227228
|
||||
return string.match(/[A-Z][a-z]+|[0-9]+/g).join(" ");
|
||||
}
|
||||
|
||||
export function insertAltStoreBanner(sourceName) {
|
||||
document.getElementById("top")?.insertAdjacentHTML("afterbegin", AltStoreBanner(sourceName));
|
||||
}
|
||||
|
||||
export function insertNavigationBar(title) {
|
||||
document.getElementById("top")?.insertAdjacentHTML("beforeend", NavigationBar(title));
|
||||
setUpBackButton();
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/43467144/19227228
|
||||
export function isValidHTTPURL(string) {
|
||||
var url;
|
||||
try {
|
||||
url = new URL(string);
|
||||
} catch (error) {
|
||||
console.error("An error occurred.", error);
|
||||
return false;
|
||||
}
|
||||
return url.protocol == "http:" || url.protocol == "https:";
|
||||
}
|
||||
|
||||
export function formatString(string) {
|
||||
if (!string) return undefined;
|
||||
|
||||
// URLs
|
||||
const urlArray = string.match(urlRegex);
|
||||
// const urlSet = [...new Set(urlArray)]; // Converting to set to remove duplicates
|
||||
var result = "";
|
||||
urlArray?.forEach(url => {
|
||||
string = string.replace(url, `<a href="${url}">${url}</a>`)
|
||||
// Remove formatted substring so it won't get formatted again (prevents <a> tag within the href attribute another <a> tag)
|
||||
let endIndexOfClosingTag = string.indexOf("</a>") + 4;
|
||||
let formattedSubstring = string.substring(0, endIndexOfClosingTag);
|
||||
result += formattedSubstring;
|
||||
string = string.replace(formattedSubstring, "");
|
||||
});
|
||||
|
||||
result += string;
|
||||
|
||||
// New lines
|
||||
return result.replaceAll("\n", "<br>");
|
||||
}
|
||||
|
||||
export function setTintColor(color) {
|
||||
document.querySelector(':root')?.style.setProperty("--accent-color", `#${color}`);
|
||||
}
|
||||
|
||||
export function setUpBackButton() {
|
||||
document.getElementById("back")?.addEventListener("click", () => history.back());
|
||||
}
|
||||
|
||||
export function open(url) {
|
||||
window.open(url, "_self");
|
||||
}
|
||||
|
||||
const $ = selector => selector.startsWith("#") && !selector.includes(".") && !selector.includes(" ")
|
||||
? document.getElementById(selector.substring(1))
|
||||
: document.querySelectorAll(selector);
|
||||
Reference in New Issue
Block a user