Automatically show more replies on Twitter (+ offensive replies)

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

You will need to install an extension such as Tampermonkey, Greasemonkey 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 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.

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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