mirror of
https://github.com/zumbiepig/MineXLauncher.git
synced 2025-06-08 09:24:48 +00:00
build process stuff
This commit is contained in:
parent
2b37e5d687
commit
4c15fa2286
48
build.ts
48
build.ts
@ -1,20 +1,52 @@
|
||||
import { $, build } from 'bun';
|
||||
import { readdirSync, statSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const directoryPath = join(import.meta.dir, 'public');
|
||||
|
||||
function getFiles(directory: string, filesArr?: string[]) {
|
||||
function getFiles(baseDir: string, dir?: string, filesArr?: string[]) {
|
||||
dir = dir || baseDir;
|
||||
filesArr = filesArr || [];
|
||||
const files = readdirSync(directory);
|
||||
const files = readdirSync(dir);
|
||||
for (const file of files) {
|
||||
const name = join(directory, file);
|
||||
const name = join(dir, file);
|
||||
if (statSync(name).isDirectory()) {
|
||||
getFiles(name, filesArr);
|
||||
getFiles(baseDir, name, filesArr);
|
||||
} else {
|
||||
filesArr.push(name.replace(new RegExp(`^${directoryPath}`), '').replace(/\/index\.html$/, '/'));
|
||||
filesArr.push(name);
|
||||
}
|
||||
}
|
||||
return filesArr;
|
||||
}
|
||||
|
||||
writeFileSync(join(directoryPath, 'assets.json'), JSON.stringify(getFiles(directoryPath)));
|
||||
console.log(chalk.cyan('Linting code...\n'));
|
||||
const lintOutput = await $`bunx eslint ./src/`.nothrow().text();
|
||||
if (lintOutput) {
|
||||
console.error(lintOutput);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(chalk.cyan('Removing old build artifacts...\n'));
|
||||
await $`rm -rf ./public/resources/scripts/ ./public/assets.json ./public/sw.js ./public/sw-full.js`.quiet();
|
||||
|
||||
console.log(chalk.cyan('Bundling TypeScript and modules...\n'));
|
||||
const srcFilesArr = getFiles(join(import.meta.dir, 'src'));
|
||||
await build({
|
||||
entrypoints: srcFilesArr,
|
||||
outdir: './public/',
|
||||
root: './src/',
|
||||
minify: true,
|
||||
});
|
||||
|
||||
console.log(chalk.cyan('Obfuscating JavaScript...\n'));
|
||||
await $`bunx javascript-obfuscator ./public/resources/scripts/ --output ./public/resources/scripts/ --options-preset high-obfuscation`.quiet();
|
||||
|
||||
console.log(chalk.cyan('Generating assets list...\n'));
|
||||
const publicDir = join(import.meta.dir, 'public');
|
||||
writeFileSync(
|
||||
join(publicDir, 'assets.json'),
|
||||
JSON.stringify(getFiles(publicDir))
|
||||
.replace(new RegExp(`^${publicDir}`), '')
|
||||
.replace(/\/index\.html$/, '/')
|
||||
);
|
||||
|
||||
console.log(chalk.green('Build complete!\n'));
|
||||
|
4
index.ts
4
index.ts
@ -1,7 +1,7 @@
|
||||
import { join } from 'path';
|
||||
import { env } from 'bun';
|
||||
import express, { json, urlencoded } from 'express';
|
||||
import chalk from 'chalk'
|
||||
import chalk from 'chalk';
|
||||
import compression from 'compression';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import debug from 'debug';
|
||||
@ -30,7 +30,7 @@ app.use(
|
||||
})
|
||||
);
|
||||
|
||||
app.use(morgan('combined'));
|
||||
app.use(morgan(isDev ? 'dev' : 'combined'));
|
||||
app.use(json());
|
||||
app.use(urlencoded({ extended: false }));
|
||||
|
||||
|
@ -5,10 +5,10 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "NODE_ENV=production bun run ./index.ts",
|
||||
"dev": "NODE_ENV=development DEBUG=app:* bun --watch run ./index.ts",
|
||||
"dev": "NODE_ENV=development DEBUG=app:* bun --hot run ./index.ts",
|
||||
"lint": "eslint ./src/",
|
||||
"lint:fix": "eslint --fix ./src/",
|
||||
"build": "bun run lint; rm -rf ./public/resources/scripts/ ./public/assets.json; tsc; javascript-obfuscator ./public/resources/scripts/ --output ./public/resources/scripts/ --options-preset high-obfuscation; bun run ./build.ts"
|
||||
"build": "bun run ./build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^5.3.0",
|
||||
@ -19,6 +19,7 @@
|
||||
"express": "^4.19.2",
|
||||
"helmet": "^7.1.0",
|
||||
"morgan": "^1.10.0",
|
||||
"semver": "^7.6.3",
|
||||
"serve-favicon": "^2.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -29,12 +30,13 @@
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/errorhandler": "^1.5.3",
|
||||
"@types/morgan": "^1.9.9",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/serve-favicon": "^2.5.7",
|
||||
"eslint": "^9.9.1",
|
||||
"javascript-obfuscator": "^4.1.1",
|
||||
"typescript-eslint": "^8.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -1,78 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>MineXLauncher</title>
|
||||
<link rel="icon" type="image/webp" href="/resources/images/icons/favicon.webp" />
|
||||
<link rel="stylesheet" href="/resources/styles/themes/default.css" />
|
||||
<link rel="stylesheet" id="theme" />
|
||||
<script src="/resources/scripts/google-tag.js"></script>
|
||||
<script src="/resources/scripts/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ads-container">
|
||||
<ins class="adsbygoogle" style="display: block" data-ad-client="ca-pub-1132419379737567" data-ad-slot="3280170072" data-ad-format="auto" data-full-width-responsive="true"></ins>
|
||||
</div>
|
||||
<div class="launcher">
|
||||
<div class="title-bar">
|
||||
<span>MineXLauncher 1.5</span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="sidebar">
|
||||
<div class="profile">
|
||||
<span class="profile-name" id="profile-name"></span>
|
||||
</div>
|
||||
<nav>
|
||||
<li class="nav-item" onclick="navigate.updates()">
|
||||
<img src="/resources/images/icons/nav/updates.webp" class="nav-icon" />
|
||||
<span class="nav-text">Updates</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.home.game()">
|
||||
<img src="/resources/images/icons/nav/game.webp" class="nav-icon" />
|
||||
<span class="nav-text">Game</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.servers()">
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item selected" onclick="navigate.mods.client()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.settings()">
|
||||
<img src="/resources/images/icons/nav/settings.webp" class="nav-icon" />
|
||||
<span class="nav-text">Settings</span>
|
||||
</li>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="main-panel">
|
||||
<div class="top-menu">
|
||||
<ul>
|
||||
<li class="menu-item selected" onclick="navigate.mods.client()">Client</li>
|
||||
<li class="menu-item" onclick="navigate.mods.mods()">Mods</li>
|
||||
<li class="menu-item" onclick="navigate.mods.resourcepacks()">Resource Packs</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
<img src="/resources/images/covers/eaglerforge.webp" class="cover-image" />
|
||||
<div class="installations">
|
||||
<button class="play-button" onclick="game.play('/game/web/clients/eaglerforge/')">Play</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom-bar">
|
||||
<div class="bottom-bar-links">
|
||||
<a href="https://discord.gg/YKgfuFvKhA" class="bottom-bar-left">Join the MineXLauncher Discord</a>
|
||||
</div>
|
||||
<div class="bottom-bar-links">
|
||||
<span class="bottom-bar-right">© 2024 MineXLauncher. All rights reserved.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ads-container">
|
||||
<ins class="adsbygoogle" style="display: block" data-ad-client="ca-pub-1132419379737567" data-ad-slot="3280170072" data-ad-format="auto" data-full-width-responsive="true"></ins>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -37,7 +37,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item selected" onclick="navigate.mods.client()">
|
||||
<li class="nav-item selected" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
@ -50,7 +50,6 @@
|
||||
<div class="main-panel">
|
||||
<div class="top-menu">
|
||||
<ul>
|
||||
<li class="menu-item" onclick="navigate.mods.client()">Client</li>
|
||||
<li class="menu-item selected" onclick="navigate.mods.mods()">Mods</li>
|
||||
<li class="menu-item" onclick="navigate.mods.resourcepacks()">Resource Packs</li>
|
||||
</ul>
|
||||
|
@ -37,7 +37,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item selected" onclick="navigate.mods.client()">
|
||||
<li class="nav-item selected" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
@ -50,7 +50,6 @@
|
||||
<div class="main-panel">
|
||||
<div class="top-menu">
|
||||
<ul>
|
||||
<li class="menu-item" onclick="navigate.mods.client()">Client</li>
|
||||
<li class="menu-item" onclick="navigate.mods.mods()">Mods</li>
|
||||
<li class="menu-item selected" onclick="navigate.mods.resourcepacks()">Resource Packs</li>
|
||||
</ul>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -9,7 +9,6 @@
|
||||
<link rel="stylesheet" id="theme" />
|
||||
<script src="/resources/scripts/google-tag.js"></script>
|
||||
<script src="/resources/scripts/main.js"></script>
|
||||
<script src="/resources/scripts/settings.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ads-container">
|
||||
@ -37,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<img src="/resources/images/icons/nav/servers.webp" class="nav-icon" />
|
||||
<span class="nav-text">Server List</span>
|
||||
</li>
|
||||
<li class="nav-item" onclick="navigate.mods.client()">
|
||||
<li class="nav-item" onclick="navigate.mods.mods()">
|
||||
<img src="/resources/images/icons/nav/mods.webp" class="nav-icon" />
|
||||
<span class="nav-text">Addons</span>
|
||||
</li>
|
||||
|
@ -10,7 +10,6 @@
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<script src="/resources/scripts/google-tag.js"></script>
|
||||
<script src="/resources/scripts/main.js"></script>
|
||||
<script src="/resources/scripts/settings.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="launcher">
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { gt, coerce } from 'semver';
|
||||
|
||||
let selectedVersion: string | undefined;
|
||||
const launcherVersion = '1.5';
|
||||
|
||||
@ -89,6 +91,7 @@ const game = {
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const navigate = {
|
||||
home: {
|
||||
@ -118,12 +121,6 @@ const navigate = {
|
||||
},
|
||||
},
|
||||
mods: {
|
||||
client: function () {
|
||||
document.body.style.display = 'none';
|
||||
const navUrl = '/mods/client/';
|
||||
storage.session.set('lastPage', navUrl);
|
||||
window.location.href = navUrl;
|
||||
},
|
||||
mods: function () {
|
||||
document.body.style.display = 'none';
|
||||
const navUrl = '/mods/mods/';
|
||||
@ -159,6 +156,7 @@ const navigate = {
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const cookie = {
|
||||
set: function (key: string, value: string, days: number) {
|
||||
@ -252,6 +250,7 @@ const storage = {
|
||||
},
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const query = {
|
||||
get: function (name: string) {
|
||||
@ -354,12 +353,12 @@ if (window.location.pathname === '/') {
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const lastVersion = storage.local.get('lastVersion');
|
||||
if (lastVersion !== null && lastVersion < launcherVersion) {
|
||||
if (lastVersion !== null && gt(launcherVersion, lastVersion)) {
|
||||
alert(`MineXLauncher has been updated to v${launcherVersion}!
|
||||
|
||||
Changes in v${launcherVersion}:
|
||||
- You can now install the launcher as a PWA web app`);
|
||||
storage.local.set('lastVersion', launcherVersion);
|
||||
storage.local.set('lastVersion', coerce(launcherVersion, { includePrerelease: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -372,3 +371,110 @@ if (detect.mobile()) {
|
||||
}
|
||||
|
||||
theme.load();
|
||||
|
||||
if (window.location.pathname === '/settings/') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const profileName = document.getElementById('profile-name');
|
||||
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
|
||||
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
|
||||
// const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement;
|
||||
const adsCheckbox = document.getElementById('ads-checkbox') as HTMLInputElement;
|
||||
|
||||
usernameInput.placeholder = storage.local.get('username') ?? '';
|
||||
themeSelect.value = storage.local.get('theme') ?? '';
|
||||
// offlineCheckbox.checked = storage.local.get('offlineCache') ?? false;
|
||||
adsCheckbox.checked = storage.local.get('showAds') !== false;
|
||||
|
||||
usernameInput.addEventListener('input', () => {
|
||||
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
while (username.length < 3) {
|
||||
username += '_';
|
||||
}
|
||||
storage.local.set('username', username);
|
||||
if (profileName) {
|
||||
profileName.textContent = username;
|
||||
}
|
||||
});
|
||||
|
||||
themeSelect.addEventListener('change', () => {
|
||||
theme.set(themeSelect.value);
|
||||
});
|
||||
|
||||
/* offlineCheckbox.addEventListener('change', () => {
|
||||
storage.local.set('offlineCache', offlineCheckbox.checked);
|
||||
if (offlineCheckbox.checked) {
|
||||
serviceworker.register('/sw-full.js');
|
||||
alert(
|
||||
'Offline cache is now downloading.\nThe download size is about 1GB, so it may take a while.\n\nPlease do not leave this page while the download is in progress.\nYou will be notified when the download is complete.'
|
||||
);
|
||||
} else {
|
||||
serviceworker.register('/sw.js');
|
||||
alert('Offline cache has been deleted.');
|
||||
}
|
||||
}); */
|
||||
|
||||
adsCheckbox.addEventListener('change', () => {
|
||||
storage.local.set('showAds', adsCheckbox.checked);
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (window.location.pathname === '/welcome/') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const setupForm = document.getElementById('setup-form') as HTMLFormElement;
|
||||
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
|
||||
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
|
||||
// const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement;
|
||||
|
||||
usernameInput.addEventListener('input', () => {
|
||||
const username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
});
|
||||
|
||||
themeSelect.addEventListener('change', () => {
|
||||
theme.load(themeSelect.value);
|
||||
});
|
||||
|
||||
setupForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
|
||||
if (!username) {
|
||||
alert('Please type a username.');
|
||||
return;
|
||||
} else {
|
||||
while (username.length < 3) {
|
||||
username += '_';
|
||||
}
|
||||
|
||||
storage.local.set('username', username);
|
||||
storage.local.set('theme', themeSelect.value);
|
||||
// storage.local.set('offlineCache', offlineCheckbox.checked);
|
||||
storage.local.set('showAds', true);
|
||||
storage.local.set('lastVersion', coerce(launcherVersion, { includePrerelease: true }));
|
||||
|
||||
/* if (offlineCheckbox.checked) {
|
||||
serviceworker.register('/sw-full.js');
|
||||
alert(
|
||||
'Offline cache is now downloading.\nThe download size is about 1GB, so it may take a while.\n\nPlease do not leave this page while the download is in progress.\nYou will be notified when the download is complete.'
|
||||
);
|
||||
try {
|
||||
// @ts-expect-error
|
||||
installPwaEvent.prompt();
|
||||
} catch (error) {
|
||||
console.error('Failed to prompt PWA install:', error);
|
||||
}
|
||||
} else {
|
||||
serviceworker.register('/sw.js');
|
||||
} */
|
||||
|
||||
// @ts-expect-error
|
||||
window.top.location.href = '/';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,106 +0,0 @@
|
||||
if (window.location.pathname === '/settings/') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const profileName = document.getElementById('profile-name');
|
||||
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
|
||||
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
|
||||
// const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement;
|
||||
const adsCheckbox = document.getElementById('ads-checkbox') as HTMLInputElement;
|
||||
|
||||
usernameInput.placeholder = storage.local.get('username') ?? '';
|
||||
themeSelect.value = storage.local.get('theme') ?? '';
|
||||
// offlineCheckbox.checked = storage.local.get('offlineCache') ?? false;
|
||||
adsCheckbox.checked = storage.local.get('showAds') !== false;
|
||||
|
||||
usernameInput.addEventListener('input', () => {
|
||||
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
while (username.length < 3) {
|
||||
username += '_';
|
||||
}
|
||||
storage.local.set('username', username);
|
||||
if (profileName) {
|
||||
profileName.textContent = username;
|
||||
}
|
||||
});
|
||||
|
||||
themeSelect.addEventListener('change', () => {
|
||||
theme.set(themeSelect.value);
|
||||
});
|
||||
|
||||
/* offlineCheckbox.addEventListener('change', () => {
|
||||
storage.local.set('offlineCache', offlineCheckbox.checked);
|
||||
if (offlineCheckbox.checked) {
|
||||
serviceworker.register('/sw-full.js');
|
||||
alert(
|
||||
'Offline cache is now downloading.\nThe download size is about 1GB, so it may take a while.\n\nPlease do not leave this page while the download is in progress.\nYou will be notified when the download is complete.'
|
||||
);
|
||||
} else {
|
||||
serviceworker.register('/sw.js');
|
||||
alert('Offline cache has been deleted.');
|
||||
}
|
||||
}); */
|
||||
|
||||
adsCheckbox.addEventListener('change', () => {
|
||||
storage.local.set('showAds', adsCheckbox.checked);
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (window.location.pathname === '/welcome/') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const setupForm = document.getElementById('setup-form') as HTMLFormElement;
|
||||
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
|
||||
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
|
||||
// const offlineCheckbox = document.getElementById('offline-checkbox') as HTMLInputElement;
|
||||
|
||||
usernameInput.addEventListener('input', () => {
|
||||
const username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
});
|
||||
|
||||
themeSelect.addEventListener('change', () => {
|
||||
theme.load(themeSelect.value);
|
||||
});
|
||||
|
||||
setupForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
|
||||
usernameInput.value = username;
|
||||
|
||||
if (!username) {
|
||||
alert('Please type a username.');
|
||||
return;
|
||||
} else {
|
||||
while (username.length < 3) {
|
||||
username += '_';
|
||||
}
|
||||
|
||||
storage.local.set('username', username);
|
||||
storage.local.set('theme', themeSelect.value);
|
||||
// storage.local.set('offlineCache', offlineCheckbox.checked);
|
||||
storage.local.set('showAds', true);
|
||||
storage.local.set('lastVersion', launcherVersion);
|
||||
|
||||
/* if (offlineCheckbox.checked) {
|
||||
serviceworker.register('/sw-full.js');
|
||||
alert(
|
||||
'Offline cache is now downloading.\nThe download size is about 1GB, so it may take a while.\n\nPlease do not leave this page while the download is in progress.\nYou will be notified when the download is complete.'
|
||||
);
|
||||
try {
|
||||
// @ts-expect-error
|
||||
installPwaEvent.prompt();
|
||||
} catch (error) {
|
||||
console.error('Failed to prompt PWA install:', error);
|
||||
}
|
||||
} else {
|
||||
serviceworker.register('/sw.js');
|
||||
} */
|
||||
|
||||
// @ts-expect-error
|
||||
window.top.location.href = '/';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user