Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// The account a Bluesky profile URL names, without the browser around it.//// bsky.app's profile pages serve no standard.site well-known, so the one thing// that identifies whose publications to look for is the URL itself. Kept// separate from src/content.ts so the parsing rules can be unit-tested.
const BSKY_HOSTS = new Set(['bsky.app', 'www.bsky.app'])
/** * Path segments the SPA owns rather than names an account. A profile URL is * `/profile/<handle-or-did>`; these keep a route that happens to sit under * that prefix from being read as a handle. */const RESERVED = new Set([ 'about', 'download', 'feeds', 'hashtag', 'intent', 'lists', 'messages', 'moderation', 'notifications', 'privacy', 'profile', 'search', 'settings', 'start', 'support', 'terms',])
/** * The handle or DID named by a bsky.app profile URL, or undefined. * * Accepts `bsky.app` and `www.bsky.app`, and any trailing path such as * `/profile/<handle>/post/<rkey>` — the profile is the same account. Everything * else (other hosts, a bare `/profile/`, reserved routes, unparseable or * undecodable input) has no answer. */export function profileHandleFromUrl(url: string): string | undefined { let parsed: URL try { parsed = new URL(url) } catch { return undefined } if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return undefined if (parsed.port !== '') return undefined if (!BSKY_HOSTS.has(parsed.hostname)) return undefined
const segments = parsed.pathname.split('/').filter(Boolean) if (segments[0] !== 'profile') return undefined
const raw = segments[1] if (!raw) return undefined
let handle: string try { handle = decodeURIComponent(raw) } catch { return undefined } // A percent-encoded slash or question mark would change which route this // is; whitespace cannot be part of a handle or DID. if (!handle || /[/?#\s]/.test(handle)) return undefined if (RESERVED.has(handle.toLowerCase())) return undefined return handle}