我正在尝试对chrome进行扩展,该扩展基于options.html
页面将允许显示某些上下文菜单项。我知道有Google制作的“全局上下文搜索”演示。但我希望根据用户的选择显示一些网址。
chrome.storage.onChanged.addListener(function(list, sync) {
let newlyDisabled = [];
let newlyEnabled = [];
let currentRemoved = list.nrMenu.newValue;
let oldRemoved = list.nrMenu.oldValue || [];
for (let key of Object.keys(nrAgentList)) {
if (currentRemoved.includes(key) && !oldRemoved.includes(key)) {
newlyDisabled.push(key);
} else if (oldRemoved.includes(key) && !currentRemoved.includes(key))
{
newlyEnabled.push({
id: nrAgentList[key],
title: key
});
}
}
for (let locale of newlyEnabled) {
var locale.title = chrome.contextMenus.create({title: locale.id+'+'+locale.title+"+"+ locale , id: locale.title});
console.log(locale.title);
console.log("Enabled");
console.log(newlyEnabled);
}
});
因此,从理论上讲,当上面用值APM调用ParentID
时,我希望它传递下面的链接以显示在上下文菜单中。
var Installation_APM = chrome.contextMenus.create({title: "Installation", "parentId": APM,});
chrome.contextMenus.create({title: "Link1", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://link1.com"});}});
chrome.contextMenus.create({title: "Link2", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://link2.com"});}});
chrome.contextMenus.create({title: "link3", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://Link3.com"});}});
chrome.contextMenus.create({title: "Link4", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://Link4.com"});}});
我猜测我缺少一些基本知识,如果您能指出正确的方向,我将不胜感激。