opera.extension.urlfilter.block.add()

By Opera Software

From Opera 15 onward, Opera 11 & 12’s extension format is no longer supported, and instead, we’ve switched to Chromium’s extension model. Check out our new documentation for developing extensions for Opera 15 and higher and start building your own extensions.

Description:

Adds a rule to the virtual list of blocked URLs.

Parameters:

  • rule: The rule (e.g. domain) to block.

Syntax:

void add (<DOMString> rule)

Example:

<!--
  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)
//

// Store and retrieve a list of URLs in the extension's preferences
widget.preferences['blacklist'] = ['http://opera.com/*', 'http://*.opera.com/*'];
var blacklist = widget.preferences['blacklist'].split(',');

// Assign the URLFilter object to a variable for efficiency
var filter = opera.extension.urlfilter;

// Loop through the array of sites and add each one to the "block" list
for (var i = 0, len = blacklist.length; i < len; i++) {
  filter.block.add(blacklist[i]);
}

The following 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.

Parameters:

  • rule: The rule (e.g. domain) to allow.
  • options: Options to specify conditions for the given rule.

Syntax:

void add (DOMString rule, RuleOptions options)

Example

The following example blocks all content from the google.com but only when it appears in a third-party domain (i.e. not google.com).

<!--
  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)
//

if (typeof opera.extension.urlfilter != 'undefined') {
  // Set the options for the filter rule
  var ruleOptions = {
      thirdParty: true
  }

  opera.extension.urlfilter.block.add('||google.com/*', ruleOptions);
}

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

  • photo

    akpanediomo

    Monday, November 19, 2012

    New improve opera should come with antivirus
No new comments accepted.