nsite-ts/public/main.js

33 lines
878 B
JavaScript
Raw Normal View History

2024-09-25 15:28:28 -05:00
import { nip19, SimplePool } from "nostr-tools";
2024-09-01 13:26:37 -05:00
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-25 15:28:28 -05:00
site.querySelector(".pubkey").textContent = npub;
site.querySelector(".link").href = new URL("/", `${location.protocol}//${npub}.${location.host}`).toString();
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
}
}
const pool = new SimplePool();
2024-09-25 15:28:28 -05:00
console.log("Loading sites");
pool.subscribeMany(
["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine"],
[{ kinds: [34128], "#d": ["/index.html"] }],
{
onevent: addSite,
},
);