From f64bc007e1efbb84d5dca22ae978e3facc6b47b5 Mon Sep 17 00:00:00 2001 From: LittleBit Date: Wed, 12 Aug 2026 16:43:44 -0500 Subject: [PATCH] [new script] add switch-nostr-clients --- switch-nostr-clients.user.js | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 switch-nostr-clients.user.js diff --git a/switch-nostr-clients.user.js b/switch-nostr-clients.user.js new file mode 100644 index 0000000..4b5c0a2 --- /dev/null +++ b/switch-nostr-clients.user.js @@ -0,0 +1,49 @@ +// ==UserScript== +// @name Switch Nostr Clients +// @namespace https://tangled.org/did:plc:ba3ftueh2aewxja4dtuhi7kf +// @version 2026-08-08 +// @description Switch between different Nostr clients when viewing Nostr posts or profiles on the web +// @author LittleBit +// @match *://*/* +// @grant GM_registerMenuCommand +// ==/UserScript== + +(function() { + 'use strict'; + + // Client entries require "name", and either an allUrl or separate profileUrl and eventUrl + // profileUrl is used for npub/nprofile, eventUrl is used for nevent/naddr + // allUrl takes priority + // The NIP19 string will go in place of %n + const clients = [ + {name:"Ditto", allUrl:"https://ditto.pub/%n"}, + {name:"Primal", profileUrl:"https://primal.net/p/%n", eventUrl:"https://primal.net/e/%n"}, + {name:"Nostria", profileUrl:"https://nostria.app/p/%n", eventUrl:"https://nostria.app/e/%n"}, + {name:"Nosotros", allUrl:"https://nosotros.app/%n"}, + {name:"Nosotros Dev", allUrl:"https://dev.nosotros.app/%n"} + ]; + + const NIP19_REGEX = /(npub|nprofile|nevent|naddr)1[a-z0-9]+/i; + + function getNip19FromUrl() { + const match = window.location.href.match(NIP19_REGEX); + return match ? match[0] : null; + } + + function openInClient(clientObject) { + const nip19 = getNip19FromUrl(); + if (!nip19) { + window.alert("You aren't viewing a supported Nostr object; there's no NIP19 string in the URL."); + return; + } + + const isProfile = /^(npub|nprofile)/i.test(nip19); + const clientUrlTemplate = clientObject.allUrl || (isProfile ? clientObject.profileUrl : clientObject.eventUrl); + + window.location.href = clientUrlTemplate.replace("%n", nip19); + } + + clients.forEach((client) => { + GM_registerMenuCommand(`Open in ${client.name}`, ()=>{openInClient(client)}) + }) +})(); \ No newline at end of file -- knotmirror 0.0.1