1
0
forked from sent/waves

This commit is contained in:
𓍼 2025-04-16 23:04:06 -05:00
parent 9479504cc9
commit 55b199ac03
2 changed files with 133 additions and 142 deletions

View File

@ -1,43 +1,43 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('gameSearchInput'); const searchInput = document.getElementById('gameSearchInput');
const grid = document.querySelector('.games-grid'); const grid = document.querySelector('.games-grid');
let gamesData = []; let gamesData = [];
fetch('/assets/data/g.json') fetch('/assets/data/g.json')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
gamesData = data; gamesData = data;
searchInput.placeholder = `Search through ${gamesData.length} Games…`; searchInput.placeholder = `Search through ${gamesData.length} Games…`;
displayGames(gamesData); displayGames(gamesData);
searchInput.addEventListener('input', function() { searchInput.addEventListener('input', function() {
const query = searchInput.value.toLowerCase(); const query = searchInput.value.toLowerCase();
const filteredGames = gamesData.filter(game => { const filtered = gamesData.filter(game => {
const name = game.name ? game.name.toLowerCase() : ''; const name = (game.name || '').toLowerCase();
return name.includes(query); return name.includes(query);
}); });
displayGames(filteredGames); displayGames(filtered);
}); });
}) })
.catch(err => console.error('Error loading games data:', err)); .catch(err => console.error('Error loading games data:', err));
function displayGames(games) { function displayGames(games) {
grid.innerHTML = ''; grid.innerHTML = '';
if (games.length === 0) { if (games.length === 0) {
grid.innerHTML = '<p>Zero games were found matching your search :(</p>'; grid.innerHTML = '<p>Zero games were found matching your search :(</p>';
return; return;
} }
games.forEach(game => { games.forEach(game => {
const card = document.createElement('div'); const card = document.createElement('div');
card.classList.add('game-card'); card.classList.add('game-card');
card.innerHTML = ` card.innerHTML = `
<img src="/assets/g/${game.directory}/${game.image}" alt="${game.name} Icon" /> <img src="/assets/g/${game.directory}/${game.image}" alt="${game.name} Icon" />
<h2>${game.name}</h2> <h2>${game.name}</h2>
`; `;
card.addEventListener('click', function() { card.addEventListener('click', function() {
const url = `${location.origin}/assets/g/${game.directory}`; const url = `/assets/g/${game.directory}`;
window.handleSearch(url); window.handleSearch(url);
}); });
grid.appendChild(card); grid.appendChild(card);
}); });
} }
}); });

View File

