Created
October 6, 2020 17:26
-
-
Save gaulinmp/a3e7ad91f37a01346b2d39ca1ba38bfc to your computer and use it in GitHub Desktop.
Revisions
-
gaulinmp created this gist
Oct 6, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ // ==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); })();