Full Width Tweets for Twitter

Display Tweets in Full-Width

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           Full Width Tweets for Twitter
// @namespace      Violentmonkey Scripts
// @match          https://x.com/*
// @match          https://twitter.com/*
// @grant          none
// @version        1.01
// @author         Yukiteru
// @description    Display Tweets in Full-Width
// @license        MIT
// ==/UserScript==


(function() {
  'use strict';

  function applyLayoutStyles() {
    const sidebar = document.querySelector('[data-testid="sidebarColumn"]');
    const primaryColumn = document.querySelector('[data-testid="primaryColumn"]');
    const innerContainer = document.querySelector('main section[role="region"]')?.parentNode;

    sidebar.style.display = 'none';
    primaryColumn.style.maxWidth = 'none';

    if (innerContainer) {
      innerContainer.style.maxWidth = 'none';
      innerContainer.style.marginRight = '0';
    }
  }

  let oldPostCount = 0;
  let postsChecked = false;

  function getPostList() {
    const postList = document.querySelectorAll('main section article');
    return postList;
  }

  function applyButtonStyles() {
    const postList = getPostList();
    postList.forEach(post => {
      const buttonGroup = post.querySelector('div[role="group"]');
      buttonGroup.style.minWidth = '100%';
    })
  }

  function updatePosts() {
    const postCount = getPostList().length;
    if (postCount === oldPostCount) return;
    oldPostCount = postCount;
    applyButtonStyles();
  }

  const observer = new MutationObserver((mutationsList, observer) => {
    const primaryColumn = document.querySelector('[data-testid="primaryColumn"]');
    if (primaryColumn) applyLayoutStyles()
    if (!postsChecked && document.querySelector('main section article')) {
      updatePosts();
      postsChecked = true;
    }
  });

  document.addEventListener('scroll', () => updatePosts());
  observer.observe(document.body, { childList: true, subtree: true });
})();