Reputation: 51181
Currently I have a custom context menu entry Login when I right click on a link. However, I wonder if there is a possibility to present my custom context menu entry only for specific types of links? Currently my code looks like this:
var context = 'link';
var title = 'Login';
var id = chrome.contextMenus.create({"title": title,
"contexts":[context],
"onclick": login});
function login(e){
var url = e.linkUrl;
url += ((url.indexOf("?")>-1)?"&":"?") + "Login=admin&Password=admin";
window.open(url);
}
I would like to have a context filter so that I could choose to show the entry only if the link has a certain format, e.g. http://.../myspecificurl/...
.
Basically I need something like:
var context = 'link[href*=/myspecificurl/]';
or a callback upon rendering the context menu.
Upvotes: 2
Views: 2365
Reputation: 47833
It's documented as targetUrlPatterns using match patterns.
chrome.contextMenus.create({
"title": title,
"contexts": [context],
"onclick": login,
"targetUrlPatterns": ["http://*.example.com/*"]
});
Upvotes: 5