-
-
Save Bossett/adb894e142fbdc5dec1df3eb889c3c10 to your computer and use it in GitHub Desktop.
followAllListMembers.js
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
// 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