1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-26 10:05:10 +00:00
This commit is contained in:
zumbiepig
2024-07-25 15:09:32 -07:00
parent 0a46d808f4
commit 7ea56cb254
27 changed files with 216 additions and 205 deletions

View File

@@ -1,52 +1,44 @@
let selectedVersion = "";
document.addEventListener("DOMContentLoaded", function () {
const usernameForm = document.getElementById("username-form") as HTMLFormElement;
const usernameInput = document.getElementById("username-input") as HTMLInputElement;
const profileName = document.getElementById("profile-name");
const savedUsername = cookie.get("launcher_username");
if (profileName && savedUsername) {
profileName.textContent = savedUsername;
} else if (profileName && !savedUsername) {
profileName.textContent = "Default";
}
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("launcher_username", username, 30);
}
});
}
});
const theme = {
load() {
const setTheme = cookie.get('minexlauncher.theme');
if (setTheme === null) {
theme.set('default');
} else if (setTheme !== 'default') {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = '/resources/styles/' + setTheme + '.css';
document.head.appendChild(link);
}
},
set(setTheme: string) {
cookie.set('minexlauncher.theme', setTheme, 30);
window.location.reload();
},
};
const versionSelector = {
open() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
const customOptions = document.querySelector('.custom-options');
const customSelect = document.querySelector('.custom-select');
if (customOptions && customSelect) {
customOptions.classList.add("open");
customSelect.classList.add("open");
customOptions.classList.add('open');
customSelect.classList.add('open');
}
},
close() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
const customOptions = document.querySelector('.custom-options');
const customSelect = document.querySelector('.custom-select');
if (customOptions && customSelect) {
customOptions.classList.remove("open");
customSelect.classList.remove("open");
customOptions.classList.remove('open');
customSelect.classList.remove('open');
}
},
toggle() {
const customOptions = document.querySelector(".custom-options");
const customSelect = document.querySelector(".custom-select");
const customOptions = document.querySelector('.custom-options');
const customSelect = document.querySelector('.custom-select');
if (customOptions && customSelect) {
customOptions.classList.toggle("open");
customSelect.classList.toggle("open");
customOptions.classList.toggle('open');
customSelect.classList.toggle('open');
}
},
};
@@ -55,20 +47,20 @@ const game = {
play(version?: string) {
if (version) {
embed.remove();
// @ts-expect-error 1234567890
// @ts-expect-error 123
window.top.location.href = version;
} else if (selectedVersion) {
embed.remove();
// @ts-expect-error 1234567890
// @ts-expect-error 123
window.top.location.href = selectedVersion;
} else {
alert("Please select a version to play.");
alert('Please select a version to play.');
return;
}
},
select(path: string, name: string) {
selectedVersion = path;
const selector = document.querySelector(".custom-select");
const selector = document.querySelector('.custom-select');
if (selector?.textContent) {
if (name) {
selector.textContent = `Selected: ${name}`;
@@ -80,13 +72,13 @@ const game = {
},
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",
'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`;
selectedVersion = `https://archive.eaglercraft.rip/Eaglercraft${client === 'b1.3' ? '_b1.3' : `_${client}`}/client/${dropdown.value}/index.html`;
game.play();
}
},
@@ -94,23 +86,23 @@ const game = {
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";
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/";
iframe.src = '/mobile/';
} else {
iframe.src = "/home/";
iframe.src = '/home/';
}
document.body.appendChild(iframe);
},
remove() {
const iframe = document.getElementById("embed");
const iframe = document.getElementById('embed');
iframe?.remove();
},
};
@@ -118,62 +110,64 @@ const embed = {
const navigate = {
home: {
game() {
window.location.href = "/home/game/";
window.location.href = '/home/game/';
},
clients() {
window.location.href = "/home/clients/";
window.location.href = '/home/clients/';
},
archive() {
window.location.href = "/home/archive/";
window.location.href = '/home/archive/';
},
downloads() {
window.location.href = "/home/downloads/";
window.location.href = '/home/downloads/';
},
},
mods: {
client() {
window.location.href = "/mods/client/";
window.location.href = '/mods/client/';
},
mods() {
window.location.href = "/mods/mods/";
window.location.href = '/mods/mods/';
},
resourcepacks() {
window.location.href = "/mods/resourcepacks/";
window.location.href = '/mods/resourcepacks/';
},
},
mobile() {
window.location.href = "/mobile/";
window.location.href = '/mobile/';
},
updates() {
window.location.href = "/updates/";
window.location.href = '/updates/';
},
servers() {
window.location.href = "/servers/";
window.location.href = '/servers/';
},
settings() {
window.location.href = "/settings/";
window.location.href = '/settings/';
},
};
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] ?? "");
get(key: string): string | null {
for (const cookie of document.cookie.replaceAll('; ', ';').split(';')) {
const cookiePair = cookie.split('=');
if (encodeURIComponent(key) === cookiePair[0]) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
},
set(name: string, value: string, days: number) {
let expires = "";
set(key: string, value: string, days: number) {
let maxAge;
if (days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
maxAge = days * 60 * 60 * 24;
} else {
maxAge = 31536000;
}
document.cookie = name + "=" + (value || "") + expires + "; path=/; domain=" + window.location.hostname.replace(/^www\./, "");
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; max-age=${maxAge}; path=/; secure`;
},
delete(key: string) {
document.cookie = `${encodeURIComponent(key)}=; max-age=0; path=/`;
},
};
@@ -193,10 +187,34 @@ function isMobile(): boolean {
}
}
if (window.location.hostname === "0.0.0.0") {
versionSelector;
game;
if (window.location.hostname === '0.0.0.0') {
navigate;
query;
isMobile;
}
let selectedVersion: string;
theme.load();
document.addEventListener('DOMContentLoaded', function () {
const usernameForm = document.getElementById('username-form') as HTMLFormElement;
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
const profileName = document.getElementById('profile-name');
const savedUsername = cookie.get('minexlauncher.username');
if (profileName && savedUsername) {
profileName.textContent = savedUsername;
} else if (profileName && !savedUsername) {
profileName.textContent = 'Default';
}
if (profileName && window.location.pathname === '/settings/') {
usernameForm.addEventListener('submit', function (event) {
event.preventDefault();
const username = usernameInput.value.trim();
if (username) {
cookie.set('minexlauncher.username', username, 30);
profileName.textContent = cookie.get('minexlauncher.username');
}
});
}
});

View File

@@ -1,22 +1,22 @@
document.addEventListener("DOMContentLoaded", function () {
fetch("/resources/data/mods.json")
document.addEventListener('DOMContentLoaded', function () {
fetch('/resources/data/mods.json')
.then((response) => response.json())
.then((data: { mods: { [x: string]: string; icon: string; author: string; description: string }[] }) => {
const modListElement = document.querySelector(".mod-list");
const modListElement = document.querySelector('.mod-list');
data.mods.forEach((mod: { [x: string]: string; icon: string; author: string; description: string }) => {
const modItem = document.createElement("div");
modItem.classList.add("mod-item");
const modItem = document.createElement('div');
modItem.classList.add('mod-item');
modItem.innerHTML = `
<div class="mod-icon">
<img src="${mod.icon}" />
</div>
<div class="mod-details">
<h3 class="mod-name">${mod["display-name"] ?? ""}</h3>
<p class="mod-author">By <a href="${mod["author-link"] ?? ""}" target="_blank">${mod.author}</a></p>
<h3 class="mod-name">${mod['display-name'] ?? ''}</h3>
<p class="mod-author">By <a href="${mod['author-link'] ?? ''}" target="_blank">${mod.author}</a></p>
<p class="mod-description">${mod.description}</p>
<div class="mod-links">
<a href="${mod["repo-link"] ?? ""}" class="mod-link" target="_blank">Repository</a>
<a href="${mod["download-link"] ?? ""}" class="mod-link" download>Download</a>
<a href="${mod['repo-link'] ?? ''}" class="mod-link" target="_blank">Repository</a>
<a href="${mod['download-link'] ?? ''}" class="mod-link" download>Download</a>
</div>
</div>
`;
@@ -24,6 +24,6 @@ document.addEventListener("DOMContentLoaded", function () {
});
})
.catch((error: unknown) => {
console.error("Error fetching mods:", error);
console.error('Error fetching mods:', error);
});
});

View File

@@ -1,22 +1,22 @@
document.addEventListener("DOMContentLoaded", function () {
fetch("/resources/data/mods.json")
document.addEventListener('DOMContentLoaded', function () {
fetch('/resources/data/mods.json')
.then((response) => response.json())
.then((data: { resourcepacks: { [x: string]: string; icon: string; author: string; description: string }[] }) => {
const modListElement = document.querySelector(".mod-list");
const modListElement = document.querySelector('.mod-list');
data.resourcepacks.forEach((mod: { [x: string]: string; icon: string; author: string; description: string }) => {
const modItem = document.createElement("div");
modItem.classList.add("mod-item");
const modItem = document.createElement('div');
modItem.classList.add('mod-item');
modItem.innerHTML = `
<div class="mod-icon">
<img src="${mod.icon}" />
</div>
<div class="mod-details">
<h3 class="mod-name">${mod["display-name"] ?? ""}</h3>
<p class="mod-author">By <a href="${mod["author-link"] ?? ""}" target="_blank">${mod.author}</a></p>
<h3 class="mod-name">${mod['display-name'] ?? ''}</h3>
<p class="mod-author">By <a href="${mod['author-link'] ?? ''}" target="_blank">${mod.author}</a></p>
<p class="mod-description">${mod.description}</p>
<div class="mod-links">
<a href="${mod["repo-link"] ?? ""}" class="mod-link" target="_blank">Repository</a>
<a href="${mod["download-link"] ?? ""}" class="mod-link" download>Download</a>
<a href="${mod['repo-link'] ?? ''}" class="mod-link" target="_blank">Repository</a>
<a href="${mod['download-link'] ?? ''}" class="mod-link" download>Download</a>
</div>
</div>
`;
@@ -24,6 +24,6 @@ document.addEventListener("DOMContentLoaded", function () {
});
})
.catch((error: unknown) => {
console.error("Error fetching resource packs:", error);
console.error('Error fetching resource packs:', error);
});
});