(function () { 'use strict'; var params = new URLSearchParams(window.location.search); var redirect = params.get('redirect'); if (!redirect) { window.location.replace('/Main-Menu/'); return; } var safe = false; try { var u = new URL(redirect, window.location.origin); if (u.origin === window.location.origin && /^\/Game\/room-lobby\.html$/i.test(u.pathname)) { safe = true; } } catch (e) { safe = false; } if (!safe) { window.location.replace('/Game/lobby.html'); return; } var totalSlides = 7; var idx = 0; var slideImg = document.getElementById('slide-img'); var pageEl = document.getElementById('slide-page'); var fill = document.getElementById('loading-bar-fill'); var pctEl = document.getElementById('loading-pct'); var barWrap = document.getElementById('loading-bar-wrap'); function pad2(n) { return n < 10 ? '0' + n : String(n); } function showSlide(i) { idx = (i + totalSlides * 10) % totalSlides; if (slideImg) slideImg.src = 'IMAGE/t-' + pad2(idx + 1) + '.png?v=1'; if (pageEl) pageEl.textContent = (idx + 1) + ' / ' + totalSlides; } document.getElementById('btn-prev')?.addEventListener('click', function () { showSlide(idx - 1); }); document.getElementById('btn-next')?.addEventListener('click', function () { showSlide(idx + 1); }); var durationMs = 6500; var startTs = null; var navigated = false; function goLobby() { if (navigated) return; navigated = true; /* replace = ไม่ให้ room-lobby กด Back กลับมาค้างที่หน้า Loading — ควรกลับไป Main-Menu */ window.location.replace(redirect); } document.getElementById('btn-skip')?.addEventListener('click', goLobby); function tick(ts) { if (navigated) return; if (startTs == null) startTs = ts; var t = Math.min(1, (ts - startTs) / durationMs); var p = Math.min(100, Math.floor(t * 100)); if (fill) fill.style.width = p + '%'; if (pctEl) pctEl.textContent = p + '%'; if (barWrap) barWrap.setAttribute('aria-valuenow', String(p)); if (t >= 1) { goLobby(); return; } requestAnimationFrame(tick); } requestAnimationFrame(tick); })();