jmcgover / unblock-all

A javascript script that unblocks all of a Twitter user's blocked Twitter accounts
MIT License
31 stars 20 forks source link

blocked-text class name no longer exists #7

Open vvuk opened 2 years ago

vvuk commented 2 years ago

the blocked-text class name is no longer used; however, replacing the getElementsByClassName with document.querySelectorAll('div[role="button"][aria-label="Blocked"]') seems to work. Twitter also no longer keeps all the elements on the page as you scroll, so it's necessary to unblock in a loop.

vvuk commented 2 years ago

Currently using

async function unblock(timeoutMs, maxScrolls) {
    var prevScrollY;
    var scrollY = window.scrollY;
    var numScrolls = 0;
    do {
        window.scrollTo(0,document.body.scrollHeight);
        numScrolls++;
        prevScrollY = scrollY;
        await sleep(timeoutMs);
        scrollY = window.scrollY;

        var unblockButtons = document.querySelectorAll('div[role="button"][aria-label="Blocked"]');
        clickAll(unblockButtons);
    } while((scrollY - prevScrollY) > 0 && (typeof maxScrolls === 'undefined' || numScrolls < maxScrolls));
}

(no confirmation)

AK47dev1 commented 2 years ago

Great! Works like a charm :) So the whole code is as follows:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

function clickAll(buttons) {
    for (i = 0; i < buttons.length; i++) {
        buttons[i].click();
    }
}

async function unblock(timeoutMs, maxScrolls) {
    var prevScrollY;
    var scrollY = window.scrollY;
    var numScrolls = 0;
    do {
        window.scrollTo(0,document.body.scrollHeight);
        numScrolls++;
        prevScrollY = scrollY;
        await sleep(timeoutMs);
        scrollY = window.scrollY;

        var unblockButtons = document.querySelectorAll('div[role="button"][aria-label="Blocked"]');
        clickAll(unblockButtons);
    } while((scrollY - prevScrollY) > 0 && (typeof maxScrolls === 'undefined' || numScrolls < maxScrolls));
}

function main() {
    unblock(500);
}

main()