Automatically show more replies on Twitter (+ offensive replies)

6/1/2024, 1:49:37 AM

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Automatically show more replies on Twitter (+ offensive replies)
// @namespace   Violentmonkey Scripts
// @match       https://x.com/*
// @grant       none
// @version     1.1
// @author      minnieo
// @description 6/1/2024, 1:49:37 AM
// @license     MIT
// ==/UserScript==


// Function to check and click the 'Show more replies' button
function clickShowMoreRepliesButton() {
    // Find the button that contains a span with the text 'Show more replies'
    const buttons = document.querySelectorAll('button');
    buttons.forEach(button => {
        const span = button.querySelector('span');
        if (span && span.textContent === 'Show more replies') {
            button.click();
            console.log('Button "Show more replies" clicked!');
        }
    });
}

// REMOVE THESE LINES BELOW
function clickShowAdditionalRepliesButton() {
    // Find the div that contains a span with the text 'Show additional replies, including those that may contain offensive content'
    const divs = document.querySelectorAll('div');
    divs.forEach(div => {
        const span = div.querySelector('span');
        if (span && span.textContent === 'Show additional replies, including those that may contain offensive content') {
            // Find the button within the same div
            const button = div.querySelector('button');
            if (button) {
                button.click();
                console.log('Button "Show additional replies" clicked!');
            }
        }
    });
}
// REMOVE THESE LINES ABOVE


// Set up a MutationObserver to monitor changes in the DOM
const observer = new MutationObserver((mutationsList, observer) => {
    for (let mutation of mutationsList) {
        if (mutation.type === 'childList' || mutation.type === 'subtree') {
            clickShowMoreRepliesButton();
            clickShowAdditionalRepliesButton(); // REMOVE THIS LINE
        }
    }
});

// Start observing the entire document for changes
observer.observe(document.body, {
    childList: true,
    subtree: true
});

// Initial check in case the buttons are already present
clickShowMoreRepliesButton();
clickShowAdditionalRepliesButton(); // REMOVE THIS LINE