|
259 | 259 | } |
260 | 260 |
|
261 | 261 |
|
262 | | - function saveGameToHistory(game) { |
263 | | - let history = JSON.parse(localStorage.getItem('gameHistory')) || []; |
264 | | - history = history.filter(item => item.alt !== game.alt); |
265 | | - history.unshift(game); // Add to the beginning |
266 | | - // 10 games limit |
267 | | - history = history.slice(0, 10); |
268 | | - localStorage.setItem('gameHistory', JSON.stringify(history)); |
269 | | - displayGameHistory(); |
270 | | - } |
271 | | - |
272 | | - |
273 | | - function displayGameHistory() { |
274 | | - const historyContainer = document.getElementById('gameHistoryContainer'); |
275 | | - const noHistoryMessage = document.getElementById('noHistoryMessage'); |
276 | | - |
277 | | - |
278 | | - if (!historyContainer || !noHistoryMessage) { |
279 | | - console.warn("History container or no history message element not found, skipping history display."); |
280 | | - return; |
281 | | - } |
282 | | - |
283 | | - const history = JSON.parse(localStorage.getItem('gameHistory')) || []; |
284 | | - |
285 | | - if (history.length === 0) { |
286 | | - noHistoryMessage.classList.remove('hidden'); |
287 | | - historyContainer.innerHTML = ''; // delete the mf history |
288 | | - } else { |
289 | | - noHistoryMessage.classList.add('hidden'); |
290 | | - historyContainer.innerHTML = history.map(game => ` |
291 | | - <div |
292 | | - onclick="opengame('${game.apiUrl}', '${game.alt}', '${game.title}')" |
293 | | - class="flex items-center justify-between p-3 mb-2 rounded-lg cursor-pointer hover:bg-gray-100 transition-colors duration-200 outline outline-1 outline-offset-1 outline-gray-200" |
294 | | - > |
295 | | - <span class="font-medium">${game.title}</span> |
296 | | - <i data-lucide="play" class="w-5 h-5 text-blue-500"></i> |
297 | | - </div> |
298 | | - `).join(''); |
299 | | - } |
300 | | - |
301 | | - lucide.createIcons(); //naw |
302 | | - } |
303 | 262 |
|
304 | 263 |
|
305 | | - function clearGameHistory() { |
306 | | - localStorage.removeItem('gameHistory'); |
307 | | - displayGameHistory(); |
308 | | - showMessage('Game history cleared!'); |
309 | | - } |
310 | | - |
311 | 264 | // themes |
312 | 265 |
|
313 | 266 | function setTheme(themeName) { |
|
352 | 305 | //sidebar logic |
353 | 306 |
|
354 | 307 | function showSection(sectionId) { |
355 | | - const sections = ['gameContainer', 'gameHistorySection', 'settingsSection']; |
| 308 | + const sections = ['gameContainer', 'settingsSection']; |
356 | 309 | const searchSortSection = document.getElementById('searchSortSection'); |
357 | 310 | const paginationControls = document.getElementById('paginationControls'); |
358 | 311 |
|
|
391 | 344 | }); |
392 | 345 | if (sectionId === 'gameContainer') { |
393 | 346 | document.getElementById('navHomeBtn').classList.add('active'); |
394 | | - } else if (sectionId === 'gameHistorySection') { |
395 | | - document.getElementById('navHistoryBtn').classList.add('active'); |
396 | 347 | } else if (sectionId === 'settingsSection') { |
397 | 348 | document.getElementById('navSettingsBtn').classList.add('active'); |
398 | 349 | } |
|
415 | 366 | // Sidebar |
416 | 367 |
|
417 | 368 | document.getElementById('navHomeBtn').addEventListener('click', () => showSection('gameContainer')); |
418 | | - document.getElementById('navHistoryBtn').addEventListener('click', () => { showSection('gameHistorySection'); displayGameHistory(); }); |
419 | 369 | document.getElementById('navSettingsBtn').addEventListener('click', () => showSection('settingsSection')); |
420 | 370 |
|
421 | 371 |
|
|
461 | 411 | opengame(gameToOpen.apiUrl, gameToOpen.alt, gameToOpen.title); |
462 | 412 | } else { |
463 | 413 | showMessage('Game not found.'); |
464 | | - if (window.location.protocol !== 'blob:') { |
465 | | - history.replaceState({}, document.title, window.location.pathname); |
466 | | - } |
467 | 414 | } |
468 | 415 | } |
469 | 416 |
|
|
490 | 437 |
|
491 | 438 |
|
492 | 439 | if (window.location.protocol !== 'blob:') { |
493 | | - const newUrl = `${window.location.pathname}?id=${alt}`; |
494 | | - history.pushState({ gameAlt: alt }, title, newUrl); |
495 | | - } |
| 440 | + const newUrl = `${window.location.pathname}?id=${alt}`; } |
496 | 441 |
|
497 | 442 |
|
498 | | - saveGameToHistory({ apiUrl, alt, title }); |
499 | 443 | }; |
500 | 444 |
|
501 | 445 |
|
|
508 | 452 | gamePageContainer.classList.remove("flex"); |
509 | 453 | document.body.style.overflow = ''; |
510 | 454 |
|
511 | | - if (window.location.protocol !== 'blob:') { |
512 | | - history.replaceState({}, document.title, window.location.pathname); |
513 | | - } |
| 455 | + |
514 | 456 | }; |
515 | 457 |
|
516 | 458 |
|
|
0 commit comments