X Block List Counter

Counts the number of accounts in your X block list, handling pagination

02.05.2025 itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name         X Block List Counter
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Counts the number of accounts in your X block list, handling pagination
// @author       adamlproductions
// @match        https://x.com/settings/blocked/all
// @grant        none
// @license      MIT
// ==/UserScript==
// jshint        esversion: 8

(function() {
    'use strict';

    async function countBlockedAccounts() {
        let blockedCount = 0;
        let seenUserIds = new Set();
        let lastHeight = document.body.scrollHeight;
        let noNewContentCount = 0;

        const counterDiv = document.createElement('div');
        counterDiv.style.position = 'fixed';
        counterDiv.style.top = '10px';
        counterDiv.style.right = '10px';
        counterDiv.style.background = '#000000';
        counterDiv.style.color = '#FFFFFF';
        counterDiv.style.padding = '10px';
        counterDiv.style.border = '1px solid #000';
        counterDiv.style.zIndex = '1000';
        counterDiv.innerText = 'Counting blocked accounts...';
        document.body.appendChild(counterDiv);

        while (noNewContentCount < 3) {
            const blockedAccounts = document.querySelectorAll('div[data-testid="cellInnerDiv"]');

            for (const account of blockedAccounts) {
                const userLink = account.querySelector('a[href*="/"]');
                const userId = userLink ? userLink.getAttribute('href') : null;
                if (userId && !seenUserIds.has(userId)) {
                    seenUserIds.add(userId);
                    blockedCount++;
                }
            }

            counterDiv.innerText = `Blocked accounts: ${blockedCount}`;

            window.scrollTo(0, document.body.scrollHeight);
            await new Promise(resolve => setTimeout(resolve, 1500));

            const newHeight = document.body.scrollHeight;
            if (newHeight === lastHeight) {
                noNewContentCount++;
            } else {
                noNewContentCount = 0;
            }
            lastHeight = newHeight;
        }

        counterDiv.innerText = `Total blocked accounts: ${blockedCount}`;
        console.log(`Total blocked accounts: ${blockedCount}`);
    }

    window.addEventListener('load', () => {
        countBlockedAccounts().catch(error => {
            console.error('Error counting blocked accounts:', error);
            const errorDiv = document.createElement('div');
            errorDiv.style.position = 'fixed';
            errorDiv.style.top = '50px';
            errorDiv.style.right = '10px';
            errorDiv.style.background = '#000000';
            errorDiv.style.color = '#FFFFFF';
            errorDiv.style.padding = '10px';
            errorDiv.style.border = '1px solid #f00';
            errorDiv.style.zIndex = '1000';
            errorDiv.innerText = 'Error counting blocked accounts. Check console for details.';
            document.body.appendChild(errorDiv);
        });
    });
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。