browser action:点击时改变图标

运用 background_page, browser_action and tabs

调用:

源码:

  • background.js
  // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  // Use of this source code is governed by a BSD-style license that can be
  // found in the LICENSE file.

  var min = 1;
  var max = 5;
  var current = min;

  function updateIcon() {
    chrome.browserAction.setIcon({path:"icon" + current + ".png"});
    current++;

    if (current > max)
      current = min;
  }

  chrome.browserAction.onClicked.addListener(updateIcon);
  updateIcon();
  • manifest.json
  {
    "name": "A browser action which changes its icon when clicked.",
    "version": "1.1",
    "background": { "scripts": ["background.js"] },
    "permissions": [
      "tabs", "http://*/*"
    ],
    "browser_action": {
        "name": "Click to change the icon's color"
    },
    "manifest_version": 2
  }

资源下载

set_icon_path.zip