Twitter: view more replies and remove useless sections

View more replies and remove useless sections from twitter

目前為 2022-08-02 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          Twitter: view more replies and remove useless sections
// @description   View more replies and remove useless sections from twitter
// @author        MK
// @namespace     max44
// @homepage      https://greasyfork.org/en/users/309172-max44
// @match         *://twitter.com/*
// @match         *://mobile.twitter.com/*
// @icon          https://www.google.com/s2/favicons?domain=twitter.com
// @version       1.7.8
// @license       MIT
// @require       https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @grant         none
// @run-at        document-idle
// ==/UserScript==

(function () {
  'use strict';

  const config = {childList: true, subtree: true};

  const rootCallback = function (mutationsList, observer) {
//  setInterval(function() { //Check page content constantly
    //==== ENGLISH INTERFACE
    //Show more
    $( "div[role='button'][tabindex='0'] > div > div > div > span:contains('Show replies')" ).click(); //"Show replies" button
    $( "div[role='button'][tabindex='0'] > div > div > span:contains('Show more replies')" ).click(); //"Show more replies" button
    $( "div[role='button'][tabindex='0'] > div > span > span:contains('Show')" ).click(); //"Show additional replies, including those that may contain offensive content" button

    //Hide useless sections
    $( "aside[aria-label='Who to follow']" ).parent().hide(); //"Who to follow" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Who to follow')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Who to follow" - at anybody's profile
    $( "section[role='region'] > div[aria-label='Timeline: Trending now']" ).parent().parent().hide(); //"Trends for you" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('What's happening')" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //"What's happening" - at the newsfeed (right column)
    $( "div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Trends for you')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Trends for you" - at 'Explore' page
    $( "div > div > div > div > div > h1 > span:contains('You seem to be in a new location')" ).parent().parent().parent().parent().parent().parent().hide(); //"You seem to be in a new location" - at 'Explore' page
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Topics to follow')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Topics to follow" - at anybody's profile
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Suggested Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Suggested topics" - at 'More > Topics' page
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Discover new Lists')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Discover new Lists" - at 'Lists' page
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Expand your timeline with Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Expand your timeline with Topics" - at the newsfeed
    //$( "span[aria-label^='Recommended Topic:'] > span > span" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //At the newsfeed
    $( "div[aria-label='Open app']" ).parent().hide(); //"Open app" - at any tweet on mobile browser
    $( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Concerned about your digital security?')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Digital security" - at the newsfeed
    $( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Get the app')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Get the app" - at the newsfeed
//    $( "article span:contains('Promoted')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide(); //"Promoted" - at ?, active for some regions only
//    $( "span:contains('Promoted by')" ).parent().parent().parent().parent().hide().next().hide().next().hide(); //"Promoted by" - at ?, active for some regions only
//    $( "span:contains('Promoted Tweet')" ).parent().parent().parent().hide(); //"Promoted Tweet" - at ?, active for some regions only
//    $( "span:contains('Promoted')" ).parent().parent().parent().parent().hide(); //"Promoted" - at ?, active for some regions only
//    $( "div[aria-label='Set as not interested']" ).parent().parent().parent().parent().parent().parent().parent().hide(); //"Set as non-interested" - at ?, active for some regions only

    //==== UKRAINIAN INTERFACE
    //Show more
    $( "div[role='button'][tabindex='0'] > div > div > div > span:contains('Показати відповіді')" ).click(); //"Show replies" button
    $( "div[role='button'][tabindex='0'] > div > div > span:contains('Показати більше відповідей')" ).click(); //"Show more replies" button
    $( "div[role='button'][tabindex='0'] > div > span > span:contains('Показати')" ).click(); //"Show additional replies, including those that may contain offensive content" button

    //Hide useless sections
    $( "aside[aria-label='Рекомендовані']" ).parent().hide(); //"Who to follow" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Рекомендації')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Who to follow" - at anybody's profile
    $( "section[role='region'] > div[aria-label='Стрічка: Актуальне зараз']" ).parent().parent().hide(); //"Trends for you" - at the newsfeed (right column)
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('What's happening')" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //"What's happening" - at the newsfeed (right column)
    $( "div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Тренди для вас')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Trends for you" - at 'Explore' page
    $( "div > div > div > div > div > h1 > span:contains('Схоже, ви перебуваєте в новому місці')" ).parent().parent().parent().parent().parent().parent().hide(); //"You seem to be in a new location" - at 'Explore' page
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Topics to follow')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Topics to follow" - at anybody's profile
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Suggested Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Suggested topics" - at 'More > Topics' page
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Discover new Lists')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //At the newsfeed
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Expand your timeline with Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Expand your timeline with Topics" - at the newsfeed
    //$( "span[aria-label^='Recommended Topic:'] > span > span" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //At the newsfeed
    $( "div[aria-label='Відкрити додаток']" ).parent().hide(); //"Open app" - at any tweet on mobile browser
    $( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Є сумніви щодо цифрової безпеки?')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Digital security" - at the newsfeed
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Get the app')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Get the app" - at the newsfeed

    //==== CHINEESE SIMPLIFIED INTERFACE
    //Show more
    $( "div[role='button'][tabindex='0'] > div > div > div > span:contains('显示回复')" ).click(); //"Show replies" button
    $( "div[role='button'][tabindex='0'] > div > div > span:contains('显示更多回复')" ).click(); //"Show more replies" button
    $( "div[role='button'][tabindex='0'] > div > span > span:contains('显示')" ).click(); //"Show additional replies, including those that may contain offensive content" button

    //Hide useless sections
    $( "aside[aria-label='推荐关注']" ).parent().hide(); //"Who to follow" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('推荐关注')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Who to follow" - at anybody's profile
    $( "section[role='region'] > div[aria-label='Timeline: Trending now']" ).parent().parent().hide(); //"Trends for you" - at the newsfeed (right column)
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('What's happening')" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //"What's happening" - at the newsfeed (right column)
    $( "div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('你的趋势')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Trends for you" - at 'Explore' page
    $( "div > div > div > div > div > h1 > span:contains('你似乎到了一个新位置')" ).parent().parent().parent().parent().parent().parent().hide(); //"You seem to be in a new location" - at 'Explore' page
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Topics to follow')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Topics to follow" - at anybody's profile
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Suggested Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Suggested topics" - at 'More > Topics' page
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Discover new Lists')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //At the newsfeed
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Expand your timeline with Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Expand your timeline with Topics" - at the newsfeed
    //$( "span[aria-label^='Recommended Topic:'] > span > span" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //At the newsfeed
    $( "div[aria-label='打开应用']" ).parent().hide(); //"Open app" - at any tweet on mobile browser
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Concerned about your digital security?')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Digital security" - at the newsfeed
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Get the app')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Get the app" - at the newsfeed

    //==== CHINEESE TRADITIONAL INTERFACE
    //Show more
    $( "div[role='button'][tabindex='0'] > div > div > div > span:contains('顯示回覆')" ).click(); //"Show replies" button
    $( "div[role='button'][tabindex='0'] > div > div > span:contains('顯示更多回覆')" ).click(); //"Show more replies" button
    $( "div[role='button'][tabindex='0'] > div > span > span:contains('顯示')" ).click(); //"Show additional replies, including those that may contain offensive content" button

    //Hide useless sections
    $( "aside[aria-label='跟隨誰']" ).parent().hide(); //"Who to follow" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('跟隨誰')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Who to follow" - at anybody's profile
    $( "section[role='region'] > div[aria-label='時間軸:流行趨勢']" ).parent().parent().hide(); //"Trends for you" - at the newsfeed (right column)
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('What's happening')" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //"What's happening" - at the newsfeed (right column)
    $( "div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('你的流行趨勢')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Trends for you" - at 'Explore' page
    $( "div > div > div > div > div > h1 > span:contains('你似乎位於新的位置')" ).parent().parent().parent().parent().parent().parent().hide(); //"You seem to be in a new location" - at 'Explore' page
    //$( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Topics to follow')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Topics to follow" - at anybody's profile
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Suggested Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Suggested topics" - at 'More > Topics' page
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Discover new Lists')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //At the newsfeed
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Expand your timeline with Topics')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Expand your timeline with Topics" - at the newsfeed
    //$( "span[aria-label^='Recommended Topic:'] > span > span" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //At the newsfeed
    $( "div[aria-label='開啟應用程式']" ).parent().hide(); //"Open app" - at any tweet on mobile browser
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Concerned about your digital security?')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Digital security" - at the newsfeed
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Get the app')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Get the app" - at the newsfeed

    //==== SPANISH INTERFACE
    //Show more
    $( "div[role='button'][tabindex='0'] > div > div > div > span:contains('Mostrar respuestas')" ).click(); //"Show replies" button
    $( "div[role='button'][tabindex='0'] > div > div > span:contains('Mostrar más respuestas')" ).click(); //"Show more replies" button
    $( "div[role='button'][tabindex='0'] > div > span > span:contains('Mostrar')" ).click(); //"Show additional replies, including those that may contain offensive content" button

    //Hide useless sections
    $( "aside[aria-label='A quién seguir']" ).parent().hide(); //"Who to follow" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('A quién seguir')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Who to follow" - at anybody's profile
    $( "section[role='region'] > div[aria-label='Cronología: Tendencias del momento']" ).parent().parent().hide(); //"Trends for you" - at the newsfeed (right column)
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Qué está pasando')" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //"What's happening" - at the newsfeed (right column)
    $( "div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Tendencias para ti')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Trends for you" - at 'Explore' page
    $( "div > div > div > div > div > h1 > span:contains('Parece que estás en una nueva ubicación')" ).parent().parent().parent().parent().parent().parent().hide(); //"You seem to be in a new location" - at 'Explore' page
    $( "div > div > h2 > div[style='-webkit-line-clamp: 3;'] > span:contains('Temas para seguir')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Topics to follow" - at anybody's profile
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Temas sugeridos')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Suggested topics" - at 'More > Topics' page
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Descubre Listas nuevas')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //"Discover new Lists" - at 'Lists' page
    $( "div[style='-webkit-line-clamp: 3;'] > span:contains('Amplía tu cronología con Temas')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide().next().hide().next().hide(); //At the newsfeed
    //$( "div[style='-webkit-line-clamp: 3;'] > span:contains('Amplía tu cronología con Temas')" ).parent().parent().parent().parent().parent().parent().hide().next().hide().next().hide().next().hide(); //"Expand your timeline with Topics" - at the newsfeed
    //$( "span[aria-label^='Recommended Topic:'] > span > span" ).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().hide(); //At the newsfeed
    $( "div[aria-label='Abrir aplicación']" ).parent().hide(); //"Open app" - at any tweet on mobile browser
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Concerned about your digital security?')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Digital security" - at the newsfeed
    //$( "div[data-testid='inlinePrompt'] > h1[role='heading'] > span > span > span:contains('Get the app')" ).parent().parent().parent().parent().parent().parent().parent().hide().next().hide(); //"Get the app" - at the newsfeed
    $( "article span:contains('Promocionado')" ).parent().parent().parent().parent().parent().hide().next().hide().next().hide(); //"Promoted" - at ?, active for some regions only
    //$( "span:contains('Promoted by')" ).parent().parent().parent().parent().hide().next().hide().next().hide(); //"Promoted by" - at ?, active for some regions only
    $( "span:contains('Tweet promocionado')" ).parent().parent().parent().hide(); //"Promoted Tweet" - at ?, active for some regions only
    $( "span:contains('Promocionado')" ).parent().parent().parent().parent().hide(); //"Promoted" - at ?, active for some regions only
    //$( "div[aria-label='Set as not interested']" ).parent().parent().parent().parent().parent().parent().parent().hide(); //"Set as non-interested" - at ?, active for some regions only

//  }, 100); //Interval to check page content
  };

  const rootNode = document.querySelector("#react-root");
  if (rootNode != null) {
    const rootObserver = new MutationObserver(rootCallback);
    rootObserver.observe(rootNode, config);
  }

})();