Developers › Dev.Opera

RuleOptions.includeDomains

May 16, 2012 · by Opera Software

This functionality is currently in production, and only available to test in an experimental build of Opera desktop. To download the experimental build, see Desktop build with new extension APIs: Screenshot, Resource Loader and URL Filter.

Description:

An array of zero or more domains on which to apply a given URL Filter rule.

This property is passed within a RuleOptions object as a parameter for URL Filter methods.

Syntax:

DOMString[] includeDomains

Example:

The following example blocks any content with /ads/ in the URL except from ||huffpost.com/images/ads/* and when included in pages in the huffingtonpost.com domain.

<!-- 
  The configuration file ('config.xml').
-->
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
    ...
    <feature name="opera:urlfilter"/>
</widget>
//
// The background process (e.g. index.html)
//

// Check that the URL Filter API exists
if (typeof opera.extension.urlfilter != 'undefined') {  
  // Assign the URLFilter object to a variable for efficiency
  var filter = opera.extension.urlfilter;
  
  filter.block.add('*/ads/*');
  
  // The following is the same as this Adblock syntax for whitelisting:
  // @@||huffpost.com/images/ads/$domain=huffingtonpost.com
  var ruleOptions = {
    includeDomains: ['huffingtonpost.com']
  }
  filter.allow.add('||huffpost.com/images/ads/*', ruleOptions);
}

Note the use of || which is a hostname mark. This indicates that the subsequent characters should begin matching from any host name in the URL. For example, ||example.com* matches http://example.com/, https://www.example.com/, or similar. However, it will not match http://badexample.com/.

About this article

Published inDev.Opera
DateMay 16, 2012
AuthorOpera Software
Tagsextensions API, URL filter
OriginalInternet Archive