Tools page auto-personalization: dashboard hands off ?id=, every post/swipe (copy payload AND visible preview) swaps the bare main-domain link for the member's /join/<id> link; sticky via localStorage; green confirmation banner
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+33
-1
@@ -12,6 +12,38 @@
|
||||
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/…'; }
|
||||
if(idIn){ idIn.addEventListener('input',render); render(); }
|
||||
|
||||
// ---- 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();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user