Add link rel=me and rel=author, filter unique URIs

This commit is contained in:
Râu Cao 2025-04-30 13:39:34 +04:00
parent 0dd0f8bf3d
commit d6ef7cdd5e
Signed by: raucao
GPG Key ID: 37036C356E56CC51

View File

@ -1,20 +1,26 @@
document.addEventListener('DOMContentLoaded', function() {
const alternateLinks = document.querySelectorAll('link[rel="alternate"][type="application/nostr+json"]');
const linkRels = ['alternate', 'me', 'author'];
const selector = linkRels.map(rel => `link[rel="${rel}"][type="application/nostr+json"]`).join(',');
const links = document.querySelectorAll(selector);
const linkMap = new Map();
if (alternateLinks.length > 0) {
console.debug("[nostr-links] Found:", alternateLinks);
if (links.length > 0) {
links.forEach(link => {
const uri = link.href.replace(/^(nostr|web+nostr):/, "").trim();
let text = link.title?.trim() || '';
if (link.rel === "author") text = `Author: ${text}`;
const links = Array.from(alternateLinks).map((link, index) => ({
uri: link.href.replace(/^(nostr|web+nostr):/, ""),
text: link.title.trim()
// icon: "icon.png"
}));
linkMap.set(uri, {
uri: uri,
text: text,
rel: link.rel
// icon: "icon.png"
});
});
browser.runtime.sendMessage({
action: "showNostrLinksPageAction",
links: links
links: Array.from(linkMap.values())
});
} else {
console.debug("[nostr-links] No nostr links found");
}
});