// ==UserScript== // @name Twitter cleanup // @version 1.9.3 // @grant Sly_North // @description Remove user and topics to follow suggestions from Twitter // @author Sly_North // @match https://twitter.com/* // @match https://mobile.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 // @downloadURL 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 = ""; } // Tool to remove the "X follows Y" tweets and "See more" suggested topics. function RemoveSuggestedTweets(name, regex) {   let elts = Array.from(document.getElementsByTagName('article')).filter(e => e.innerText.match(regex));   if (elts.length > 0) {     console.log('- Found ', name, ' count=', elts.length);     for (let e of elts) {       console.log('  - ', e.innerText.substring(0, 40));       e.innerHTML = "";     }   } } function RemoveSuggestions() {   // Remove suggested people to follow   let elts = Array.from(document.getElementsByTagName('H2')).filter(  // Needs to be in screen for nextSibling to be defined.     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);     }   }   // Remove suggested topics   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) {     console.log('Found "', elts[0].innerText, '"');     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, '"');   }   // Remove tweets of people followed by one we follow   RemoveSuggestedTweets('X follows Y', / follows*\n/);   // Remove "See more" suggestions   RemoveSuggestedTweets('See more', /\nSee more\n/);   // Unfreeze scrolling (ie: in incognito after scrolling a bit)   if (document.documentElement.style.overflow) document.documentElement.style.overflow = "scroll";   let eltCred = document.getElementById('credential_picker_container');   if (eltCred && eltCred.getBoundingClientRect().width < 400) eltCred.style.display = "none";   // If the window is very small (like when watching a video in a small secondary window),   // remove the Twitter left column and top banner.   {     let elts = document.getElementsByTagName('header');     if (elts.length > 0) { const widthLimit = document.location.href === 'https://twitter.com/home' ? 1000 : 800;       const smallWindow = window.innerWidth < widthLimit;       elts[0].style.display = smallWindow ? "none" : "";       const primaryCol = document.querySelector('[data-testid="primaryColumn"]');       primaryCol.style.maxWidth = smallWindow ? null : '600px';       primaryCol.style.minWidth = smallWindow ? '100vw' : null;     }     var elt = document.querySelector('[aria-label="Home timeline"]');     if (elt) elt.firstChild.style.display = (window.innerHeight < 700) ? "none" : "";   }   setTimeout(RemoveSuggestions, 1000); } // Remove credential banner (in incognito windows) let bottomBanners = Array.from(document.getElementsByTagName('div'))     .filter(e => e.dataset.testid === 'BottomBar' ); if (bottomBanners.length > 0) bottomBanners[0].innerHTML = ''; let elt = document.getElementById('credential_picker_container'); if (elt) elt.innerHTML = ""; setTimeout(RemoveSuggestions, 1000); /* // Switch to the Following tab if (document.location.href === 'https://twitter.com/home') {   setTimeout(() => {   for (let e of document.getElementsByTagName('span')) {       if (e.innerText === 'Following') { e.click(); break;}     }   }, 500); } */