Last active
January 9, 2021 13:29
-
-
Save wwerner/2c9b0f151f646bf44903f1acd96441e7 to your computer and use it in GitHub Desktop.
Mute Twitter accounts sending promotions
This file contains 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
// 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Superseeded by Promute: https://github.com/wwerner/promute