Greasy Fork

Greasy Fork is available in English.

Twitter cleanup

Remove user and topics to follow suggestions from Twitter

当前为 2022-10-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Twitter cleanup
// @version 1.3.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, removeWithoutFollowButton) {
  // console.log('***  Removing H=', e.getBoundingClientRect().height, ' ', e.innerText);
  let next = e.nextSibling;
  let nextH = next.getBoundingClientRect().height;
  if (next && nextH < 200) {
    if (removeWithoutFollowButton || next.innerText.match(/Follow/))
      RemoveFollowingThinElements(next, removeWithoutFollowButton);
    else {
      // console.log('Stop 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);
    }
    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;
    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);