This documentation relates to Opera's now deprecated .oex Extension API framework for Opera versions <= 12.15 and also provided by our OEX2NEX shim library.
For the latest Opera Extensions API documentation for Opera versions > 12.15 please consult the latest Opera Extensions API documentation online.
Adds a rule to the virtual list of blocked URLs (blacklist).
Note that allowed rules have priority over blocked rules.
rule
: The rule (e.g. domain) to block.void add (<DOMString> rule)
In this example, domains to be blocked are stored in the extension's preferences, and then retrieved and added to the filter's blocking rules.
<!--
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.
rule
: The rule (e.g. domain) to allow.options
: Options to specify conditions for the given rule.void add (DOMString rule, RuleOptions options)
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);
}