Christoph
Christoph

Reputation: 51181

chrome.contextMenus: context menu entry for specific links only

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

Answers (1)

abraham
abraham

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

Related Questions