Im trying to make an extension for chrome, that based on an options.html
page will allow certain context menu items to show up. I know there is the Demo of 'Global Context Search' made by google. But I want a selection of urls to appear based on the users choice.
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);
}
});
So in theory when the ParentID
is called above with the value APM, I want it to pass in the links below to appear in the context menu.
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"});}});
Im guessing that Im missing something fundamental, if you could point me in the right direction I would be grateful.