Skip to content

Commit

Permalink
[WIP] Start wrapping mute snippet into chrome extension
Browse files Browse the repository at this point in the history
  • Loading branch information
wwerner committed Dec 19, 2020
1 parent 4eea1d3 commit 925c347
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/promute.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Promute",
"manifest_version": 2,
"version": "0.0.1",
"description": "Promute automatically mutes twitter accounts sending promotions to your timeline as you scroll by.",
"content_scripts": [
{
"matches": ["*://twitter.com/*"],
"js": ["test.js"]
}
]
}
26 changes: 26 additions & 0 deletions promute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var xPathEvaluator = $x

function debounce(func, wait = 100) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}

mutePromoters = () => {
xPathEvaluator()
.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)
33 changes: 33 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const XPATH_PROMOTED_TWEET_MENU_ACTIVATORS = '//span[text()="Promoted"]/../../../..//div[@data-testid="caret"]'
const XPATH_MUTE_BUTTON = '//*[@role="menuitem"]//span[starts-with(text(),"Mute")]'

function debounce(func, wait = 100) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}

mutePromoters = () => {
console.log('foo')
let promotedTweetActivators = document.evaluate(XPATH_PROMOTED_TWEET_MENU_ACTIVATORS, document.body, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null)
if (promotedTweetActivators){
var promotedTweetActivator = promotedTweetActivators.iterateNext();
while(promotedTweetActivator) {
console.log('bar')
promotedTweetActivator.click();
setTimeout(() => {
let muteButton = document.evaluate(XPATH_MUTE_BUTTON,document.body, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null)[0];
console.log(muteButton.innerText);
muteButton.click()
}, 250)
promotedTweetActivator = promotedTweetActivators.iterateNext();
}
}
}

debouncedMutePromoters = debounce(mutePromoters, 1000)
document.addEventListener('scroll', debouncedMutePromoters)

0 comments on commit 925c347

Please sign in to comment.