1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-26 10:05:10 +00:00

MineXLauncher 1.1

This commit is contained in:
zumbiepig
2024-07-24 13:05:45 -07:00
parent c403967f1c
commit 9c9c8196b3
389 changed files with 41700 additions and 35751 deletions

View File

@@ -1,191 +1,202 @@
let selectedVersion = "";
document.addEventListener("DOMContentLoaded", function () {
if (window.location.pathname === "/") {
if (isMobile()) {
createFullscreenEmbed("/mobile/");
} else {
createFullscreenEmbed("/home/");
}
}
if (window.location.pathname === "/mobile/") {
selectVersion("/game/web/mobile/1.8.8/", "1.8.8");
toggleOptions();
}
const usernameForm = document.getElementById("username-form") as HTMLFormElement;
const usernameInput = document.getElementById("username-input") as HTMLInputElement;
const profileName = document.getElementById("profile-name");
const usernameForm = document.getElementById("username-form") as HTMLFormElement | null;
const usernameInput = document.getElementById("username-input") as HTMLInputElement | null;
const profileName = document.getElementById("profile-name");
const savedUsername = cookie.get("launcherUsername");
if (profileName && savedUsername) {
profileName.textContent = savedUsername;
} else if (profileName && !savedUsername) {
profileName.textContent = "Default";
}
const savedUsername = getCookie("username");
if (savedUsername && profileName) {
profileName.textContent = savedUsername;
}
if (usernameForm && usernameInput && profileName) {
usernameForm.addEventListener("submit", function (event) {
event.preventDefault();
const username = usernameInput.value.trim();
if (username) {
profileName.textContent = username;
setCookie("username", username, 365);
}
});
}
if (profileName && window.location.pathname === "/settings/") {
usernameForm.addEventListener("submit", function (event) {
event.preventDefault();
const username = usernameInput.value.trim();
if (username) {
profileName.textContent = username;
cookie.set("launcherUsername", username, 365);
}
});
}
});
function toggleOptions() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
if (customOptions) customOptions.classList.toggle("open");
if (customSelect) customSelect.classList.toggle("open");
}
const versionSelector = {
open() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
if (customOptions && customSelect) {
customOptions.classList.add("open");
customSelect.classList.add("open");
}
},
close() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
if (customOptions && customSelect) {
customOptions.classList.remove("open");
customSelect.classList.remove("open");
}
},
toggle() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
if (customOptions && customSelect) {
customOptions.classList.toggle("open");
customSelect.classList.toggle("open");
}
},
};
function selectVersion(path: string, name: string) {
selectedVersion = path;
const selector = document.querySelector(".custom-select");
if (selector?.textContent) {
selector.textContent = `Selected: ${name}`;
}
toggleOptions();
}
const game = {
play(version?: string) {
if (version) {
embed.remove();
// @ts-expect-error 1234567890
window.top.location.href = version;
} else if (selectedVersion) {
embed.remove();
// @ts-expect-error 1234567890
window.top.location.href = selectedVersion;
} else {
alert("Please select a version to play.");
return;
}
},
select(path: string, name: string) {
selectedVersion = path;
const selector = document.querySelector(".custom-select");
if (selector?.textContent) {
if (name) {
selector.textContent = `Selected: ${name}`;
} else {
selector.textContent = `Selected: ${path}`;
}
}
versionSelector.close();
},
archive(client: string) {
const clients: Record<string, string> = {
"1.8.8": "18-client-version",
"1.5.2": "15-client-version",
"b1.3": "b13-client-version",
};
const dropdown = clients[client] ? (document.getElementById(clients[client]) as HTMLSelectElement) : null;
if (dropdown?.value) {
selectedVersion = `https://archive.eaglercraft.rip/Eaglercraft${client === "b1.3" ? "_b1.3" : `_${client}`}/client/${dropdown.value}/index.html`;
game.play();
}
},
};
function playGame() {
if (!selectedVersion) {
alert("Please select a version to play.");
return;
}
replaceFullscreenEmbed(selectedVersion);
}
const embed = {
create() {
const iframe = document.createElement("iframe");
iframe.id = "embed";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "none";
if (isMobile()) {
iframe.src = "/mobile/";
} else {
iframe.src = "/home/";
}
document.body.appendChild(iframe);
},
remove() {
const iframe = document.getElementById("embed");
iframe?.remove();
},
};
function openClientManually(clientName: string) {
replaceFullscreenEmbed(clientName);
}
const navigate = {
home: {
game() {
window.location.href = "/home/game/";
},
clients() {
window.location.href = "/home/clients/";
},
archive() {
window.location.href = "/home/archive/";
},
downloads() {
window.location.href = "/home/downloads/";
},
},
mods: {
client() {
window.location.href = "/mods/client/";
},
mods() {
window.location.href = "/mods/mods/";
},
resourcepacks() {
window.location.href = "/mods/resourcepacks/";
},
},
mobile() {
window.location.href = "/mobile/";
},
updates() {
window.location.href = "/updates/";
},
servers() {
window.location.href = "/servers/";
},
settings() {
window.location.href = "/settings/";
},
};
function openOldClient(client: string) {
const clients: Record<string, string> = {
"1.8.8": "18-client-version",
"1.5.2": "15-client-version",
"b1.3": "b13-client-version"
};
const cookie = {
get(name: string): string | null {
const cookieArr = document.cookie.split(";");
for (const cookie of cookieArr) {
const cookiePair = cookie.split("=");
if (name === cookiePair[0]?.trim()) {
return decodeURIComponent(cookiePair[1] ?? "");
}
}
return null;
},
set(name: string, value: string, days: number) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/; domain=" + window.location.hostname.replace(/^www\./, "");
},
};
const dropdown = clients[client] ? document.getElementById(clients[client]) as HTMLSelectElement : null;
if (dropdown?.value) {
selectedVersion = `https://archive.eaglercraft.rip/Eaglercraft${client === 'b1.3' ? '_b1.3' : `_${client}`}/client/${dropdown.value}/index.html`;
playGame();
}
}
function navigateTo(path: string) {
window.location.href = path;
}
function navigateToHome() { navigateTo("/home/"); }
function navigateToMobile() { navigateTo("/mobile/"); }
function navigateToUpdates() { navigateTo("/updates/"); }
function navigateToSettings() { navigateTo("/settings/"); }
function navigateToServers() { navigateTo("/servers/"); }
function navigateToDownloads() { navigateTo("/downloads/"); }
function navigateToOther() { navigateTo("/other/"); }
function navigateToResource() { navigateTo("/mods/resourcepacks/"); }
function navigateToArchive() { navigateTo("/archive/"); }
function navigateToMods() { navigateTo("/mods/"); }
function navigateToModClient() { navigateTo("/mods/modclient/"); }
const query = {
get(name: string) {
const urlParams = new URLSearchParams(top?.location.search);
return urlParams.get(name);
},
};
function isMobile(): boolean {
try {
document.exitPointerLock();
return /Mobi/i.test(window.navigator.userAgent);
} catch (e) {
return true;
}
try {
document.exitPointerLock();
return /Mobi/i.test(window.navigator.userAgent);
} catch (e) {
return true;
}
}
function getCookie(name: string): string | null {
const cookieArr = document.cookie.split(";");
for (const cookie of cookieArr) {
const cookiePair = cookie.split("=");
if (name === cookiePair[0]?.trim()) {
return decodeURIComponent(cookiePair[1] ?? "");
}
}
return null;
}
function setCookie(name: string, value: string, days: number) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/; domain=" + window.location.hostname.replace(/^www\./, "");
}
function createFullscreenEmbed(url: string) {
const iframe = document.createElement("iframe");
iframe.id = "fullscreenEmbed";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "none";
iframe.src = url;
document.body.appendChild(iframe);
}
function replaceFullscreenEmbed(url: string) {
const fullscreenEmbed = window.parent.document.getElementById("fullscreenEmbed") as HTMLIFrameElement | null;
if (fullscreenEmbed) {
fullscreenEmbed.src = url;
fullscreenEmbed.focus();
}
}
function removeFullscreenEmbed() {
const iframe = window.parent.document.getElementById("fullscreenEmbed");
if (iframe) {
iframe.remove();
}
}
async function enterFullscreen() {
const element = document.getElementById("fullscreenEmbed");
if (!document.fullscreenElement) {
if (element) {
await element.requestFullscreen();
}
}
}
async function exitFullscreen() {
if (document.fullscreenElement) {
await document.exitFullscreen();
}
}
if (window.location.hostname === '0.0.0.0') { noUnusedFunctions }
function noUnusedFunctions() {
openClientManually
openOldClient
navigateTo
getCookie
setCookie
removeFullscreenEmbed
enterFullscreen
exitFullscreen
navigateToArchive
navigateToHome
navigateToMobile
navigateToUpdates
navigateToSettings
navigateToServers
navigateToDownloads
navigateToOther
navigateToResource
navigateToMods
navigateToModClient
if (window.location.hostname === "0.0.0.0") {
versionSelector;
game;
navigate;
query;
isMobile;
}