条件上下文菜单取决于站点
我正在开发一个小 chrome 扩展,当用户右键单击网页时,它使用 contextMenu 添加一个或两个选项。但是,这仅与少数网页相关,我只想在相关时显示附加菜单项。
因此,我想要一种方法来获取后台页面中的当前 URL,并查看该 URL 是否与我的白名单中的任何网站匹配。
我用谷歌搜索了一下,但我不确定这是否可能。任何帮助将不胜感激,请不要吝惜我的细节 - JavaScript 不是我的强项。
I'm am working on a little chrome extension which uses the contextMenu to add an option or two when the user right clicks a webpage. However, this is only relevant of a few webpages out there and I would like to only show the additional menu item when it is relevant.
I would therefore like a way to get the current URL in my background page and see if the URL matches any of the sites in my whitelist.
I've googled a bit around but I'm not sure this is even possible. Any help would be appreciated, and please do not spare me for the details - JavaScript is not my strong side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DevGuide
参数
菜单项的类型。如果未指定,则默认为“正常”。
要在项目中显示的文本;除非类型是“分隔符”,否则这是必需的。当上下文为“选择”时,您可以在字符串中使用 %s 来显示所选文本。例如,如果此参数的值为“将 '%s' 翻译为 Pig Latin”并且用户选择单词“cool”,则该选择的上下文菜单项为“将 'cool' 翻译为 Pig Latin”。
复选框或单选项目的初始状态:true 表示已选定,false 表示未选定。在给定的一组单选项目中一次只能选择一个单选项目。
此菜单项将出现在的上下文列表。如果未指定,则默认为 ['page']。
父菜单项的 ID;这使得该项目成为先前添加的项目的子项。
允许您将项目限制为仅应用于其 URL 与给定模式之一匹配的文档。 (这也适用于帧。)有关模式格式的详细信息,请参阅匹配模式。
与 documentUrlPatterns 类似,但允许您根据 img/audio/video 标签的 src 属性和锚标签。
单击菜单项时将回调的函数。
参数
有关单击的项目以及单击发生的上下文的信息。
单击发生的选项卡的详细信息。
DevGuide
Parameters
The type of menu item. Defaults to 'normal' if not specified.
The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin".
The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items.
List of contexts this menu item will appear in. Defaults to ['page'] if not specified.
The ID of a parent menu item; this makes the item a child of a previously added item.
Lets you restrict the item to apply only to documents whose URL matches one of the given patterns. (This applies to frames as well.) For details on the format of a pattern, see Match Patterns.
Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.
A function that will be called back when the menu item is clicked.
Parameters
Information about the item clicked and the context where the click happened.
The details of the tab where the click took place.