-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Start wrapping mute snippet into chrome extension
- Loading branch information
Showing
8 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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"] | ||
} | ||
] | ||
} |
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
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) |
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
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) |