Chrome扩展程序:如何使用自定义名称创建上下文菜单,而不是插件名称

Ask*_* B. 3 google-chrome contextmenu google-chrome-extension

我正在尝试创建一个基本的chrome扩展.在发现根上下文菜单每个插件只能包含一个项目之后,我想至少能够为父项命名除了我的插件名称之外的其他内容:

chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
});
Run Code Online (Sandbox Code Playgroud)

http://i.imgur.com/hsObtyL.png

那我该怎么做?

Ask*_* B. 9

我所采取的方式,是一个自定义创建父项目titleid,然后将我需要的所有物品,因为儿童的父项(我的script.js文件):

chrome.contextMenus.create({
    title: "Custom Parent Name",
    contexts:["selection"],
    id: "parent",
});
chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
    parentId: "parent",
    id: "child1",
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
    parentId: "parent",
    id: "child2",
});
Run Code Online (Sandbox Code Playgroud)

这是结果:

结果