Last active
March 13, 2023 07:58
-
-
Save webfussel/ee6299ba87a53beb6aa6a2aaeca256fe to your computer and use it in GitHub Desktop.
Remove Twittertrends and Sponsored Tweets/Follow Suggestions - Tampermonkey Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove Twittertrends and Sponsored Tweets/Follow Suggestions | |
// @namespace http://webfussel.de | |
// @version 1.5.1 | |
// @description Remove those stupid twitter trends and sponsored ads / follow suggestions | |
// @author webfussel | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
const sponsored = ['Gesponsert', 'Sponsored'] | |
const sponsoredRegexp = new RegExp(sponsored.join('|')) | |
const removeElement = e => { | |
// Remove sponsored | |
// Tweets | |
if (e.matches('[data-testid="placementTracking"]') && e.innerText.match(sponsoredRegexp)) e.parentElement.parentElement.innerHTML = '' | |
// Follow Suggestions | |
if (e.matches('[data-testid="UserCell"]') && e.innerText.match(sponsoredRegexp)) e.remove() | |
} | |
const removeTrends = () => { | |
// Twitter Blue Menu Point | |
document.querySelector('[aria-label="Twitter Blue"]')?.remove() | |
// Trends | |
document.querySelector('[href*="explore"]')?.remove() | |
const lists = document.querySelectorAll('[aria-labelledby^="accessible-l"]') | |
lists?.forEach(element => { | |
if (element.querySelector(':scope > h1')?.innerText.toLowerCase().indexOf('trends') > -1) { | |
element.parentElement.parentElement.remove() | |
} | |
}) | |
} | |
const observer = new MutationObserver(mutations => { | |
removeTrends() | |
mutations.forEach(mutation => { | |
mutation.addedNodes.forEach(removeElement) | |
}) | |
}) | |
observer.observe(document.body, { | |
childList: true | |
,subtree: true | |
,attributes: false | |
,characterData: false | |
}) |
bensh90
commented
Jul 24, 2021
•
Thanks! I implemented it :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment