Unblock All Users on Twitter

Unblock all users on the blocked users page with a button, preload, and autoscroll

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Unblock All Users on Twitter
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Unblock all users on the blocked users page with a button, preload, and autoscroll
// @author       Doxie
// @match        https://x.com/settings/blocked/all
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Add a large button in the middle of the page
    const button = document.createElement('button');
    button.innerText = 'Unblock All Users';
    button.style.position = 'fixed';
    button.style.top = '50%';
    button.style.left = '50%';
    button.style.transform = 'translate(-50%, -50%)';
    button.style.padding = '20px';
    button.style.fontSize = '20px';
    button.style.zIndex = '1000';
    button.style.backgroundColor = '#4CAF50';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '10px';
    button.style.cursor = 'pointer';
    document.body.appendChild(button);

    async function preloadBlockedUsers() {
        return new Promise((resolve) => {
            let lastScrollHeight = 0;
            let scrollInterval = setInterval(() => {
                window.scrollBy(0, window.innerHeight);
                if (document.documentElement.scrollHeight !== lastScrollHeight) {
                    lastScrollHeight = document.documentElement.scrollHeight;
                } else {
                    clearInterval(scrollInterval);
                    resolve();
                }
            }, 1000);
        });
    }

    async function unblockAllUsers() {
        function getBlockedContainers() {
            return Array.from(document.querySelectorAll('div')).filter(div => div.innerText.includes('Blocked'));
        }

        function getUnblockButtonFromContainer(container) {
            return container.closest('div').querySelector('button');
        }

        let blockedContainers = getBlockedContainers();
        while (blockedContainers.length > 0) {
            blockedContainers.forEach(container => {
                let unblockButton = getUnblockButtonFromContainer(container);
                if (unblockButton) {
                    unblockButton.click();
                }
            });
            await new Promise(resolve => setTimeout(resolve, 1000)); // wait 1 second to avoid rate limiting
            blockedContainers = getBlockedContainers();
        }
        console.log('All users have been unblocked.');
    }

    button.addEventListener('click', async () => {
        button.remove(); // Remove the button after clicking
        await preloadBlockedUsers(); // Scroll to load all blocked users
        await unblockAllUsers(); // Start unblocking users
    });
})();