为chrome扩展上下文菜单添加更多自定义选项

时间:2016-04-19 10:14:06

标签: google-chrome-extension

当用户右键点击Chrome中的扩展程序时,有没有办法向扩展程序上下文菜单添加自定义选项。任何输入将不胜感激。 enter image description here

更新 我试过的示例页面操作扩展

Manifest.json
   {
       "name": "Sample",
       "version": "0.1",
       "manifest_version": 2,
       "background": {
        "scripts": ["background.js"]
       },
       "page_action": {
        "default_title": "Sample"
        },
        "permissions": [
        "contextMenus"
        ]
    }

Background.js

chrome.contextMenus.create({
    title: "Option22",
    contexts: ["page_action"],
    onclick: function() {
        console.log("click");
    }
});

chrome.runtime.onInstalled.addListener(function() {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page's URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: 'g' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});

1 个答案:

答案 0 :(得分:3)

请检查contextMenus,您可以通过设置上下文<div ng-repeat="item in posts | filter:searchBox" class="card has-header" ng-if="searchBox.storeName">

来创建扩展上下文菜单

的manifest.json

"browser_action"

background.js

{
    "name": "36715370",
    "version": "0.1",
    "manifest_version": 2,
    "background": {
        "scripts": ["background.js"]
    },
    "browser_action": {
        "default_title": "Your browser action title"
    },
    "permissions": [
        "contextMenus"
    ]
}