Twitter cleanup

Remove user and topics to follow suggestions from Twitter

目前為 2022-10-05 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Twitter cleanup
// @version 1.4
// @grant Sly_North
// @description Remove user and topics to follow suggestions from Twitter
// @author Sly_North
// @match https://twitter.com/*
// @namespace https://greasyfork.org/en/users/759669-sly-north
// @icon https://abs.twimg.com/responsive-web/client-web/icon-svg.168b89d8.svg
// @license MIT
// @grant none
// ==/UserScript==

function RemoveFollowingThinElements(e, removeWithoutFollowButton) {
  console.log('- removing H=', e.getBoundingClientRect().height, ' ', e.innerText);
  let next = e.nextSibling;
  if (next) {
 let nextH = next.getBoundingClientRect().height;
    if (nextH < 200) {
      if (removeWithoutFollowButton || next.innerText.match(/Follow/))
        RemoveFollowingThinElements(next, removeWithoutFollowButton);
      else {
        // console.log('- TWcleanup stops at H=', nextH, ' "' + next.innerText + '"');
        if (next.innerText === 'Show more') {
          next.innerHTML = "";
        }
      }
    }
  }
  e.innerHTML = "";
}

function RemoveSuggestions() {
  // Needs to be in screen for nextSibling to be defined.
let elts = Array.from(document.getElementsByTagName('H2')).filter(
    e => e.getBoundingClientRect().top < window.innerHeight &&
           e.innerText === 'Who to follow');
  if (elts.length > 0) {
    console.log('Found "Who to follow"');
    for (let e of elts) {
e = e.parentElement.parentElement.parentElement.parentElement;
      RemoveFollowingThinElements(e, false);
    }
  }

  elts = Array.from(document.getElementsByTagName('SPAN')).filter(
    e => // e.getBoundingClientRect().top < window.innerHeight &&
    (e.innerText === 'Topics to follow' || e.innerText === 'Expand your timeline with Topics'));
  if (elts.length > 0) {
    let title = e.innerText;
    console.log('Found "', title, '"');
    for (let e of elts) {
      e = e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
      // Remove topics and offset bar
      RemoveFollowingThinElements(e.nextSibling, true);
      // Remove title
      e.innerHTML = "";
    }
    console.log('Removed "', title, '"');
  }

setTimeout(RemoveSuggestions, 1000);
}

setTimeout(RemoveSuggestions, 1000);

// If the window is very small (like when watching a video in a small secondary window),
// remove the Twitter left column and top banner.
if (window.innerWidth < 700 && window.innerHeight < 700) setTimeout(function() {
  console.log('ici');
  let elts = document.getElementsByTagName('header');
  console.log('side header count=', elts.length);
  if (elts.length > 0) {
    elts[0].style.display = "none";
  }
  var elt = document.querySelector('[aria-label="Home timeline"]');
  if (elt) elt.firstChild.style.display = "none";
}, 500);