document.addEventListener('DOMContentLoaded', ()=>{ renderDirectory(); renderKarma(); renderResources(); bindCheckout(); }); // Listing JSON generator function generateListingJSON(){ const name = document.getElementById('new_name').value.trim(); const category = document.getElementById('new_category').value.trim(); const city = document.getElementById('new_city').value.trim(); const url = document.getElementById('new_url').value.trim(); const tags = document.getElementById('new_tags').value.split(',').map(s=>s.trim()).filter(Boolean); const desc = document.getElementById('new_desc').value.trim(); const id = name.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/(^-|-$)/g,''); const obj = { "id": id, "name": name, "category": category, "city": city, "url": url, "tags": tags, "desc": desc, "logo":"./img/placeholder.svg", "reviews": 0, "stars": 0, "verified": false, "karma": {"profile":0.5,"reviews":0.5,"velocity":0.5,"verification":0.0} }; document.getElementById('new_output').value = JSON.stringify(obj, null, 2); } // Digital Karma page async function renderKarma(){ const kconf = document.getElementById('kconf'); const kboard = document.getElementById('kboard'); if(!kconf && !kboard) return; const [conf, data] = await Promise.all([getJSON('./data/karma-config.json'), getJSON('./data/listings.json')]); const W = conf.weights; if(kconf){ kconf.innerHTML = ` SignalWeightDescription Profile${(W.profile*100).toFixed(0)}%Completeness, images, links, schema Reviews${(W.reviews*100).toFixed(0)}%Stars & recent review velocity Velocity${(W.velocity*100).toFixed(0)}%Update cadence / freshness Verification${(W.verification*100).toFixed(0)}%Ownership & identity proof `; } if(kboard){ function score(k){ if(!k) return 0; return (k.profile*W.profile + k.reviews*W.reviews + k.velocity*W.velocity + k.verification*W.verification) } const items = data.listings.map(x=>({...x,_karma:score(x.karma)})).sort((a,b)=>b._karma-a._karma).slice(0,10); kboard.innerHTML = items.map((x,i)=>`
${i+1}. ${x.name} (${x.category})
${(x._karma*100).toFixed(0)}
`).join(''); } } // Health Check logic async function runHealthCheck(){ const [conf] = await Promise.all([getJSON('./data/karma-config.json')]); const W = conf.weights;