Block Ad accounts on X (Twitter) | UserScript | Tampermonkey This is a Tampermonkey userscript designed to automatically block advertising accounts on X (formerly Twitter). The script identifies promoted tweets labeled "Ad" on the platform, then programmatically clicks through the interface to block each advertiser account, storing the blocked accounts in the browser's local storage. It runs immediately upon page load and continues to check for new ads every five seconds. block-ad-accounts-on-x.userscript.js 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 Show hidden characters // ==UserScript== // @name Block Ad accounts on X Twitter // @namespace http://tampermonkey.net/ // @version 2024-11-30 // @description try to take over the world // @author You // @match https://x.com/ // @icon https://www.google.com/s2/favicons?sz=64&domain=x.com // @grant none // ==/UserScript== async function blockAdvertisers { const ads = Array.from document.querySelectorAll ' data-testid="tweet" style ="rgb" ' .filter ad = /^Ad$/.test ad.innerText ; for const ad of ads { const tweet = ad.closest ' data-testid="tweet" ' ; localStorage. blockAdvertisers = localStorage. blockAdvertisers || "{}"; const btn = ad.parentElement.parentElement.parentElement.querySelector "button" ; btn.click ; await new Promise r = setTimeout r, 100 ; const menu = document.querySelector ' role="menu" ' ; const blockBtn = Array.from menu.querySelectorAll 'div role="menuitem" ' .find d = /Block @/.test d.innerText ; blockBtn.click ; await new Promise r = setTimeout r, 100 ; const okBtn = document.querySelector ' role="group" button' ; okBtn.click ; await new Promise r = setTimeout r, 1000 ; localStorage. blockAdvertisers = JSON.stringify { ...JSON.parse localStorage. blockAdvertisers , tweet.querySelector "a" .href.slice 1 : true, } ; const maybeLater = Array.from document.querySelectorAll "button" .find x = /Maybe later/.test x.innerText ; maybeLater?.click ; await new Promise r = setTimeout r, 100 ; } } blockAdvertisers ; setInterval = { blockAdvertisers ; }, 5000 ;