a demonstration replicated social networking web app built with anproto wiredove.net/
social ed25519 protocols
at master 43 lines 1.4 kB view raw
1import { apds } from 'apds' 2 3const timestampRefreshMs = 60000 4const visibleTimestamps = new Map() 5let timestampObserver = null 6 7const refreshTimestamp = async (element, timestamp) => { 8 if (!document.body.contains(element)) { 9 const stored = visibleTimestamps.get(element) 10 if (stored) { clearInterval(stored.intervalId) } 11 visibleTimestamps.delete(element) 12 return 13 } 14 element.textContent = await apds.human(timestamp) 15} 16 17export const observeTimestamp = (element, timestamp) => { 18 if (!element) { return } 19 element.dataset.timestamp = timestamp 20 if (!timestampObserver) { 21 timestampObserver = new IntersectionObserver((entries) => { 22 entries.forEach(entry => { 23 const target = entry.target 24 const ts = target.dataset.timestamp 25 if (!ts) { return } 26 if (entry.isIntersecting) { 27 refreshTimestamp(target, ts) 28 if (!visibleTimestamps.has(target)) { 29 const intervalId = setInterval(() => { 30 refreshTimestamp(target, ts) 31 }, timestampRefreshMs) 32 visibleTimestamps.set(target, { intervalId }) 33 } 34 } else { 35 const stored = visibleTimestamps.get(target) 36 if (stored) { clearInterval(stored.intervalId) } 37 visibleTimestamps.delete(target) 38 } 39 }) 40 }) 41 } 42 timestampObserver.observe(element) 43}