-
-
Save af-inet/fc287e6e23e8e33dfef0c160fcb10ec8 to your computer and use it in GitHub Desktop.
| /* | |
| HOW TO USE THIS PROGRAM | |
| 1. Log in to facebook, and go to your "Activity Feed". | |
| 2. Scroll down a little bit so you have posts on the screen. | |
| 3. Paste this code into the developer console. | |
| 4. Execute deletePost() in the console. | |
| 5. Done; watch as the bot will delete roughly 1 post every 4 seconds. | |
| 6. Refresh the page to disable the script. | |
| */ | |
| function clickConfirmDeleteButton() { | |
| var confirmDeleteButton = findConfirmDeleteButton(); | |
| // show the user we're about to click this button | |
| confirmDeleteButton.style.border = "solid 2px red" | |
| setTimeout(function () { | |
| // finally we can delete this post | |
| confirmDeleteButton.click(); | |
| // wait for the post to disappear | |
| setTimeout(function () { | |
| // the post was deleted, no need to increment the skip counter | |
| deletePost() | |
| }, 4000) | |
| }, 100) | |
| } | |
| function findConfirmDeleteButton() { | |
| var elements = document.querySelectorAll('button[type="submit"]'); | |
| for (var i = 0; i < elements.length; i++) { | |
| if (elements[i].textContent.toLowerCase() === "delete") { | |
| return elements[i]; | |
| } | |
| } | |
| throw new Error("failed to find confirm delete button") | |
| } | |
| function findDeleteButton() { | |
| var elements = [] | |
| var iterator = document.evaluate("//a[contains(., 'Delete')]", document, null, XPathResult.ANY_TYPE, null); | |
| var element = null; | |
| while (element = iterator.iterateNext()) { | |
| elements.push(element) | |
| } | |
| if (elements.length <= 0) { | |
| throw new Error("did not find delete button") | |
| } | |
| return elements[elements.length - 1] | |
| } | |
| function clickDeleteButton() { | |
| var deleteButton = findDeleteButton() | |
| // show the user we're about to click this button | |
| deleteButton.style.border = "solid 2px red" | |
| setTimeout(function () { | |
| deleteButton.click() | |
| setTimeout(clickConfirmDeleteButton, 1000); | |
| }, 100) | |
| } | |
| function findNextPost() { | |
| var elements = document.querySelectorAll('[data-tooltip-content="Edit"], [data-tooltip-content="Allowed on timeline"], [data-tooltip-content="Hidden from timeline"]'); | |
| if (elements.length > 0) { | |
| return elements[0]; | |
| } | |
| return null; | |
| } | |
| function deletePost() { | |
| var target = findNextPost() | |
| if (target) { | |
| // show the user we're about to click this button | |
| target.style.border = "solid 2px red"; | |
| setTimeout(function () { | |
| target.click(); | |
| // don't click that shit again | |
| target.parentElement.removeChild(target); | |
| setTimeout(clickDeleteButton, 100); | |
| }, 100) | |
| } | |
| else { | |
| console.log("failed to find a post, scrolling down and starting over. We might have run out of posts..."); | |
| // this part is annoying because we need to scroll down and wait for new posts to load, | |
| // so we scroll, wait, scroll, wait, etc... | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| window.scrollTo(0, document.body.scrollHeight); | |
| setTimeout(function () { | |
| deletePost() | |
| }, 1000) | |
| }, 1000); | |
| }, 1000); | |
| }, 1000); | |
| }, 1000); | |
| } | |
| } |
So today a friend of mine asked me to make a script for him that does something similar to this. However my script is current with facebooks UI and deletes much more than this script did. I may or may not be releasing this yet, I'm not sure, but anyone who wants this sort of thing done to their account, feel free to contact me!
I imagine my script doesn't work anymore since it's been 7 years. Since you've written a better one, why not upload it to GitHub?
Well I'm currently trying to find ways to monitize the things I develop. Since my friend who put me on this informed me that similar things exist for this kind of task and that they are pay for options, I'm thinking about creating a software as a service system for this script and it's operations. There are some major technical hurdles to face with that, and I'm not sure if there is a substantial enough market for this that it would validate all the work it would take to build a secure system to give a paying user access to this script. I've done some research and it does seem possible on the technical side, but I am not sure that the work would pay off since I cant find much at all of people wanting something like this. So once again, I'm not sure if the market exists for this type of service.
I'm going to be performing some research into this and seeing if people would actually want something like this and would pay for it.
If it turns out that there's not really a market for it, I'll open source this and put it on GitHub.
I'm just at a point where I'm throwing stuff at the proverbial wall and seeing what sticks in the sense of trying to monitize the work I do to make ends meet.
I went to https://business.facebook.com/latest/posts/published_posts/ and ran the following script to delete all the posts on page, worked flawlessly.
/**
* Facebook Post Deleter - Modern 2026 Version
*
* Instructions:
* 1. Log in to Facebook and go to your "Manage Activity" page (Settings > Your Facebook Information > Activity Log > Manage Activity).
* Or go to your Profile and click "Manage Posts".
* 2. Paste this entire script into the Developer Console.
* 3. Run: await startDeletion()
* 4. To stop: Refresh the page.
*/
const DELAY = 3000; // Delay between actions in ms
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function findAndClick(selector, textContent = null) {
let elements = document.querySelectorAll(selector);
for (let el of elements) {
if (!textContent || el.textContent.includes(textContent)) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
el.style.border = "5px solid red";
await sleep(500);
el.click();
return true;
}
}
return false;
}
async function deleteNextPost() {
console.log("Looking for items to manage...");
// 1. Bulk Selection Mode
const bulkCheckboxes = Array.from(document.querySelectorAll('input[type="checkbox"][aria-label^="Check item"]:not([aria-checked="true"])'));
if (bulkCheckboxes.length > 0) {
const BATCH_SIZE = 100; // Increased to 100 as requested
const toSelect = bulkCheckboxes.slice(0, BATCH_SIZE);
console.log(`Selecting ${toSelect.length} items for this batch...`);
for (let cb of toSelect) {
if (cb.getAttribute('aria-checked') === 'true') continue;
cb.scrollIntoView({ behavior: 'smooth', block: 'center' });
cb.style.outline = "5px solid blue";
await sleep(100); // Faster selection for large batches
cb.click();
}
console.log("Batch selection complete. Looking for 'Actions' button...");
await sleep(2000);
// Find the "Actions" button based on provided HTML
const actionsBtn = Array.from(document.querySelectorAll('div[role="button"]')).find(btn =>
btn.textContent.trim().includes("Actions") && btn.offsetParent !== null
);
if (actionsBtn) {
console.log("Found 'Actions' button. Clicking...");
actionsBtn.style.border = "5px solid red";
await sleep(1000);
actionsBtn.click();
await sleep(1500); // Wait for menu to open
// Find "Delete posts" menu item
const deletePostsItem = Array.from(document.querySelectorAll('div[role="menuitem"]')).find(item =>
item.textContent.trim().includes("Delete posts") && item.offsetParent !== null
);
if (deletePostsItem) {
console.log("Found 'Delete posts' menu item. Clicking...");
deletePostsItem.click();
await sleep(2500); // Wait for confirmation modal
// Find "Move to trash" confirmation button
const moveToTrashBtn = Array.from(document.querySelectorAll('div[role="button"], button')).find(btn =>
btn.textContent.trim() === "Move to trash" && btn.offsetParent !== null
);
if (moveToTrashBtn) {
console.log("Found 'Move to trash' confirmation. Clicking...");
moveToTrashBtn.click();
console.log("Batch sent to trash. Waiting for refresh...");
await sleep(8000); // Long wait for 100 items to process
return true;
} else {
console.log("Could not find 'Move to trash' confirmation button. Please click it manually.");
return false;
}
} else {
console.log("Could not find 'Delete posts' in the Actions menu. Please click it manually.");
return false;
}
} else {
console.warn("Could not find the 'Actions' button. Stopping so you can click it manually.");
return false;
}
}
// 2. Individual Deletion Mode (Fallback)
const menuSelectors = [
'div[aria-label="Actions for this post"]',
'div[aria-label="More options"]',
'div[aria-label="Edit post"]',
'div[aria-label="Action options"]'
];
let foundMenu = false;
for (const sel of menuSelectors) {
if (await findAndClick(sel)) {
foundMenu = true;
break;
}
}
if (!foundMenu) {
console.log("No menu found, scrolling...");
window.scrollBy(0, 500);
return;
}
await sleep(1500); // Wait for menu to open
// 2. Look for "Move to Trash" or "Delete" in the menu
// FB usually shows "Move to trash" for profile posts
const options = ["Move to trash", "Delete post", "Delete", "Remove"];
let foundOption = false;
// Look for spans/divs containing these texts
const menuItems = document.querySelectorAll('div[role="menuitem"], span');
for (let item of menuItems) {
if (options.some(opt => item.textContent.includes(opt))) {
item.click();
foundOption = true;
break;
}
}
if (!foundOption) {
console.log("Could not find delete/trash option in menu.");
// Close menu by clicking elsewhere or hitting Escape
document.body.click();
return;
}
await sleep(1500); // Wait for confirmation dialog
// 3. Confirm the action
const confirmButtons = ["Move", "Delete", "Confirm", "Yes"];
const buttons = document.querySelectorAll('div[aria-label="Move"], div[aria-label="Delete"], div[role="button"], button');
for (let btn of buttons) {
if (confirmButtons.some(txt => btn.textContent === txt)) {
btn.click();
console.log("Post action confirmed.");
await sleep(DELAY);
return;
}
}
}
async function startDeletion() {
console.log("Starting Facebook Deleter...");
while (true) {
try {
const success = await deleteNextPost();
if (success === false) {
console.log("Script paused or finished. Please check the page.");
break;
}
await sleep(1000);
} catch (e) {
console.error("Error in deletion loop:", e);
await sleep(2000);
}
}
}
console.log("Script loaded. Run 'await startDeletion()' to begin.");
Enjoy.
So today a friend of mine asked me to make a script for him that does something similar to this. However my script is current with facebooks UI and deletes much more than this script did. I may or may not be releasing this yet, I'm not sure, but anyone who wants this sort of thing done to their account, feel free to contact me!