Chrome Extension: How do I poll RSS Feeds to see if there is new content and display that as a number on the extension icon
I wonder if you could help a little.
I want to have a simple Extension, that shows the number of new items i开发者_StackOverflown a RSS feed since the extension was clicked.
It would poll every 2-3 mins for example and if the RSS feed is updated it should display a count of how many new items there are. I assume it has to set the setBadgeText field.
Any help would be greatly appreciated.
You will have to implement a couple of things.
A background_page that will contain all of your code and periodically poll the RSS feed.
Within the backround_page you will have to use XHR to request the feed.
After you get the feed parse it and compare with a list of previous posts in localStorage. If there are new ones use chrome.browserAction.setBadgetText() to update the displayed count.
Once a user clicks on the browserAction button you will likely want to open a new tab to the website with chrome.tabs.create() and clear the shown new count.
You can do this with the chrome.browserAction.setBadgeText API.
Something like:
chrome.browserAction.setBadgeText({ text: '5' });
精彩评论