2024-09-25 15:28:28 -05:00
|
|
|
import { nip19, SimplePool } from "nostr-tools";
|
2024-09-01 13:26:37 -05:00
|
|
|
|
2024-09-26 16:03:28 -05:00
|
|
|
const relays = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine"];
|
|
|
|
const pool = new SimplePool();
|
|
|
|
|
2024-09-25 15:28:28 -05:00
|
|
|
const seen = new Set();
|
|
|
|
function addSite(event) {
|
|
|
|
if (seen.has(event.pubkey)) return;
|
|
|
|
seen.add(event.pubkey);
|
2024-09-01 13:26:37 -05:00
|
|
|
|
2024-09-25 15:28:28 -05:00
|
|
|
try {
|
|
|
|
const template = document.getElementById("site");
|
|
|
|
const site = template.content.cloneNode(true);
|
|
|
|
const npub = nip19.npubEncode(event.pubkey);
|
2024-09-01 13:26:37 -05:00
|
|
|
|
2024-09-26 16:03:28 -05:00
|
|
|
site.querySelector("nostr-name").setAttribute("pubkey", event.pubkey);
|
|
|
|
site.querySelector("nostr-name").textContent = npub.slice(0, 8);
|
|
|
|
site.querySelector("nostr-picture").setAttribute("pubkey", event.pubkey);
|
|
|
|
|
|
|
|
site
|
|
|
|
.querySelector(".nsite-link")
|
|
|
|
?.setAttribute("href", new URL("/", `${location.protocol}//${npub}.${location.host}`).toString());
|
|
|
|
site.querySelector("time").textContent = new Date(event.created_at * 1000).toDateString();
|
2024-09-01 13:26:37 -05:00
|
|
|
|
2024-09-25 15:28:28 -05:00
|
|
|
document.getElementById("sites").appendChild(site);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("Failed to add site", event);
|
|
|
|
console.log(error);
|
2024-09-01 13:26:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 15:28:28 -05:00
|
|
|
console.log("Loading sites");
|
2024-09-26 16:03:28 -05:00
|
|
|
pool.subscribeMany(relays, [{ kinds: [34128], "#d": ["/index.html"] }], {
|
|
|
|
onevent: addSite,
|
|
|
|
});
|