Greasy Fork

Greasy Fork is available in English.

Twitter cleanup

Remove user and topics to follow suggestions from Twitter

当前为 2022-09-29 提交的版本,查看 最新版本

// ==UserScript==
// @name Twitter cleanup
// @version 1.1
// @grant Sly_North
// @description Remove user and topics to follow suggestions from Twitter
// @author Sly_North
// @match https://twitter.com/*
// @namespace http://greasyfork.icu/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) {
  let next = e.nextSibling;
  if (next && next.getBoundingClientRect().height < 200) RemoveFollowingThinElements(next);
  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);
    }
    console.log('Removed "Who to follow"');
  }

  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;
    for (let e of elts) {
      e = e.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
      // Remove topics and offset bar
      RemoveFollowingThinElements(e.nextSibling);
      // Remove title
      e.innerHTML = "";
    }
    console.log('Removed "', title, '"');
  }

  // Login banner
  let elt = document.getElementById('layers');
  if (elt) elt.style.display = "none" ;

	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);