Skip to content

Instantly share code, notes, and snippets.

@wwerner
Last active January 9, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwerner/2c9b0f151f646bf44903f1acd96441e7 to your computer and use it in GitHub Desktop.
Save wwerner/2c9b0f151f646bf44903f1acd96441e7 to your computer and use it in GitHub Desktop.
Mute Twitter accounts sending promotions
// This is neither elegant nor robust,
// but it _does_ mute everyone sending
// promoted tweets to my timeline.
// It works by installing a debounced
// scroll listener which checks for promoted tweets
// and mutes their sender by clicking the resp.
// tweet context menu action.
var xPathEvaluator = $x
function debounce(func, wait = 100) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}
mutePromoters = () => {
xPathEvaluator('//span[text()="Promoted"]/../../../..//div[@data-testid="caret"]')
.forEach(promotedTweetMenuActivator => {
promotedTweetMenuActivator.click();
setTimeout(() => {
let muteButton = xPathEvaluator('//*[@role="menuitem"]//span[starts-with(text(),"Mute")]')[0];
console.log(muteButton.innerText);
muteButton.click()
}, 250)
})
}
debouncedMutePromoters = debounce(mutePromoters, 1000)
document.addEventListener('scroll', debouncedMutePromoters)
@wwerner
Copy link
Author

wwerner commented Jan 9, 2021

Superseeded by Promute: https://github.com/wwerner/promute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment