Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e133cae63 | |||
| 1fc46a38a8 | |||
| aa944e8894 | |||
| f04773a3a9 | |||
| bb56e269c4 | |||
| d6ef7cdd5e | |||
| 0dd0f8bf3d | |||
| f1c2b4a592 |
24
LICENSE
Normal file
24
LICENSE
Normal file
@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org/>
|
||||
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Nostr Links Web Extension
|
||||
|
||||
A browser extension for discovering and opening Nostr links.
|
||||
|
||||

|
||||
|
||||
Details described in this article: https://nostr.kosmos.org/@raucao/link-rel-nostr
|
||||
|
||||
## ngit
|
||||
|
||||
This repo is also available via ngit:
|
||||
|
||||
git clone nostr://raucao@kosmos.org/nostr-links
|
||||
|
||||
[Issues and PRs](https://gitworkshop.dev/raucao@kosmos.org/nostr-links/prs)
|
||||
are also accepted this way.
|
||||
|
||||
Quick start: https://gitworkshop.dev/quick-start
|
||||
32
content.js
32
content.js
@ -1,20 +1,30 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const alternateLinks = document.querySelectorAll('link[rel="alternate"][type="application/nostr+json"]');
|
||||
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();
|
||||
|
||||
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 === "me") text = `Me: ${text}`;
|
||||
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");
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Nostr Links",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.0",
|
||||
"description": "A web extension to discover Nostr links",
|
||||
"author": "Râu Cao",
|
||||
"homepage_url": "https://gitea.kosmos.org/raucao/nostr-links",
|
||||
|
||||
25
test/example.html
Normal file
25
test/example.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!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>
|
||||
Loading…
x
Reference in New Issue
Block a user