SiteโฏBuilder
Editing:
geofence-guard1.js
writable 0666
/* geo/geofenceโguard.js ----------------------------------------------------------- โข Looks for boundary.json via a lightweight fetch โข Shows / hides the edit form accordingly โข Requires: - #editForm (your existing form wrapper) - #locateBtn (LocateโMe button already in the page) - #geoBanner (empty div we add to show status) */ (async ()=>{ const slug = new URLSearchParams(location.search).get('user') || location.pathname.split('/').filter(Boolean).slice(-2,-1)[0]; if(!slug) return; const banner = document.createElement('div'); banner.id = 'geoBanner'; banner.style='font-weight:700;margin-bottom:1rem'; document.querySelector('h1')?.after(banner); const form = document.getElementById('editForm'); const btn = document.getElementById('locateBtn'); // 1) Does boundary.json exist? let zone=null; try{ const r = await fetch(`/social/${slug}/boundary.json`,{cache:'no-cache'}); if(r.ok) zone = await r.json(); }catch{} if(!zone){ banner.textContent='๐ This account is locked โ no geofence found.'; form?.remove(); btn?.remove(); return; } banner.textContent='๐ฐ๏ธ Geofence enabled โ click โLocateย Meย toย Editโ.'; form.style.display='none'; // 2) Hook the existing LocateโMe button btn?.addEventListener('click', ()=>{ navigator.geolocation.getCurrentPosition(pos=>{ const d = distKm(pos.coords.latitude,pos.coords.longitude, zone.lat, zone.lon); if(d<=zone.radius_km){ banner.textContent='โ Location verified โ you may edit.'; form.style.display=''; }else{ banner.textContent='โ You are outside the allowed area.'; } }, err=>{ banner.textContent='โ Unable to get your location.'; }, {timeout:8000}); }); function distKm(a,b,c,d){ const R=6371,rad=x=>x*Math.PI/180; const dLa=rad(c-a), dLo=rad(d-b); const e=Math.sin(dLa/2)**2 + Math.cos(rad(a))*Math.cos(rad(c))*Math.sin(dLo/2)**2; return 2*R*Math.atan2(Math.sqrt(e),Math.sqrt(1-e)); } })();
Save changes
Create folder
writable 0777
Create
Cancel