Skip to content

Instantly share code, notes, and snippets.

@z0rs
Created January 16, 2025 10:04
Show Gist options
  • Save z0rs/95dfd51a13d828d57d9d4c59786adf52 to your computer and use it in GitHub Desktop.
Save z0rs/95dfd51a13d828d57d9d4c59786adf52 to your computer and use it in GitHub Desktop.
(async function () {
    const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

    async function scrollToLoadMore() {
        console.log("Scrolling to load more replies...");
        window.scrollTo(0, document.body.scrollHeight); // Scroll ke bawah
        await delay(2000);
    }

    async function clickMuteButton() {
        let accountsMuted = 0;
        const replies = document.querySelectorAll('[data-testid="tweet"]');

        for (const reply of replies) {
            const blueCheck = reply.querySelector('svg[aria-label="Verified account"]');
            const replyText = reply.querySelector('[data-testid="tweetText"]')?.textContent || '';
            const isShortReply = replyText.split(' ').length <= 5; // Cek apakah reply pendek

            if (blueCheck || isShortReply) {
                const moreOptionsButton = reply.querySelector('[aria-label="More"]');
                if (moreOptionsButton) {
                    moreOptionsButton.click();
                    await delay(500);

                    const muteButton = Array.from(document.querySelectorAll('[role="menuitem"]'))
                        .find(item => item.textContent.includes('Mute'));
                    if (muteButton) {
                        muteButton.click();
                        console.log(`Muted an account${blueCheck ? ' (blue check)' : ''}${isShortReply ? ' (short reply)' : ''}!`);
                        accountsMuted++;
                        await delay(1000);
                    }
                }
            }
        }
        return accountsMuted;
    }

    async function processRepliesUntilDone() {
        let totalMuted = 0;
        let retries = 0;

        while (retries < 10) {
            console.log(`Scanning... Attempt ${retries + 1}`);
            const accountsMuted = await clickMuteButton();
            totalMuted += accountsMuted;

            if (accountsMuted === 0) {
                retries++;
                console.log("No new accounts found. Scrolling to load more replies...");
                await scrollToLoadMore();
            } else {
                retries = 0;
            }

            if (retries >= 10) {
                console.log("No more replies to process. Stopping...");
                break;
            }
        }

        console.log(`Finished processing. Total accounts muted: ${totalMuted}`);
    }

    console.log("Starting script to mute all blue check accounts and short replies...");
    await processRepliesUntilDone();
    console.log("Script finished.");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment