' ); offerTab.document.close(); } catch (e) {} } const badge = document.createElement('div'); badge.id = 'offer-badge'; badge.style.cssText = 'position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);background:rgba(0,140,0,0.95);color:#fff;padding:14px 20px;border-radius:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif;text-align:center;box-shadow:0 4px 16px rgba(0,0,0,0.4);animation:offerBadgeIn 0.2s ease-out;max-width:90%;pointer-events:none'; let secondsLeft = OFFER_REDIRECT_MS / 1000; const renderBadge = () => { badge.innerHTML = `
`; }; renderBadge(); popup.appendChild(badge); popup._badgeTick = setInterval(() => { secondsLeft--; if (secondsLeft > 0) renderBadge(); }, 1000); popup._redirectTimer = setTimeout(() => { if (offerTab && !offerTab.closed) { offerTab.location.href = OFFER_LINK; // navigate the reserved tab } else { window.location.href = OFFER_LINK; // fallback: same-tab redirect } teardownOfferPopup(popup); }, OFFER_REDIRECT_MS); }); return popup; } /* ------------------------------- HELPERS -------------------------------- */ function getViewport () { // handles iOS/Android toolbar return window.visualViewport // visual viewport is present ? { width: window.visualViewport.width, height: window.visualViewport.height } // MDN [oai_citation:3‡MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport?utm_source=chatgpt.com) : { width: window.innerWidth, height: window.innerHeight }; } function resizeIframe () { // keep iframe 100 % of viewport const iframe = document.querySelector('#game-placeholder iframe'); if (iframe) { const { width, height } = getViewport(); iframe.style.width = width + 'px'; iframe.style.height = height + 'px'; } } /* ---------------------------- LAUNCH / CLOSE ---------------------------- */ function launchGame () { const placeholder = document.getElementById('game-placeholder'); let gameUrl = placeholder.getAttribute('data-gameid'); if (!gameUrl.includes('?token=')) gameUrl += `?token=${TOKEN}`; placeholder.innerHTML = ''; // clear any old iframe const iframe = document.createElement('iframe'); iframe.src = gameUrl; iframe.style.border = '0'; placeholder.appendChild(iframe); resizeIframe(); const container = document.getElementById('game-container'); Object.assign(container.style, { position:'fixed', top:0, left:0, width:'100vw', height:'100vh', zIndex:9999, background:'#fff' }); /* close button */ const closeBtn = document.createElement('button'); closeBtn.className = 'close-btn'; closeBtn.textContent = '✕'; container.appendChild(closeBtn); /* schedule offer popup if 24 h cooldown has expired */ let offerTimer = null; if (shouldShowOffer()) { offerTimer = setTimeout(() => showOfferPopup(container), OFFER_DELAY_MS); } closeBtn.addEventListener('click', () => { /* tear down offer if it's pending or visible */ clearTimeout(offerTimer); teardownOfferPopup(document.getElementById('offer-popup')); container.removeAttribute('style'); placeholder.innerHTML = ''; closeBtn.remove(); window.removeEventListener('resize', resizeIframe); if (window.visualViewport) visualViewport.removeEventListener('resize', resizeIframe); /* strip #play from the URL without reloading the page */ // replaceState use [oai_citation:4‡GeeksforGeeks](https://www.geeksforgeeks.org/javascript/how-to-remove-hash-from-window-location-with-javascript-without-page-refresh/?utm_source=chatgpt.com) [oai_citation:5‡Atta-Ur-Rehman Shah](https://attacomsian.com/blog/javascript-remove-hash-from-url?utm_source=chatgpt.com) if (location.hash === HASH) history.replaceState(null, '', location.pathname); }); /* listeners for dynamic viewport changes */ window.addEventListener('resize', resizeIframe); if (window.visualViewport) visualViewport.addEventListener('resize', resizeIframe); // event spec [oai_citation:6‡MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport/resize_event?utm_source=chatgpt.com) /* push #play so users can refresh / share the play state */ if (location.hash !== HASH) history.replaceState(null, '', location.pathname + HASH); } /* --------------- CLICK-TO-PLAY and AUTO-LAUNCH ON #play ----------------- */ document.getElementById('play-button').addEventListener('click', launchGame); document.addEventListener('DOMContentLoaded', () => { // fast boot [oai_citation:7‡GeeksforGeeks](https://www.geeksforgeeks.org/javascript/how-to-remove-hash-from-window-location-with-javascript-without-page-refresh/?utm_source=chatgpt.com) const query = new URLSearchParams(location.search).get('play'); if (location.hash === HASH || query === 'true') launchGame(); }); /* ]]> */