我刚刚构建了一个简单的chrome扩展程序来显示特定关键字的推文。它工作正常。每当有新的推文可用时,如果用户点击它显示的扩展图标。
但有没有办法在扩展程序图标中显示一些通知,表明检索到了新数据?
这是我的javascript代码
var req=null;
window.onload = function() {
req = new XMLHttpRequest();
req.open("GET", "http://search.twitter.com/search.atom?q=20SongsThatILike", true);
req.onload = showTweets;
req.send(null);
}
function showTweets() {
var title=req.responseXML.getElementsByTagName('title')[1].childNodes[0];
var author=req.responseXML.getElementsByTagName('author')[1].childNodes[0].childNodes[0];
document.body.appendChild(title);
}
这是我的HTML代码
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width:357px;
overflow-x:hidden;
}
img {
margin:5px;
border:2px solid black;
vertical-align:middle;
width:75px;
height:75px;
}
</style>
<!-- JavaScript and HTML must be in separate files for security. -->
<script src="script.js"></script>
</head>
<body>
</body>
</html>
这是manifest.json
{
"name": "My First Extension",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://search.twitter.com/*"
]
}
答案 0 :(得分:3)
你可以使用
chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});
此代码会在y
的图标上放置一个数字