twitter text comments only

Twitter script to curate and display only text comments that are relevant and meaningful, filtering out unrelated memes and nonsensical content.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         twitter text comments only
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Twitter script to curate and display only text comments that are relevant and meaningful, filtering out unrelated memes and nonsensical content.
// @author       You
// @match https://twitter.com/*/status/*

// ==/UserScript==

(function () {
    'use strict';
    function injectCss() {
        // Create a <style> element
        var styleElement = document.createElement('style');
        styleElement.id = "text-comments-only";
        // Define your CSS rules
        var cssCode = `
            [data-testid="cellInnerDiv"]:nth-child(1) {
            display: unset !important;
            }
        `;
        // Add your CSS rules to the <style> element
        styleElement.textContent = cssCode;
        document.head.appendChild(styleElement);
    }


    // Select the node that will be observed for mutations
    const targetNode = document.body;

    // Options for the observer (which mutations to observe)
    const config = { attributes: true, childList: true, subtree: true };

    // Create an observer instance linked to the callback
    const observer = new MutationObserver(callback);

    // Start observing the target node for configured mutations
    observer.observe(targetNode, config);

    // Callback function to execute when mutations are observed
    function callback(mutationList) {
        for (const mutation of mutationList) {
            const isNewNodeAdded = mutation.addedNodes && mutation.addedNodes?.length > 0;
            const isStyleInjected = document.getElementById("text-comments-only");

            if (isNewNodeAdded && /^https?:\/\/(www\.)?twitter\.com\/.*\/status\/\d{19}$/.test(location.href)) {
                const node = mutation.addedNodes[0];
                if (node.classList?.length > 0) {
                    const tweetPosts = document.querySelectorAll(`.${node.classList[0]} [data-testid="cellInnerDiv"]:not([textonly])`)
                    if (tweetPosts.length > 0) {
                        tweetPosts.forEach(el => {
                            const isValidVideo = el.querySelectorAll('[aria-label="Embedded video"]').length > 0;
                            const isValidImg = el.querySelectorAll('[alt="Image"]').length > 0;
                            const isValidGif = el.querySelectorAll('[aria-label="Play this GIF"]').length > 0;

                            if (isValidVideo) {
                                el.style.display = "none";
                                el.setAttribute("textonly", "true");
                                return;
                            }
                            if (isValidImg) {
                                el.style.display = "none";
                                el.setAttribute("textonly", "true");
                                return;
                            }
                            if (isValidGif) {
                                el.style.display = "none";
                                el.setAttribute("textonly", "true");
                                return;
                            }
                        })
                    }
                }

                if (!isStyleInjected) {
                    // Append the <style> element to the <head> of the document
                    injectCss();
                }
                
            }
            
        }
    };
})();