Automatically show more replies on Twitter (+ offensive replies)

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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 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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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        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