Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How adding more links on the extension page action

I'm developing an extension page action that works only in a specific domain, can I add more than one link to the page action? My background.js is this.

it is possible to add more links in background.html for the extension page action?

//background.js

chrome.runtime.onInstalled.addListener(function() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {

  chrome.declarativeContent.onPageChanged.addRules([ 
{
  conditions: [
    new chrome.declarativeContent.PageStateMatcher({
      pageUrl: { urlContains: 'www.exemple.com' },
 })
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
like image 414
Weiller Jayceon Avatar asked Dec 02 '14 16:12

Weiller Jayceon


1 Answers

Yes, you can register a page action for multiple sites by adding multiple PageStateMatchers to the list of conditions.

chrome.runtime.onInstalled.addListener(function() {
    chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
        chrome.declarativeContent.onPageChanged.addRules([{
            conditions: [
                new chrome.declarativeContent.PageStateMatcher({
                    pageUrl: { hostSuffix: 'example.com' }
                }),
                new chrome.declarativeContent.PageStateMatcher({
                    pageUrl: { hostSuffix: 'example.net' }
                }),
            ],
            actions: [ new chrome.declarativeContent.ShowPageAction() ]
       }]);
    });
});

Note: I replaced urlContains with hostSuffix because you wanted to show the page action on certain domains, not on all pages whose URL contain the website's host (e.g. you probably don't want to match http://localhost/path/containing/www.example.com). See the documentation of the UrlFilter type for more ways to match pages.

like image 144
Rob W Avatar answered Sep 23 '22 04:09

Rob W