-
-
Save byronaltice/8aeba3f8e1cbd565a569cba5111f9d4a to your computer and use it in GitHub Desktop.
Tampermonkey script to remove promoted tweets
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 Twitter Promoted | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Get rid of stupid promoted tweets | |
// @author Mac Gaulin | |
// @match http*://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
var numberTweetsHidden = 0; | |
var previousNumberTweetsHidden = 0; | |
function contains(selector, text) { | |
let elements = document.querySelectorAll(selector); | |
return Array.from(elements).filter(function(element) { | |
return RegExp(text).test(element.textContent); | |
}); | |
} | |
function removePromoted() { | |
let found = contains("span", "^Promoted"); | |
for (let i = 0; i < found.length; i++) { | |
let elem = found[i]; | |
let article = elem.closest("article"); | |
if (article) { | |
article.parentNode.style.backgroundColor = "red"; | |
article.parentNode.removeChild(article); | |
numberTweetsHidden++; | |
} | |
} | |
if(numberTweetsHidden - previousNumberTweetsHidden != 0) { | |
console.log("found " + (numberTweetsHidden - previousNumberTweetsHidden) + " promoted tweets and hid them all"); | |
previousNumberTweetsHidden = numberTweetsHidden; | |
} | |
} | |
setInterval(removePromoted, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original script wouldn't hide the elements until they scrolled into view, but removeChild does
The original also only ran once, so if you scrolled into new elements it wouldn't find those. Now it runs every second.