Skip to content

Instantly share code, notes, and snippets.

@gaulinmp
Created October 6, 2020 17:26
Show Gist options
  • Save gaulinmp/a3e7ad91f37a01346b2d39ca1ba38bfc to your computer and use it in GitHub Desktop.
Save gaulinmp/a3e7ad91f37a01346b2d39ca1ba38bfc to your computer and use it in GitHub Desktop.
Tampermonkey script to remove promoted tweets
// ==UserScript==
// @name Twitter Promoted
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Get rid of stupid promoted tweets
// @author Mac Gaulin
// @match http*://twitter.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// source: https://stackoverflow.com/a/59687531
function contains(selector, text) {
var elements = document.querySelectorAll(selector);
return Array.from(elements).filter(function(element) {
return RegExp(text).test(element.textContent);
});
}
function removePromoted() {
let found = contains("span", "^Promoted");
console.log("Found " + found.length + " promoted tweets.");
for (let i = 0; i < found.length; i++) {
let elem = found[i];
let art = elem.closest("article");
if (art) {
art.style.display = 'none';
art.parentNode.style.backgroundColor = "red";
console.log("Hid promoted tweet " + i);
}
else {
console.log("Promoted tweet wasn't an article", elem);
}
}
}
setTimeout(removePromoted, 7000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment