0

特定のキーワードのツイートを表示する単純な 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/*"
  ]
}
4

1 に答える 1

3

あなたが使用することができます

chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});

このコードは、yのアイコンに数字を付けます

于 2013-02-01T11:32:47.673 に答える