Skip to content

Instantly share code, notes, and snippets.

@bhuiyanmobasshir94
Created February 15, 2026 08:10
Show Gist options
  • Select an option

  • Save bhuiyanmobasshir94/1b4ac4b659b93d4f5fe856f245a19147 to your computer and use it in GitHub Desktop.

Select an option

Save bhuiyanmobasshir94/1b4ac4b659b93d4f5fe856f245a19147 to your computer and use it in GitHub Desktop.
// Delete 30 Facebook posts - Updated with proper confirmation
(async function deleteFBPosts() {
const POSTS_TO_DELETE = 30;
const CLICK_DELAY = 1500;
const MENU_DELAY = 2000;
const SCROLL_DELAY = 2000;
let deletedCount = 0;
let failedAttempts = 0;
console.log(`๐Ÿš€ Starting deletion of ${POSTS_TO_DELETE} posts...`);
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function scrollToLoadMore() {
window.scrollTo(0, document.body.scrollHeight);
await sleep(SCROLL_DELAY);
window.scrollTo(0, 0);
await sleep(SCROLL_DELAY);
}
async function deletePost() {
try {
// Find the action menu button using the exact aria-label
const actionButton = document.querySelector('[aria-label="Actions for this post"]');
if (!actionButton) {
console.log('โŒ No action button found');
return false;
}
console.log('โœ“ Found action button, clicking...');
actionButton.click();
await sleep(MENU_DELAY);
// Find the menu items - look for delete/trash option
const menuItems = Array.from(document.querySelectorAll('[role="menuitem"]'));
console.log(`Found ${menuItems.length} menu items`);
// Look for delete option (try different text variations)
const deleteItem = menuItems.find(item => {
const text = item.textContent.toLowerCase();
return text.includes('move to trash') ||
text.includes('delete') ||
text.includes('trash') ||
text.includes('เฆฎเงเฆ›เง‡ เฆซเง‡เฆฒเงเฆจ'); // Bengali
});
if (!deleteItem) {
console.log('โŒ Delete option not found. Available options:');
menuItems.forEach((item, i) => {
console.log(` ${i}: ${item.textContent.substring(0, 50)}`);
});
// Close menu
document.body.click();
await sleep(500);
return false;
}
console.log('โœ“ Found delete option, clicking...');
deleteItem.click();
await sleep(MENU_DELAY);
// Find and click confirmation button - Updated to look for "Move" button
console.log('Looking for confirmation button...');
// First try to find by aria-label
let confirmButton = document.querySelector('[aria-label="Move"][role="button"]');
// If not found, try finding by text content
if (!confirmButton) {
const allButtons = Array.from(document.querySelectorAll('[role="button"]'));
confirmButton = allButtons.find(btn => {
const text = btn.textContent.trim();
const ariaLabel = btn.getAttribute('aria-label');
const isVisible = btn.offsetParent !== null;
// Look for "Move" button (not "Cancel")
const isMove = (text === 'Move' || ariaLabel === 'Move') &&
!text.includes('Cancel') &&
!ariaLabel?.includes('Cancel');
return isVisible && isMove;
});
}
if (!confirmButton) {
console.log('โŒ Move/Confirm button not found');
console.log('Available buttons:');
document.querySelectorAll('[role="button"]').forEach((btn, i) => {
if (btn.offsetParent !== null) {
console.log(` ${i}: aria-label="${btn.getAttribute('aria-label')}", text="${btn.textContent.substring(0, 30)}"`);
}
});
return false;
}
console.log('โœ“ Confirming deletion (clicking Move button)...');
confirmButton.click();
await sleep(CLICK_DELAY);
return true;
} catch (error) {
console.error('โŒ Error:', error.message);
return false;
}
}
// Main loop
while (deletedCount < POSTS_TO_DELETE) {
console.log(`\nโ”โ”โ” Attempt ${deletedCount + 1}/${POSTS_TO_DELETE} โ”โ”โ”`);
const success = await deletePost();
if (success) {
deletedCount++;
failedAttempts = 0;
console.log(`โœ… Progress: ${deletedCount}/${POSTS_TO_DELETE} deleted`);
} else {
failedAttempts++;
console.log(`โš ๏ธ Failed attempt #${failedAttempts}`);
if (failedAttempts >= 3) {
console.log('๐Ÿ“œ Multiple failures, scrolling to load more posts...');
await scrollToLoadMore();
failedAttempts = 0;
}
}
// Scroll every 5 successful deletions
if (deletedCount > 0 && deletedCount % 5 === 0) {
console.log('๐Ÿ“œ Loading more posts...');
await scrollToLoadMore();
}
await sleep(CLICK_DELAY);
}
console.log(`\n๐ŸŽ‰ COMPLETED! Successfully deleted ${deletedCount} posts!`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment