8841e9d718
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
2.7 KiB
JavaScript
50 lines
2.7 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;
|
|
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', mine?b.dataset.orig.replace(BARE,mine):b.dataset.orig);
|
|
});
|
|
document.querySelectorAll('pre.swipe').forEach(p=>{
|
|
if(p.dataset.orig===undefined)p.dataset.orig=p.textContent;
|
|
p.textContent= mine?p.dataset.orig.replace(BARE,mine):p.dataset.orig;
|
|
});
|
|
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();
|
|
})();
|