be268beb66
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
4.6 KiB
JavaScript
65 lines
4.6 KiB
JavaScript
// /presentation (2026-10-15): the narrated Build Wide presentation, caption language pills, and a
|
|
// sponsor card for whoever shared the link. Public, no sign-in. Works framed (traffic exchanges):
|
|
// join and sign-in open in a new tab and every internal link carries the sharer's ?ref, because a
|
|
// cross-site frame usually cannot keep the sponsor cookie.
|
|
(async function () {
|
|
const $ = id => document.getElementById(id);
|
|
const esc = t => String(t || '').replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
const framed = (() => { try { return window.top !== window.self; } catch (e) { return true; } })();
|
|
const ref = String(new URLSearchParams(location.search).get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20);
|
|
try { await IAP.renderNav('presentation'); } catch (e) {}
|
|
|
|
// ---- caption pills: Off + one per track; a non-English browser starts in its own language
|
|
const v = $('prVideo'), bar = $('prCaps');
|
|
const NAMES = { en: 'English', it: 'Italiano', fr: 'Français', es: 'Español', de: 'Deutsch', pt: 'Português' };
|
|
const tracks = () => [...(v.textTracks || [])].filter(t => t.kind === 'captions' || t.kind === 'subtitles');
|
|
function show(lang) {
|
|
tracks().forEach(t => { t.mode = lang && String(t.language).toLowerCase() === lang ? 'showing' : 'disabled'; });
|
|
bar.querySelectorAll('button').forEach(b => b.setAttribute('aria-pressed', b.dataset.lang === (lang || '') ? 'true' : 'false'));
|
|
try { localStorage.setItem('iap.capLang', lang || 'off'); } catch (e) {}
|
|
}
|
|
if (v && bar) {
|
|
bar.innerHTML = '<span class="lab">Captions</span>' + ['', 'en', 'it', 'fr', 'es', 'de', 'pt'].map(l => '<button type="button" data-lang="' + l + '" aria-pressed="false">' + (l ? NAMES[l] : 'Off') + '</button>').join('');
|
|
bar.querySelectorAll('button').forEach(b => b.addEventListener('click', () => show(b.dataset.lang)));
|
|
let start = '';
|
|
try { start = localStorage.getItem('iap.capLang') || ''; } catch (e) {}
|
|
if (!start) { const nav = String(navigator.language || '').slice(0, 2).toLowerCase(); start = NAMES[nav] && nav !== 'en' ? nav : 'off'; }
|
|
show(start === 'off' ? '' : start);
|
|
}
|
|
|
|
// ---- links: join / sign-in open a new tab when framed; internal links carry ?ref
|
|
function decorate(root) {
|
|
root.querySelectorAll('a[href]').forEach(a => {
|
|
const h = a.getAttribute('href');
|
|
if (!h || !h.startsWith('/') || h.startsWith('//') || h.startsWith('/api/')) return;
|
|
if (framed && /^\/(my|join)(\/|$|\?|#)/.test(h)) { a.target = '_blank'; a.rel = 'noopener'; }
|
|
if (ref && !/^\/join\//.test(h) && !/[?&]ref=/.test(h)) { const [p, hash] = h.split('#'); a.setAttribute('href', p + (p.includes('?') ? '&' : '?') + 'ref=' + ref + (hash ? '#' + hash : '')); }
|
|
});
|
|
}
|
|
|
|
// ---- sponsor card: the link's owner (?ref) first, then the visitor's sponsor cookie
|
|
try {
|
|
const sp = await (await fetch('/api/sponsor' + (ref ? '?ref=' + encodeURIComponent(ref) : ''))).json();
|
|
const tok = ref || (sp && sp.ref) || '';
|
|
if (sp && sp.name && tok && !sp.own) {
|
|
$('prHead').innerHTML = 'Shared with you by <b>' + esc(sp.name) + '</b>';
|
|
// /api/sponsor caps the bio at 220 characters, so a capped bio ends mid-word: trim it back to a word and add an ellipsis
|
|
const bio = sp.bio && sp.bio.length >= 220 ? sp.bio.slice(0, sp.bio.lastIndexOf(' ')).replace(/[\s,;:.—-]+$/, '') + '…' : sp.bio;
|
|
$('prText').textContent = bio ? bio : 'They can help you get set up in a few minutes, and they will be your sponsor on every platform in the network.';
|
|
$('prJoin').textContent = 'Join with ' + sp.name;
|
|
$('prJoin').href = '/join/' + encodeURIComponent(tok) + '?v=wide';
|
|
$('prIni').textContent = String(sp.name).replace(/^@/, '').slice(0, 1).toUpperCase() || '?';
|
|
if (sp.avatarUrl && /^https:\/\//.test(sp.avatarUrl)) { const im = $('prImg'); im.src = sp.avatarUrl; im.alt = sp.name; im.hidden = false; $('prIni').hidden = true; im.onerror = () => { im.hidden = true; $('prIni').hidden = false; }; }
|
|
} else if (sp && sp.own) {
|
|
$('prHead').textContent = 'This is your presentation link';
|
|
$('prText').textContent = 'Anyone who opens it sees you here, with a Join button that puts them on your line. Copy it from Promo tools.';
|
|
$('prJoin').textContent = 'Open Promo tools'; $('prJoin').href = '/my#promo';
|
|
} else {
|
|
$('prJoin').href = '/join';
|
|
}
|
|
} catch (e) {}
|
|
if (framed) { $('prJoin').target = '_blank'; $('prJoin').rel = 'noopener'; }
|
|
decorate(document);
|
|
setTimeout(() => decorate(document), 1500); // the nav's sign-in link arrives after /api/me
|
|
})();
|