Created
July 2, 2024 15:35
-
-
Save imax9000/944ef8836e8de02130a64abccd4a2f58 to your computer and use it in GitHub Desktop.
Bookmarklet for getting at:// URI from a Bluesky page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(async function () { | |
const v = new RegExp("^https://(staging\.)?bsky\.app/profile/(?<id>[^/]+)(/(?<collection>[^/]+)(/(?<rkey>[^/]+))?)?$").exec(document.URL); | |
if (!v) {alert("Must be used on a Bluesky page"); return;} | |
const did = (await (await (async function () { | |
return await fetch("https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=" + v.groups.id, { | |
headers: { authorization: "Bearer " + JSON.parse(localStorage.getItem("BSKY_STORAGE")).session.currentAccount.accessJwt, }, | |
method: "GET", | |
}); | |
})()).json()).did; | |
const lines = [ | |
did, | |
`https://bsky.app/profile/${did}`, | |
]; | |
if (v.groups.collection && v.groups.rkey) { | |
lines.push(document.URL.replace(v.groups.id, did)); | |
switch (v.groups.collection) { | |
case "post": | |
lines.push(`at://${did}/app.bsky.feed.post/${v.groups.rkey}`); break; | |
case "lists": | |
lines.push(`at://${did}/app.bsky.graph.list/${v.groups.rkey}`); break; | |
} | |
} | |
alert(lines.join("\n")); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment