Compare commits

..

1 Commits

Author SHA1 Message Date
a1a9a01e2c
Adapt extension for Chrome support 2025-04-30 14:31:32 +04:00
5 changed files with 22 additions and 53 deletions

View File

@ -1,27 +1,27 @@
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status !== 'complete') {
browser.pageAction.hide(tabId);
browser.storage.local.remove(`nl_tab_${sender.tab.id}`);
chrome.action.disable(tabId);
chrome.storage.local.remove(`nl_tab_${tabId}`);
return;
}
}, { properties: ["status"] });
});
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "showNostrLinksPageAction" && sender.tab?.id) {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'showNostrLinksPageAction' && sender.tab?.id) {
const tabLinks = { [`nl_tab_${sender.tab.id}`]: message.links };
browser.storage.local.set(tabLinks, () => {
browser.pageAction.show(sender.tab.id);
chrome.storage.local.set(tabLinks, () => {
chrome.action.enable(sender.tab.id);
});
}
if (message.action === "getNostrLinks" && message.tabId) {
browser.storage.local.get(`nl_tab_${message.tabId}`, (result) => {
if (message.action === 'getNostrLinks' && message.tabId) {
chrome.storage.local.get(`nl_tab_${message.tabId}`, (result) => {
sendResponse({ links: result[`nl_tab_${message.tabId}`] || [] });
});
return true; // Keep message channel open for async response
}
});
browser.tabs.onRemoved.addListener((tabId) => {
browser.storage.local.remove(`nl_tab_${tabId}`);
chrome.tabs.onRemoved.addListener((tabId) => {
chrome.storage.local.remove(`nl_tab_${tabId}`);
});

View File

@ -1,17 +1,13 @@
document.addEventListener('DOMContentLoaded', function() {
const linkRels = ['alternate', 'me', 'author'];
const selectorUntyped = linkRels.map(rel => `link[rel="${rel}"][href^="nostr:"]`).join(',');
const selectorTyped = linkRels.map(rel => `link[rel="${rel}"][type="application/nostr+json"]`).join(',');
const untypedLinks = document.querySelectorAll(selectorUntyped);
const typedLinks = document.querySelectorAll(selectorTyped);
const links = [...untypedLinks, ...typedLinks]
const linkMap = new Map();
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 (links.length > 0) {
links.forEach(link => {
const uri = link.href.replace(/^(nostr|web+nostr):/, "").trim();
let text = link.title?.trim() || '';
if (link.rel === "me") text = `Me: ${text}`;
if (link.rel === "author") text = `Author: ${text}`;
linkMap.set(uri, {
@ -22,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
browser.runtime.sendMessage({
chrome.runtime.sendMessage({
action: "showNostrLinksPageAction",
links: Array.from(linkMap.values())
});

View File

@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Nostr Links",
"version": "1.1.0",
"version": "1.0.2",
"description": "A web extension to discover Nostr links",
"author": "Râu Cao",
"homepage_url": "https://gitea.kosmos.org/raucao/nostr-links",
@ -15,9 +15,7 @@
"activeTab"
],
"background": {
"scripts": [
"background.js"
]
"service_worker": "background.js"
},
"content_scripts": [
{
@ -26,7 +24,7 @@
"run_at": "document_start"
}
],
"page_action": {
"action": {
"default_icon": "icons/nostr.svg",
"default_title": "Nostr",
"default_popup": "popup/nostr-links.html"

View File

@ -1,7 +1,7 @@
browser.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const tabId = tabs[0].id;
browser.runtime.sendMessage({ action: "getNostrLinks", tabId }, (response) => {
chrome.runtime.sendMessage({ action: "getNostrLinks", tabId }, (response) => {
const menu = document.getElementById("link-menu");
if (response.links && response.links.length > 0) {
menu.innerHTML = response.links

View File

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example page</title>
<link rel="me" href="nostr:npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees" title="Ru Cao">
<link rel="me" type="application/nostr+json" href="nostr:npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees" title="Râu Cao">
<link rel="author" type="text/html" href="https://nostr.kosmos.org/@jimmy" title="Jimmy">
<link rel="author" type="application/nostr+json" href="nostr:nprofile1qyfhwue69uhkcmmrv9kxsmmnwsarwdehxuqzqplp3zsllp7wzuw4z7uw62ah5vd36dzn5rdnk9fhnmq8kujdyvhnmg53sl" title="Jimmy">
<link rel="alternate" type="application/nostr+json" href="nostr:naddr1qvzqqqr4gupzqplp3zsllp7wzuw4z7uw62ah5vd36dzn5rdnk9fhnmq8kujdyvhnqyfhwue69uhkcmmrv9kxsmmnwsarwdehxuqq6vfhxgunvwp4x5unwve3xcmz28za" title="Testing my new blog">
</head>
<body>
<h1>Nostr Links Examples</h1>
<p>(Inspect link tags in source)</p>
<article>
<h2>Testing my new blog</h2>
<div class="meta"><p>By Jimmy, published on October 23, 2024</p></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <a href="https://njump.me/nprofile1qyt8wumn8ghj7mn0wd68yetvd96x2uewdaexwtcpz4mhxue69uhhyetvv9ujuat50phjummwv5hsqgqmcu9qzj9n7vtd5vl78jyly037wxkyl7vcqflvwy4eqhxjfa4yzyzh27uu" rel="noopener noreferrer">Excepteur</a> sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, <a href="https://en.wikipedia.org/wiki/Lorem_ipsum" rel="noopener noreferrer">consectetur</a> adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo <a href="https://njump.me/naddr1qvzqqqr4gupzpwcpwjhzrfk2cxs2nj9543htlkjkeegkqhp3tvvzf9ctcf6lwgu6qqgrjvmyv93nwcmxvvukgdmxxfjn2eqwafx" rel="noopener noreferrer">consequat</a>.</p>
<h3>A sub heading goes a long way</h3>
<p>Lorem ipsum dolor sit amet, <a href="https://en.wikipedia.org/wiki/Lorem_ipsum" rel="noopener noreferrer">consectetur</a> adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut <a href="npub1qlsc3g0lsl8pw8230w8d9wm6xxcax3f6pkemz5measrmwfxjxteslf2hac" rel="noopener noreferrer">aliquip ex</a> ea commodo <a href="nprofile1qy2hwumn8ghj7un9d3shjtnyv9kh2uewd9hj7qgkwaehxw309aex2mrp0yhx6mmnw3ezuur4vghsqgq8uxy2rlu8ect365tm3mftk733k8f52wsdkwc4x70vq7mjf53j7v7hknv0" rel="noopener noreferrer">consequat</a>.</p>
</article>
</body>
</html>