Skip to content

Instantly share code, notes, and snippets.

@Bossett
Last active October 28, 2023 21:25
Show Gist options
  • Save Bossett/008fa0c42c3234040b5c7362c9baa42e to your computer and use it in GitHub Desktop.
Save Bossett/008fa0c42c3234040b5c7362c9baa42e to your computer and use it in GitHub Desktop.
addSelfToList.js
// Navigate from https://bsky.app/ to the list you want to add yourself to
// Open the developer tools, and copy/paste this into the console tab:
(async () => {
const [_, handle, rkey] = window.location.href.match(/https:\/\/bsky.app\/profile\/(.*?)\/lists\/(.*?)(?:\/|$)/) || [];
if (!handle) return console.error("The URL doesn't match the expected format.");
const did = !handle.startsWith("did:") ? (await (await fetch(`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`)).json()).did : handle;
const { session } = JSON.parse(localStorage.root);
const { accessJwt, did: repo } = session.accounts.find(a => a.did === session.data.did) || {};
await fetch("https://bsky.social/xrpc/com.atproto.repo.createRecord", {
method: "POST", headers: {"Content-Type": "application/json", Authorization: `Bearer ${accessJwt}`},
body: JSON.stringify({collection: "app.bsky.graph.listitem", repo, record: {subject: repo, list: `at://${did}/app.bsky.graph.list/${rkey}`, createdAt: new Date().toISOString()}})
});
location.reload();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment