Unfollow tool for Bluesky

add preview button

Changed files
+61 -39
src
+61 -39
src/App.tsx
···
import { BskyAgent } from "@atproto/api";
const [unfollowNotice, setUnfollowNotice] = createSignal("");
+
let unfollowURIs: number[] = [];
+
let followRecords: any[];
const fetchFollows = async (agent: any) => {
const PAGE_LIMIT = 100;
···
userHandle: any,
userPassword: any,
serviceURL: any,
+
preview: boolean,
) => {
setUnfollowNotice("");
···
password: userPassword,
});
-
const followRecords = await fetchFollows(agent);
+
if (!unfollowURIs.length) {
+
followRecords = await fetchFollows(agent);
-
let followsDID: string[] = [];
-
for (let n = 0; n < followRecords.length; n++)
-
followsDID[n] = followRecords[n].value.subject;
+
let followsDID: string[] = [];
+
for (let n = 0; n < followRecords.length; n++)
+
followsDID[n] = followRecords[n].value.subject;
-
for (let n = 0; n < followsDID.length; n = n + 25) {
-
const res = await agent.getProfiles({
-
actors: followsDID.slice(n, n + 25),
-
});
+
for (let n = 0; n < followsDID.length; n = n + 25) {
+
const res = await agent.getProfiles({
+
actors: followsDID.slice(n, n + 25),
+
});
-
let tmpDID: string[] = [];
-
for (let i = 0; i < res.data.profiles.length; i++) {
-
tmpDID[i] = res.data.profiles[i].did;
-
if (res.data.profiles[i].viewer?.blockedBy) {
-
await agent.deleteFollow(followRecords[i + n].uri);
-
console.log(
-
"Unfollowed blocked account: " + followRecords[i + n].value.subject,
-
" (" + res.data.profiles[i].handle + ")",
-
);
-
setUnfollowNotice(
-
unfollowNotice() +
-
"Unfollowed blocked account: " +
-
followRecords[i + n].value.subject +
-
" (" +
-
res.data.profiles[i].handle +
-
")<br>",
-
);
+
let tmpDID: string[] = [];
+
for (let i = 0; i < res.data.profiles.length; i++) {
+
tmpDID[i] = res.data.profiles[i].did;
+
if (res.data.profiles[i].viewer?.blockedBy) {
+
unfollowURIs.push(i + n);
+
//await agent.deleteFollow(followRecords[i + n].uri);
+
setUnfollowNotice(
+
unfollowNotice() +
+
"Found blocked account: " +
+
followRecords[i + n].value.subject +
+
" (" +
+
res.data.profiles[i].handle +
+
")<br>",
+
);
+
}
}
-
}
-
for (let i = 0; i < res.data.profiles.length; i++) {
-
if (!tmpDID.includes(followsDID[i + n])) {
-
await agent.deleteFollow(followRecords[i + n].uri);
-
console.log(
-
"Unfollowed deleted account: " + followRecords[i + n].value.subject,
-
);
-
setUnfollowNotice(
-
unfollowNotice() +
-
"Unfollowed deleted account: " +
-
followRecords[i + n].value.subject +
-
"<br>",
-
);
+
for (let i = 0; i < res.data.profiles.length; i++) {
+
if (!tmpDID.includes(followsDID[i + n])) {
+
unfollowURIs.push(i + n);
+
//await agent.deleteFollow(followRecords[i + n].uri);
+
setUnfollowNotice(
+
unfollowNotice() +
+
"Found deleted account: " +
+
followRecords[i + n].value.subject +
+
"<br>",
+
);
+
}
}
}
+
}
+
+
if (!preview) {
+
for (const i of unfollowURIs) {
+
await agent.deleteFollow(followRecords[i].uri);
+
setUnfollowNotice(
+
unfollowNotice() +
+
"Unfollowed account: " +
+
followRecords[i].value.subject +
+
"<br>",
+
);
+
}
+
unfollowURIs = [];
+
followRecords = [];
}
setUnfollowNotice(unfollowNotice() + "Done");
···
<button
type="button"
onclick={() =>
-
unfollowBsky(userHandle(), appPassword(), serviceURL())
+
unfollowBsky(userHandle(), appPassword(), serviceURL(), true)
+
}
+
>
+
Preview
+
</button>
+
<button
+
type="button"
+
onclick={() =>
+
unfollowBsky(userHandle(), appPassword(), serviceURL(), false)
}
>
Unfollow