Greasy Fork

Greasy Fork is available in English.

Facebook Activity Auto Deleter (2025)

Automatically deletes Facebook activity log entries, confirms popups, and scrolls to load more. Includes a toggle to pause/resume, and handles "Something went wrong" errors gracefully.

当前为 2025-04-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Facebook Activity Auto Deleter (2025)
// @namespace    http://greasyfork.icu/en/users/1454546-shawnfrost13
// @version      3.92
// @description  Automatically deletes Facebook activity log entries, confirms popups, and scrolls to load more. Includes a toggle to pause/resume, and handles "Something went wrong" errors gracefully.
// @author       shawnfrost13
// @license      MIT
// @match        https://www.facebook.com/*/allactivity*
// @grant        none
// @run-at       document-end
// @note         Keep the tab active and non-discarded while running. Reload if FB glitches.
// ==/UserScript==

(function () {
    'use strict';

    console.log("🔥 FB Auto Deleter 3.92 started");

    let deletionCount = 0;
    let paused = true;
    let skipCurrent = 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 createToggleUI() {
        const toggle = document.createElement('div');
        toggle.id = 'fb-toggle-button';
        toggle.style.position = 'fixed';
        toggle.style.bottom = '65px';
        toggle.style.right = '10px';
        toggle.style.background = '#222';
        toggle.style.color = 'white';
        toggle.style.padding = '8px 12px';
        toggle.style.borderRadius = '8px';
        toggle.style.cursor = 'pointer';
        toggle.style.fontFamily = 'monospace';
        toggle.style.zIndex = '9999';
        toggle.textContent = '▶️ Start';

        toggle.addEventListener('click', () => {
            paused = !paused;
            toggle.textContent = paused ? '▶️ Start' : '⏸️ Pause';
            if (!paused) {
                deleteNext();
            }
        });

        const skip = document.createElement('div');
        skip.id = 'fb-skip-button';
        skip.style.position = 'fixed';
        skip.style.bottom = '100px';
        skip.style.right = '10px';
        skip.style.background = '#444';
        skip.style.color = 'white';
        skip.style.padding = '6px 10px';
        skip.style.borderRadius = '6px';
        skip.style.cursor = 'pointer';
        skip.style.fontFamily = 'monospace';
        skip.style.zIndex = '9999';
        skip.textContent = '⏭️ Skip Current';

        skip.addEventListener('click', () => {
            skipCurrent = true;
        });

        document.body.appendChild(toggle);
        document.body.appendChild(skip);
    }

    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 autoScrollAndRetry() {
        console.log("🔄 Scrolling to load more activity...");
        logStatus("Scrolling to load more items...");

        window.scrollTo({
            top: document.body.scrollHeight,
            behavior: 'smooth'
        });

        setTimeout(() => {
            deleteNext();
        }, 2500);
    }

    function deleteNext() {
        if (paused) return;

        autoConfirmPopups();

        const buttons = findMenuButtons();

        if (buttons.length === 0) {
            logStatus('No deletable buttons found. Trying to scroll...');
            autoScrollAndRetry();
            return;
        }

        const btn = buttons[0];
        btn.scrollIntoView({ behavior: 'smooth', block: 'center' });
        btn.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 (skipCurrent) {
                skipCurrent = false;
                logStatus("⏭️ Skipped current item");
                console.log("⏭️ Skipped current item by user request");
                setTimeout(deleteNext, getRandomDelay());
                return;
            }

            if (deleteOption) {
                deleteOption.click();
                console.log("🗑️ Clicked delete option, waiting for confirmation...");

                setTimeout(() => {
                    const errorPopup = document.querySelector('[role="alert"]');
                    if (errorPopup && errorPopup.textContent.includes("Something went wrong")) {
                        logStatus("❌ Deletion failed. Skipping...");
                        console.log("❌ Detected error popup. Skipping this item...");
                        setTimeout(deleteNext, getRandomDelay());
                    } else {
                        deletionCount++;
                        logStatus(`✅ Deleted item #${deletionCount}`);
                        console.log(`✅ Successfully deleted item #${deletionCount}`);
                        setTimeout(deleteNext, getRandomDelay());
                    }
                }, 1500);
            } else {
                logStatus(`⚠️ No delete option. Skipping.`);
                console.log("⚠️ No delete/remove option found. Skipping...");
                setTimeout(deleteNext, getRandomDelay());
            }
        }, 1500);
    }

    // Init
    setTimeout(() => {
        createToggleUI();
        setInterval(autoConfirmPopups, 1000);
    }, 2000);
})();