Reputation: 5722
Im using chrome.contextMenus
documentUrlPatterns to filter where to show the context menu.
I tried prepending '-' to the patterns but that doesnt change anything...
function recreateStuff(){
if(logoncmid!=-1){}
var hosts=[];
var ihosts=[];
for (var i = savedData.length - 1; i >= 0; i--) {
hosts.push(savedData[i].host);
ihosts.push("-"+savedData[i].host);
//console.log(savedData[i]);
};
// hosts created ...
chrome.contextMenus.update(logoncmid,{documentUrlPatterns: hosts});
chrome.contextMenus.update(regcmid,{documentUrlPatterns: ihosts});
}
Is it possible to make an exclude list ?
Upvotes: 2
Views: 698
Reputation: 5722
how about a hack ? :)
var windowTopTab = [];
var curWin = 1;
var curUrl = "";
function fetchCurUrl() {
if (!windowTopTab[curWin]) return;
chrome.tabs.get(windowTopTab[curWin], function(tab) {
curUrl = url;
});
}
chrome.tabs.onActivated.addListener(function(activeInfo) {
windowTopTab[activeInfo.windowId] = activeInfo.tabId;
fetchCurUrl();
recreateStuff();
});
chrome.windows.onFocusChanged.addListener(function(windowId) {
curWin = windowId;
fetchCurUrl();
recreateStuff();
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (windowTopTab[curWin])
if (windowTopTab[curWin] == tabId) {
fetchCurUrl();
recreateStuff();
}
});
var contextm = chrome.contextMenus.create({
title: "* Fill RegForm",
contexts: ["editable"],
onclick: genericOnClick
});
function recreateStuff() {
var curHN = getHostname(curUrl);
var reg = true;
for (var i = savedData.length - 1; i >= 0; i--) {
if (savedData[i].host == curHN) reg = false;
}
if (reg) {
chrome.contextMenus.update(contextm, {
title: "* RegForm",
onclick: genericOnClick
});
} else {
chrome.contextMenus.update(contextm, {
title: "* LoginForm",
onclick: genericOnClick2
});
}
}
Upvotes: 2
Reputation: 115910
I don't think this is currently possible, since documentUrlPatterns
takes an array of match patterns and there is no way to express a negative match pattern.
You might open a feature request for a mechanism to express excluded match patterns, as is done for content scripts with exclude_matches
and exclude_globs
.
Upvotes: 2