@ -10,12 +10,12 @@ document.head.appendChild(style);
const historyStack = []; const historyStack = [];
let currentIndex = -1; let currentIndex = -1;
const elements = { const elements = {
refreshIcon: document.getElementById('refreshIcon'), refreshIcon: document.getElementById('refreshIcon'),
fullscreenIcon: document.getElementById('fullscreenIcon'), fullscreenIcon: document.getElementById('fullscreenIcon'),
backIcon: document.getElementById('backIcon'), backIcon: document.getElementById('backIcon'),
forwardIcon: document.getElementById('forwardIcon'), forwardIcon: document.getElementById('forwardIcon'),
searchInput2: document.getElementById('searchInputt'), searchInput2: document.getElementById('searchInputt'),
iframe: document.getElementById('cool-iframe') iframe: document.getElementById('cool-iframe')
}; };
let loadingFallbackTimeout; let loadingFallbackTimeout;
@ -25,112 +25,99 @@ elements.backIcon.addEventListener('click', handleBack);
elements.forwardIcon.addEventListener('click', handleForward); elements.forwardIcon.addEventListener('click', handleForward);
function showLoadingScreen() { function showLoadingScreen() {
const loadingScreen = document.querySelector('.loading-screen'); if (typeof NProgress !== 'undefined') NProgress.start();
if (!loadingScreen) return;
if (typeof NProgress !== 'undefined') NProgress.start();
loadingScreen.style.display = 'flex';
setTimeout(() => loadingScreen.style.opacity = 1, 10);
clearTimeout(loadingFallbackTimeout);
loadingFallbackTimeout = setTimeout(hideLoadingScreen, 10000);
} }
function hideLoadingScreen() { function hideLoadingScreen() {
const loadingScreen = document.querySelector('.loading-screen');
if (!loadingScreen) return;
loadingScreen.style.opacity = 0;
setTimeout(() => {
loadingScreen.style.display = 'none';
if (typeof NProgress !== 'undefined') NProgress.done(); if (typeof NProgress !== 'undefined') NProgress.done();
}, 500);
clearTimeout(loadingFallbackTimeout);
} }
function handleRefresh() { function handleRefresh() {
elements.refreshIcon.classList.add('spin'); elements.refreshIcon.classList.add('spin');
const iframe = elements.iframe; const iframe = elements.iframe;
const currentUrl = iframe.contentWindow.location.href; const currentUrl = iframe.contentWindow.location.href;
if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) { if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) {
addToHistory(currentUrl); addToHistory(currentUrl);
} }
iframe.contentWindow.location.reload(true); iframe.contentWindow.location.reload(true);
setTimeout(() => elements.refreshIcon.classList.remove('spin'), 300); setTimeout(() => elements.refreshIcon.classList.remove('spin'), 300);
} }
function handleFullscreen() { function handleFullscreen() {
const iframe = elements.iframe; const iframe = elements.iframe;
if (iframe && iframe.tagName === 'IFRAME') iframe.requestFullscreen(); if (iframe && iframe.tagName === 'IFRAME') iframe.requestFullscreen();
} }
function handleBack() { function handleBack() {
toggleButtonAnimation(elements.backIcon, 'button-animate-back'); toggleButtonAnimation(elements.backIcon, 'button-animate-back');
if (currentIndex > 0) { if (currentIndex > 0) {
currentIndex--; currentIndex--;
updateIframeSrc(); updateIframeSrc();
} }
} }
function handleForward() { function handleForward() {
toggleButtonAnimation(elements.forwardIcon, 'button-animate-forward'); toggleButtonAnimation(elements.forwardIcon, 'button-animate-forward');
if (currentIndex < historyStack.length - 1) { if (currentIndex < historyStack.length - 1) {
currentIndex++; currentIndex++;
updateIframeSrc(); updateIframeSrc();
} }
} }
function toggleButtonAnimation(button, animationClass) { function toggleButtonAnimation(button, animationClass) {
button.classList.add(animationClass); button.classList.add(animationClass);
setTimeout(() => button.classList.remove(animationClass), 200); setTimeout(() => button.classList.remove(animationClass), 200);
} }
function normalizeUrl(urlStr) { function normalizeUrl(urlStr) {
try { try {
const url = new URL(urlStr); const url = new URL(urlStr);
url.searchParams.delete('ia'); url.searchParams.delete('ia');
return url.toString(); return url.toString();
} catch (e) { } catch (e) {
return urlStr; return urlStr;
} }
} }
function addToHistory(url) { function addToHistory(url) {
const normalized = normalizeUrl(url); const normalized = normalizeUrl(url);
if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return; if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return;
if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1); if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1);
historyStack.push(url); historyStack.push(url);
currentIndex++; currentIndex++;
updateNavButtons(); updateNavButtons();
updateDecodedSearchInput(); updateDecodedSearchInput();
} }
function updateIframeSrc() { function updateIframeSrc() {
showLoadingScreen(); showLoadingScreen();
elements.iframe.src = historyStack[currentIndex]; elements.iframe.src = historyStack[currentIndex];
updateNavButtons(); updateNavButtons();
updateDecodedSearchInput(); updateDecodedSearchInput();
} }
function updateNavButtons() { function updateNavButtons() {
const isAtStart = currentIndex <= 0; const isAtStart = currentIndex <= 0;
const isAtEnd = currentIndex >= historyStack.length - 1; const isAtEnd = currentIndex >= historyStack.length - 1;
elements.backIcon.disabled = isAtStart; elements.backIcon.disabled = isAtStart;
elements.forwardIcon.disabled = isAtEnd; elements.forwardIcon.disabled = isAtEnd;
elements.backIcon.classList.toggle('disabled', isAtStart); elements.backIcon.classList.toggle('disabled', isAtStart);
elements.forwardIcon.classList.toggle('disabled', isAtEnd); elements.forwardIcon.classList.toggle('disabled', isAtEnd);
} }
function updateDecodedSearchInput() { function updateDecodedSearchInput() {
if (elements.searchInput2) { if (elements.searchInput2) {
const url = historyStack[currentIndex] || elements.iframe.src; const url = historyStack[currentIndex] || elements.iframe.src;
elements.searchInput2.value = decodeUrl(url); elements.searchInput2.value = decodeUrl(url);
} }
} }
function decodeUrl(url) { function decodeUrl(url) {
try { try {
return decodeURIComponent(url); return decodeURIComponent(url);
} catch (e) { } catch (e) {
return url; return url;
} }
} }
window.addToHistory = addToHistory; window.addToHistory = addToHistory;
@ -138,39 +125,43 @@ window.updateDecodedSearchInput = updateDecodedSearchInput;
window.normalizeUrl = normalizeUrl; window.normalizeUrl = normalizeUrl;
function detectIframeNavigation() { function detectIframeNavigation() {
try { try {
const iframeWindow = elements.iframe.contentWindow; const iframeWindow = elements.iframe.contentWindow;
const pushState = iframeWindow.history.pushState; const pushState = iframeWindow.history.pushState;
const replaceState = iframeWindow.history.replaceState; const replaceState = iframeWindow.history.replaceState;
iframeWindow.history.pushState = function() { iframeWindow.history.pushState = function() {
pushState.apply(this, arguments); pushState.apply(this, arguments);
handleIframeNavigation(iframeWindow.location.href); handleIframeNavigation(iframeWindow.location.href);
}; };
iframeWindow.history.replaceState = function() { iframeWindow.history.replaceState = function() {
replaceState.apply(this, arguments); replaceState.apply(this, arguments);
handleIframeNavigation(iframeWindow.location.href); handleIframeNavigation(iframeWindow.location.href);
}; };
iframeWindow.addEventListener('popstate', () => handleIframeNavigation(iframeWindow.location.href)); iframeWindow.addEventListener('popstate', () => handleIframeNavigation(iframeWindow.location.href));
iframeWindow.addEventListener('hashchange', () => handleIframeNavigation(iframeWindow.location.href)); iframeWindow.addEventListener('hashchange', () => handleIframeNavigation(iframeWindow.location.href));
} catch (error) {} } catch (error) {}
} }
function handleIframeNavigation(url) { function handleIframeNavigation(url) {
if (url && normalizeUrl(url) !== normalizeUrl(historyStack[currentIndex] || '')) { if (url && normalizeUrl(url) !== normalizeUrl(historyStack[currentIndex] || '')) {
showLoadingScreen(); showLoadingScreen();
addToHistory(url); addToHistory(url);
} } else {
hideLoadingScreen();
}
} }
elements.iframe.addEventListener('load', () => { elements.iframe.addEventListener('load', () => {
try { try {
detectIframeNavigation(); detectIframeNavigation();
if (historyStack.length === 0) { if (historyStack.length === 0) {
addToHistory(elements.iframe.contentWindow.location.href); addToHistory(elements.iframe.contentWindow.location.href);
} else { } else {
handleIframeNavigation(elements.iframe.contentWindow.location.href); handleIframeNavigation(elements.iframe.contentWindow.location.href);
}
} catch (error) {
console.error('Error during iframe load handling:', error);
} finally {
hideLoadingScreen();
} }
} catch (error) {} finally {
hideLoadingScreen();
}
}); });