1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-08 09:24:48 +00:00
This commit is contained in:
zumbiepig 2024-09-01 19:32:13 -07:00
parent 8a2e9e1404
commit 4086637731
No known key found for this signature in database
GPG Key ID: 17C891BE28B953DE

View File

@ -321,27 +321,13 @@ if (window.location.pathname === '/') {
const lastPage = storage.session.get('lastPage'); const lastPage = storage.session.get('lastPage');
const isMobile = detect.mobile(); const isMobile = detect.mobile();
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
iframe.id = 'main_frame'; iframe.src = !storage.local.get('lastVersion') ? '/welcome/' : lastPage ? lastPage : isMobile ? '/mobile/' : '/home/game/';
if (!storage.local.get('lastVersion')) { document.addEventListener('DOMContentLoaded', () => document.body.appendChild(iframe));
iframe.src = '/welcome/';
} else if (lastPage && typeof lastPage === 'string') {
iframe.src = lastPage;
} else if (isMobile) {
iframe.src = '/mobile/';
} else {
iframe.src = '/home/game/';
}
document.addEventListener('DOMContentLoaded', () => {
document.body.appendChild(iframe);
});
window.addEventListener('beforeinstallprompt', (event) => { window.addEventListener('beforeinstallprompt', (event) => {
if (iframe.contentWindow) { // @ts-expect-error
// @ts-expect-error if (iframe.contentWindow) iframe.contentWindow.installPwaEvent = event;
iframe.contentWindow.installPwaEvent = event;
}
}); });
/* if (storage.local.get('offlineCache')) { /* if (storage.local.get('offlineCache')) {
@ -351,7 +337,25 @@ if (window.location.pathname === '/') {
} */ } */
serviceworker.register('/sw.js'); serviceworker.register('/sw.js');
} else { } else {
if (storage.local.get('showAds') !== false) { document.addEventListener('DOMContentLoaded', async () => {
const profileName = document.getElementById('profile-name');
const titleBarText = document.getElementById('title-bar-text');
const lastVersion = storage.local.get('lastVersion');
const currentVersion = (await (await fetch('/resources/data/updates.json')).json())[0].version;
const changelog = (await (await fetch('/resources/data/updates.json')).json())[0].changelog.map((change: string) => ` - ${change}`).join('\n');
if (profileName) profileName.textContent = storage.local.get('username');
if (titleBarText) titleBarText.textContent += ` ${(await (await fetch('/resources/data/updates.json')).json())[0].version}`;
// @ts-expect-error
if (lastVersion && gt(coerce(currentVersion, { includePrerelease: true }), coerce(lastVersion, { includePrerelease: true }))) {
alert(`MineXLauncher has been updated to v${currentVersion}!\n\nChanges in v${currentVersion}:\n${changelog}`);
storage.local.set('lastVersion', currentVersion);
}
});
if (storage.local.get('showAds')) {
const googleAdsScript = document.createElement('script'); const googleAdsScript = document.createElement('script');
googleAdsScript.async = true; googleAdsScript.async = true;
googleAdsScript.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1132419379737567'; googleAdsScript.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1132419379737567';
@ -364,33 +368,11 @@ if (window.location.pathname === '/') {
document.body.appendChild(googleAdsPush); document.body.appendChild(googleAdsPush);
const adsContainers = Array.from(document.getElementsByClassName('ads-container')) as HTMLElement[]; const adsContainers = Array.from(document.getElementsByClassName('ads-container')) as HTMLElement[];
for (const adsContainer of adsContainers) { adsContainers.forEach((adsContainer) => {
adsContainer.style.display = 'flex'; adsContainer.style.display = 'flex';
} });
}); });
} }
document.addEventListener('DOMContentLoaded', async () => {
const profileName = document.getElementById('profile-name');
if (profileName) {
profileName.textContent = storage.local.get('username');
}
const titleBarText = document.getElementById('title-bar-text');
if (titleBarText) {
titleBarText.textContent += ` ${(await (await fetch('/resources/data/updates.json')).json())[0].version}`;
}
});
document.addEventListener('DOMContentLoaded', async () => {
const lastVersion = storage.local.get('lastVersion');
const currentVersion = (await (await fetch('/resources/data/updates.json')).json())[0].version;
const changelog = (await (await fetch('/resources/data/updates.json')).json())[0].changelog.map((change: string) => ` - ${change}`).join('\n');
// @ts-expect-error
if (lastVersion && gt(coerce(currentVersion, { includePrerelease: true }), coerce(lastVersion, { includePrerelease: true }))) {
alert(`MineXLauncher has been updated to v${currentVersion}!\n\nChanges in v${currentVersion}:\n${changelog}`);
storage.local.set('lastVersion', currentVersion);
}
});
} }
if (window.location.pathname === '/settings/') { if (window.location.pathname === '/settings/') {
@ -404,23 +386,18 @@ if (window.location.pathname === '/settings/') {
usernameInput.placeholder = storage.local.get('username') ?? ''; usernameInput.placeholder = storage.local.get('username') ?? '';
themeSelect.value = storage.local.get('theme') ?? ''; themeSelect.value = storage.local.get('theme') ?? '';
// offlineCheckbox.checked = storage.local.get('offlineCache') ?? false; // offlineCheckbox.checked = storage.local.get('offlineCache') ?? false;
adsCheckbox.checked = storage.local.get('showAds') !== false; adsCheckbox.checked = storage.local.get('showAds');
usernameInput.addEventListener('input', () => { usernameInput.addEventListener('input', () => {
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16); let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
usernameInput.value = username; usernameInput.value = username;
while (username.length < 3) { while (username.length < 3) username += '_';
username += '_';
}
storage.local.set('username', username); storage.local.set('username', username);
if (profileName) { if (profileName) profileName.textContent = username;
profileName.textContent = username;
}
}); });
themeSelect.addEventListener('change', () => { themeSelect.addEventListener('change', () => theme.set(themeSelect.value));
theme.set(themeSelect.value);
});
/* offlineCheckbox.addEventListener('change', () => { /* offlineCheckbox.addEventListener('change', () => {
storage.local.set('offlineCache', offlineCheckbox.checked); storage.local.set('offlineCache', offlineCheckbox.checked);
@ -437,7 +414,8 @@ if (window.location.pathname === '/settings/') {
adsCheckbox.addEventListener('change', () => { adsCheckbox.addEventListener('change', () => {
storage.local.set('showAds', adsCheckbox.checked); storage.local.set('showAds', adsCheckbox.checked);
window.location.reload(); const adsContainers = Array.from(document.getElementsByClassName('ads-container')) as HTMLElement[];
adsContainers.forEach((adsContainer) => (adsContainer.style.display = 'none'));
}); });
}); });
} else if (window.location.pathname === '/welcome/') { } else if (window.location.pathname === '/welcome/') {
@ -452,9 +430,7 @@ if (window.location.pathname === '/settings/') {
usernameInput.value = username; usernameInput.value = username;
}); });
themeSelect.addEventListener('change', () => { themeSelect.addEventListener('change', () => theme.load(themeSelect.value));
theme.load(themeSelect.value);
});
setupForm.addEventListener('submit', async (event) => { setupForm.addEventListener('submit', async (event) => {
event.preventDefault(); event.preventDefault();
@ -466,9 +442,7 @@ if (window.location.pathname === '/settings/') {
alert('Please type a username.'); alert('Please type a username.');
return; return;
} else { } else {
while (username.length < 3) { while (username.length < 3) username += '_';
username += '_';
}
storage.local.set('username', username); storage.local.set('username', username);
storage.local.set('theme', themeSelect.value); storage.local.set('theme', themeSelect.value);
@ -482,15 +456,10 @@ if (window.location.pathname === '/settings/') {
alert( 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.' '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
// @ts-expect-error try installPwaEvent.prompt();
installPwaEvent.prompt(); catch (error) console.error('Failed to prompt PWA install:', error)
} catch (error) { } else serviceworker.register('/sw.js'); */
console.error('Failed to prompt PWA install:', error);
}
} else {
serviceworker.register('/sw.js');
} */
// @ts-expect-error // @ts-expect-error
window.top.location.href = '/'; window.top.location.href = '/';