Skip to content

Instantly share code, notes, and snippets.

@jogerj
Forked from cb372/hide-promoted-tweets.user.js
Last active July 15, 2022 00:49
Show Gist options
  • Save jogerj/333221ea0b5e8e09a051c38a09150127 to your computer and use it in GitHub Desktop.
Save jogerj/333221ea0b5e8e09a051c38a09150127 to your computer and use it in GitHub Desktop.
A simple userscript to hide promoted tweets on twitter.com - Modified for Tampermonkey v4
// ==UserScript==
// @name Hide Promoted Tweets
// @namespace https://github.com/jogerj
// @source https://gist.github.com/jogerj/333221ea0b5e8e09a051c38a09150127
// @version 0.1
// @description Hide promoted tweets on twitter.com
// @author JogerJ
// @author cb372
// @icon https://abs.twimg.com/favicons/favicon.ico
// @grant none
// @match *://twitter.com/*
// ==/UserScript==
var elems = document.getElementsByClassName('tweet')
for (var i=0; i < elems.length; i++) {
var e = elems[i];
if (e.nodeName.toLowerCase() == 'div' &&
e.attributes['data-promoted'] &&
e.attributes['data-promoted'].value == "true") {
// Just hiding the elem doesn't work, as this is
// not actually the elem that gets rendered to screen.
// Twitter's script will later convert it into
// another, visible, element.
//e.style.display = 'none';
e.parentNode.removeChild(e);
console.debug('Deleted a promoted tweet', e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment