Files
rm-circle-team-router/public/tools.js
T
martbost 131fa8ae2a Tools: Promote-on-Telegram section (Mini App links, posts, team setup swipe)
/tools#telegram: the member's t.me/RMCircleBot/join?startapp=YOURID links
(moving + 4 angles, self-preview tip), a paste-ready group post and warm DM,
and the connect-your-team setup message to forward (teach-forward). tools.js
personalize() now also fills YOURID tokens. Chatbot canned answer + AI prompt
synced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 07:22:00 -05:00

57 lines
2.9 KiB
JavaScript

(function(){
function copy(text, btn){
if(!text) return;
navigator.clipboard.writeText(text).then(()=>{
const old=btn.dataset.label||btn.textContent; btn.dataset.label=old;
btn.textContent='Copied ✓'; btn.disabled=true;
setTimeout(()=>{btn.textContent=old; btn.disabled=false;},1500);
}).catch(()=>{ btn.textContent='Copy failed'; setTimeout(()=>{btn.textContent=btn.dataset.label||'Copy';},1500); });
}
document.querySelectorAll('.copy-btn').forEach(b=>b.addEventListener('click',()=>copy(b.getAttribute('data-copy'),b)));
const idIn=document.getElementById('toolId'), link=document.getElementById('shareLink'), copyShare=document.getElementById('copyShare');
function url(){ const id=(idIn.value||'').replace(/\D/g,'').slice(0,15); return id?`https://rmcircle.team/join/${id}`:''; }
function render(){ link.textContent=url()||'https://rmcircle.team/join/…'; }
// ---- personalization: every asset carries the member's own invite link ----
// Replaces BARE https://rmcircle.team mentions (not /contract, /v/…, /banners/…)
// in both the copy payloads and the visible previews. ID comes from ?id=
// (dashboard hand-off), then localStorage, then the "Your link" box.
const BARE=/https:\/\/rmcircle\.team(?![\w./-])/g;
// YOURID marks Telegram Mini App links (t.me/...?startapp=YOURID[_angle]).
function fill(text,mine,id){
let out=text;
if(mine)out=out.replace(BARE,mine);
if(id)out=out.replace(/YOURID/g,id);
return out;
}
function personalize(){
const id=(idIn&&idIn.value||'').replace(/\D/g,'').slice(0,15);
const mine=id?`https://rmcircle.team/join/${id}`:null;
document.querySelectorAll('.copy-btn').forEach(b=>{
if(b.dataset.orig===undefined)b.dataset.orig=b.getAttribute('data-copy')||'';
b.setAttribute('data-copy', fill(b.dataset.orig,mine,id));
});
document.querySelectorAll('pre.swipe').forEach(p=>{
if(p.dataset.orig===undefined)p.dataset.orig=p.textContent;
p.textContent=fill(p.dataset.orig,mine,id);
});
const note=document.getElementById('personalNote');
if(note){
if(mine){ note.style.display='block'; const s=note.querySelector('strong'); if(s)s.textContent='#'+id; const l=note.querySelector('.pnl'); if(l)l.textContent=mine; }
else note.style.display='none';
}
if(id){ try{localStorage.setItem('rmc.toolsId',id);}catch(e){} }
}
(function initId(){
if(!idIn)return;
const q=new URLSearchParams(location.search).get('id');
let id=(q&&/^\d{1,15}$/.test(q))?q:'';
if(!id){ try{const s=localStorage.getItem('rmc.toolsId'); if(s&&/^\d{1,15}$/.test(s))id=s;}catch(e){} }
if(id&&!idIn.value)idIn.value=id;
})();
if(idIn){ idIn.addEventListener('input',function(){render();personalize();}); render(); }
if(copyShare){ copyShare.addEventListener('click',()=>{ const u=url(); if(!u){ idIn.focus(); return; } copy(u,copyShare); }); }
personalize();
})();