Twitter: expand tweets automaticly

For Tweets which have the "show more" Button this Script will click this button automaticly & it will remove the lineclamp on quoted tweets

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter: expand tweets automaticly
// @version      0.1
// @description  For Tweets which have the "show more" Button this Script will click this button automaticly & it will remove the lineclamp on quoted tweets
// @author       Schubsi
// @license      MIT
// @match        https://twitter.com/*
// @match        https://x.com/*
// @namespace https://greasyfork.org/users/1493523
// ==/UserScript==

(function () {
  "use strict";

  const autoShowMore = (tweet) => {
    const showMoreBtn = tweet.querySelector(
      "button[data-testid='tweet-text-show-more-link']"
    );
    if (showMoreBtn) showMoreBtn.click();

    const quotedTweet = tweet.querySelector("div[id^='id__'][aria-labelledby^='id__']");
    if (!quotedTweet) return;
    const quotedText = quotedTweet.querySelector(
      "div[data-testid='tweetText']"
    );
    if (!quotedText) return;
    quotedText.style.removeProperty("-webkit-line-clamp");
  };

  const processTweets = () => {
    document.querySelectorAll("article").forEach((tweet) => {
      autoShowMore(tweet);
    });
  };

  const observer = new MutationObserver(() => {
    processTweets();
  });

  window.addEventListener("load", () => {
    processTweets();
    observer.observe(document.body, { childList: true, subtree: true });
  });
})();