f876351391
- /app decodes startapp=<sponsorId>[_<angle>] -> unlinked visitors land on the sponsor squeeze page /join/<ref>?src=miniapp (linked members still go to their dashboard); no-invite prospects get a gold Join button -> /join-now - tg-app.js: sync __rmcInTg flag; external links route out of the webview via openLink/openTelegramLink (wallet deep links reach the wallet app reliably) - join-now.js in the webview leads with the MetaMask/Trust deep links (no injected wallet can exist there); ref + src survive into the wallet browser - tgbot: links command + weekly digest include the t.me/<bot>/<short>?startapp Telegram-native invite once config.miniAppShortName is set (new PATCH key) - Synced chat.js canned answer + AI prompt (prospects can join from the app) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
51 lines
2.2 KiB
JavaScript
51 lines
2.2 KiB
JavaScript
// 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);
|
|
})();
|