Created
July 14, 2017 08:01
-
-
Save fjaguero/1cf3cef3b468ca8a6ccee42bcb4de195 to your computer and use it in GitHub Desktop.
Content Script
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
$(document).ready(function() { | |
// Select the target node (tweet modal) | |
var target = $('.PermalinkOverlay-modal').get(0); | |
// Create an observer instance | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
// Get the Twitter modal window replies count | |
var loneTweetsCount = $('.PermalinkOverlay-body .ThreadedConversation--loneTweet .tweet').length | |
var threadedTweetsCount = $('.PermalinkOverlay-body .ThreadedConversation .tweet').length | |
var total = loneTweetsCount + threadedTweetsCount | |
// Send message to background.js so we can set the badge text | |
chrome.extension.sendMessage({'count': total}) | |
}); | |
}); | |
// Configuration of the observer | |
var config = { attributes:true, subtree: true }; | |
// Pass in the target node, as well as the observer options | |
observer.observe(target, config); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment