我正在尝试创建基本的Chrome扩展程序。在发现root context menu can only contain one item per plugin之后,我想至少能够为父母命名而不是我的插件名称:
chrome.contextMenus.create({
title: "Child Item 1",
contexts:["selection"],
});
chrome.contextMenus.create({
title: "Child Item 2",
contexts:["selection"],
});
那我该怎么做?
答案 0 :(得分:9)
我这样做的方法是创建一个包含自定义title
和id
的父项,然后将我需要的所有项目作为子项添加到父项目(添加到script.js
1}}文件):
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",
});
结果如下: