Skip to content

Instantly share code, notes, and snippets.

@poteto
Last active September 11, 2019 17:49
Show Gist options
  • Save poteto/0d1cb865f187edd38d9350caed5a6a38 to your computer and use it in GitHub Desktop.
Save poteto/0d1cb865f187edd38d9350caed5a6a38 to your computer and use it in GitHub Desktop.
Delete everyone from your Facebook group! Thanks for the dark UX, FB
class FBGroupMemberRemover {
constructor() {
this.adminText = 'Admin';
this.removeMemberModalHeadingText = 'Remove Member';
this.memberElementSelector = '[data-name="GroupProfileGridItem"]';
this.memberContextMenuSelector = 'button[aria-label="Member Settings"]';
this.removeMemberButtonSelector = 'a[data-testid="leave_group"]'
this.removalOptions = {
delete_posts: true,
delete_comments: true,
delete_invites: true,
ban_user: true
}
}
*visibleMembers() {
for (let el of Array.from(
document.querySelectorAll(this.memberElementSelector)
).filter(el => !el.textContent.includes(this.adminText))) {
yield el;
}
}
openContextMenuForMember(memberEl) {
memberEl.querySelector(this.memberContextMenuSelector).click();
}
openRemoveMemberDialog() {
const el = document.querySelector(this.removeMemberButtonSelector)
el.click();
el.remove(); // clean up old element since querySelector picks the first one
}
setRemovalOptions() {
for (let key in this.removalOptions) {
const value = this.removalOptions[key];
if (value === false) { return; }
this.removeMemberModalEl
.querySelector(`input[type="checkbox"][name="${key}"]`).click();
}
}
confirmRemoveMember() {
this.removeMemberModalEl.querySelector('button').click();
}
wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
get removeMemberModalEl() {
return Array.from(document.querySelectorAll('form'))
.find(el => el.textContent.includes(this.removeMemberModalHeadingText))
}
async start() {
for (let memberEl of this.visibleMembers()) {
this.openContextMenuForMember(memberEl);
await this.wait(100);
this.openRemoveMemberDialog();
await this.wait(1000);
// this.setRemovalOptions(); // if you care about deleting posts etc
// await this.wait(100);
this.confirmRemoveMember();
}
}
}
const fbgmr = new FBGroupMemberRemover();
fbgmr.start();
@Sh4d0wW4ll
Copy link

VM478:41 Uncaught (in promise) TypeError: Cannot read property 'querySelector' of undefined
at FBGroupMemberRemover.setRemovalOptions (:41:10)
at FBGroupMemberRemover.start (:65:12)
at

How can I solve?

Copy link

ghost commented Jul 17, 2018

Removed some procedures use the code break system and set the functions as local to suppress the error

@jimbobwho
Copy link

This works great all apart from the confirmRemoveMember(); function it fails to recognise @button@ and so none of the dialogues close. You have to confirm them individually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment