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);
source & further reading
gist.github.com — original article
agent-proxy — a zero-dep proxy that shows the bloat in Claude Code's requests (ranked tool table + full readable Markdown of every request)
PowerShell profile and test suite
A plan-of-plans for a production-grade end-to-end e-commerce website.