Greasy Fork is available in English.
Automatically deletes Facebook activity log entries, handles popups, confirms deletions, skips after repeated failures, and scrolls to load more.
当前为
// ==UserScript==
// @name Facebook Activity Auto Deleter (2025)
// @namespace http://greasyfork.icu/en/users/1454546-shawnfrost13
// @version 4.04
// @description Automatically deletes Facebook activity log entries, handles popups, confirms deletions, skips after repeated failures, and scrolls to load more.
// @author shawnfrost13
// @license MIT
// @match https://www.facebook.com/*/allactivity*
// @grant none
// @run-at document-end
// @note Script starts paused. Click toggle to run. Make sure the tab is not discarded. Reload if things break.
// ==/UserScript==
(function () {
'use strict';
let deletionCount = 0;
let isPaused = true;
let failureMap = new WeakMap();
let skipNext = false;
function getRandomDelay(min = 1100, max = 2100) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function logStatus(text) {
let el = document.getElementById('fb-auto-delete-status');
if (!el) {
el = document.createElement('div');
el.id = 'fb-auto-delete-status';
el.style.position = 'fixed';
el.style.bottom = '10px';
el.style.right = '10px';
el.style.background = '#111';
el.style.color = 'lime';
el.style.padding = '10px';
el.style.borderRadius = '10px';
el.style.fontFamily = 'monospace';
el.style.zIndex = '9999';
document.body.appendChild(el);
}
el.textContent = `🧹 ${text}`;
}
function createToggleButton() {
const btn = document.createElement('button');
btn.id = 'fb-toggle-btn';
btn.textContent = '▶️ Start Auto Delete';
btn.style.position = 'fixed';
btn.style.bottom = '60px';
btn.style.right = '10px';
btn.style.zIndex = '10000';
btn.style.padding = '10px 15px';
btn.style.borderRadius = '10px';
btn.style.border = 'none';
btn.style.background = '#333';
btn.style.color = 'white';
btn.style.cursor = 'pointer';
btn.style.fontFamily = 'monospace';
btn.onclick = () => {
isPaused = !isPaused;
btn.textContent = isPaused ? '▶️ Start Auto Delete' : '⏸️ Pause Auto Delete';
if (!isPaused) {
deleteNext();
}
};
document.body.appendChild(btn);
}
function findMenuButtons() {
return Array.from(document.querySelectorAll('[role="button"]')).filter(btn => {
const label = btn.getAttribute('aria-label') || '';
return (
btn.offsetParent !== null &&
(label.toLowerCase().includes("activity options") ||
label.toLowerCase().includes("action options"))
);
});
}
function autoConfirmPopups() {
const dialogs = Array.from(document.querySelectorAll('[role="dialog"], [role="alertdialog"]'));
dialogs.forEach(dialog => {
const deleteBtn = Array.from(dialog.querySelectorAll('div[role="button"], button')).find(btn =>
btn.offsetParent !== null &&
btn.innerText.trim().toLowerCase() === "delete"
);
if (deleteBtn) {
console.log("✅ Auto-confirming DELETE dialog");
deleteBtn.click();
logStatus("Auto-confirmed delete popup");
}
});
}
function handleErrorPopup() {
const errorPopup = Array.from(document.querySelectorAll('[role="alert"]')).find(el =>
el.textContent.includes("Something went wrong. Please try again.")
);
if (errorPopup) {
console.log("⚠️ Detected Facebook error popup");
logStatus("❌ Detected Facebook error popup");
const closeBtn = errorPopup.querySelector('[aria-label="Close"], [aria-label="Dismiss"]');
if (closeBtn) closeBtn.click();
return true;
}
return false;
}
function autoScrollAndRetry() {
console.log("🔄 Scrolling to load more activity...");
logStatus("Scrolling to load more items...");
window.scrollTo({
top: document.body.scrollHeight,
behavior: 'smooth'
});
setTimeout(() => {
if (!isPaused) deleteNext();
}, 2500);
}
function deleteNext() {
if (isPaused) return;
autoConfirmPopups();
if (handleErrorPopup()) {
// Handle failure state
const failedBtns = findMenuButtons();
if (failedBtns.length > 0) {
const failed = failedBtns[0];
let fails = failureMap.get(failed) || 0;
fails += 1;
failureMap.set(failed, fails);
if (fails >= 2) {
skipNext = true;
logStatus("⚠️ Skipping next entry due to repeated failure");
console.log("⚠️ Skipping next entry due to repeated failure");
}
}
setTimeout(deleteNext, getRandomDelay());
return;
}
const buttons = findMenuButtons();
if (buttons.length === 0) {
logStatus('No deletable buttons found. Trying to scroll...');
autoScrollAndRetry();
return;
}
const targetBtn = skipNext ? buttons[1] : buttons[0];
if (!targetBtn) {
logStatus("⚠️ Nothing to delete. Retrying...");
setTimeout(deleteNext, getRandomDelay());
return;
}
skipNext = false;
targetBtn.scrollIntoView({ behavior: 'smooth', block: 'center' });
targetBtn.click();
logStatus(`Opened menu for item #${deletionCount + 1}`);
console.log(`📂 Opened menu for item #${deletionCount + 1}`);
setTimeout(() => {
const menuItems = Array.from(document.querySelectorAll('[role="menuitem"]'));
const deleteOption = menuItems.find(el =>
el.innerText.includes("Move to Recycle bin") ||
el.innerText.includes("Delete") ||
el.innerText.includes("Remove") ||
el.innerText.includes("Unlike") ||
el.innerText.includes("Remove reaction") ||
el.innerText.includes("Remove tag")
);
if (deleteOption) {
deleteOption.click();
deletionCount++;
logStatus(`🗑️ Deleted item #${deletionCount}`);
console.log(`🗑️ Deleted item #${deletionCount}`);
setTimeout(deleteNext, getRandomDelay());
} else {
logStatus("⚠️ No delete option found. Skipping...");
console.log("⚠️ No delete/remove option found. Skipping...");
setTimeout(deleteNext, getRandomDelay());
}
}, 1500);
}
window.addEventListener('load', () => {
createToggleButton();
logStatus("Script loaded and paused");
setInterval(autoConfirmPopups, 1000);
});
})();