将上下文菜单项添加到Chrome扩展程序的浏览器操作按钮 [英] Add contextmenu items to a Chrome extension's browser action button

查看:112
本文介绍了将上下文菜单项添加到Chrome扩展程序的浏览器操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome扩展程序可以有一个'浏览器操作'。通常,当你点击它时,ext开发者会显示这些选项,这意味着每个动作需要2次点击,即使是默认的99%的时间动作。 Chrome本身会添加一个上下文菜单,其中包含一些选项:禁用ext,卸载ext,进入ext主页等。

我可以将ext开发人员添加到该上下文菜单中,所以我可以在正常/左/主鼠标点击下保持我的单击动作?



我知道 chrome.contextMenus ,但这仅适用于页面中的上下文菜单(请参阅属性' contexts ')。

我无法在 Chrome扩展开发指南,但你知道的比我多。 解决方案

此时 ,AdBlock chrome扩展有它。以下是浏览器操作中的上下文菜单的工作示例。



manifest.json:




$ name
$ name
$ name
$ name $ ,
manifest_version:2,
background:{
scripts:[background.js]
},
browser_action:{
default_title:一些工具提示,
default_popup:popup.html
},
权限:[
contextMenus
$ b图标:{
16:icon16.png
}
}

background.js:

chrome.contextMenus.removeAll();
chrome.contextMenus.create({
title:first,
contexts:[browser_action],
onclick:function(){
alert('第一');
}
});

请注意,如果您使用 Event page ,你不能使用 onclick 属性;您需要添加一个侦听器来代替 chrome.contextMenus.onClicked


A G Chrome extension can have a 'browser action'. Usually the ext developer displays the options when you click on it, meaning every action requires 2 clicks, even the default 99%-of-the-time action. Chrome itself adds a context menu with a few options: disable ext, uninstall ext, go to ext homepage etc.

Can I as ext developer add items to that context menu, so I can keep my 1-click-action under the normal/left/primary mouse click?

I know of chrome.contextMenus but that's only for context menus in the page (see property 'contexts').

I can't find it in the Chrome Extension dev guide, but you know more than I.

解决方案

It is now possible, AdBlock chrome extensions has it. Below is working example of "context menu in browser action".

manifest.json:

{
    "name": "Custom context menu in browser action",
    "version": "1",
    "manifest_version": 2,
    "background": {
      "scripts": ["background.js"]
    },
    "browser_action": {
      "default_title": "Some tooltip",
      "default_popup": "popup.html"
    },
    "permissions": [
      "contextMenus"
    ],
    "icons": {
      "16": "icon16.png"
    }
}

background.js:

chrome.contextMenus.removeAll();
chrome.contextMenus.create({
      title: "first",
      contexts: ["browser_action"],
      onclick: function() {
        alert('first');
      }
});

Note that if you use an Event page, you cannot use the onclick attribute; you'll need to add a listener to chrome.contextMenus.onClicked instead.

这篇关于将上下文菜单项添加到Chrome扩展程序的浏览器操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