// In-Telegram polish for every site page. No-ops in a normal browser; inside // the Mini App webview it lazy-loads the vendored Telegram SDK (CSP stays // script-src 'self') and wires theme + BackButton so pages feel native. (function () { 'use strict'; var inTg = false; try { inTg = sessionStorage.getItem('rmcTg') === '1'; } catch (e) {} if (!inTg && (window.TelegramWebviewProxy !== undefined || /tgWebApp(Data|Platform)/.test(location.hash))) inTg = true; if (!inTg) return; window.__rmcInTg = 1; // synchronous flag for page scripts (join-now.js etc.) try { sessionStorage.setItem('rmcTg', '1'); } catch (e) {} function boot() { var tg = window.Telegram && window.Telegram.WebApp; if (!tg || !tg.initData) return; tg.ready(); try { tg.expand(); } catch (e) {} try { tg.setHeaderColor('#071421'); tg.setBackgroundColor('#071421'); } catch (e) {} // Back button mirrors webview history: /app enters via location.replace, so // the landing dashboard has no history and stays clean; any deeper page // (tools, training, another member view) gets a native back arrow. var bb = tg.BackButton; if (bb && history.length > 1) { bb.show(); bb.onClick(function () { history.back(); }); } // External links must LEAVE the webview: wallet deep links (MetaMask/Trust) // have to reach the wallet app, t.me links belong to Telegram itself, and // explorers etc. open in the system browser. Same-origin links stay inside. document.addEventListener('click', function (ev) { var a = ev.target && ev.target.closest && ev.target.closest('a[href]'); if (!a) return; var href = a.href || ''; if (!/^https?:/i.test(href)) return; var ext = false; try { ext = new URL(href).origin !== location.origin; } catch (e) {} if (!ext) return; ev.preventDefault(); try { if (/^https:\/\/t\.me\//i.test(href) && tg.openTelegramLink) tg.openTelegramLink(href); else tg.openLink(href); } catch (e) { location.href = href; } }, true); } if (window.Telegram && window.Telegram.WebApp) { boot(); return; } var s = document.createElement('script'); s.src = '/telegram-web-app.js'; s.onload = boot; document.head.appendChild(s); })();