Skip to content

Instantly share code, notes, and snippets.

@Bossett
Last active October 30, 2023 18:54
Show Gist options
  • Save Bossett/adb894e142fbdc5dec1df3eb889c3c10 to your computer and use it in GitHub Desktop.
Save Bossett/adb894e142fbdc5dec1df3eb889c3c10 to your computer and use it in GitHub Desktop.
followAllListMembers.js
// FOLLOWS ALL MEMBERS OF A LIST
// -----------------------------
// Navigate from https://bsky.app/ to the list you want to follow
// Open the developer tools, and copy/paste this into the console tab:
// It may take a little while to run - the page will reload when finished
(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) || {};
let totalRetrieved = 0, currentCursor = "", members = [];
do {
const list = await (await fetch(`https://bsky.social/xrpc/app.bsky.graph.getList?list=at://${did}/app.bsky.graph.list/${rkey}&limit=100&cursor=${currentCursor}`, {
headers: { "Content-Type": "application/json", Authorization: `Bearer ${accessJwt}` }
})).json();
currentCursor = list.cursor;
totalRetrieved = list.items.length;
members = [...members, ...list.items];
} while (totalRetrieved > 0);
for (let i = 0; i < members.length; i += 10) {
await Promise.all(members.slice(i, i + 10).map((member) => 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.follow", repo, record: { subject: member.subject.did, createdAt: new Date().toISOString() } })
})));
}
location.reload();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment