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.
A bit-masked value indicating the types of resources to apply a given URL Filter rule to. The available resource types are as follows:
<img>
elements, the background attribute on various elements, or CSS properties.<audio>
, <video>
or <source>
elements.<object>
elements.<embed>
or <object>
element.<meta>
element with an http-equiv
attribute whose value is "refresh" and a content attribute whose value contains a timeout value and optionally a URL.<script>
elements.<link>
elements or @import
directives within a stylesheet.<frame>
or <iframe>
element.XMLHttpRequest
object.This property is passed within a RuleOptions
object as a parameter for URL Filter methods.
unsigned long resources
The following example blocks content from google.com whenever it appears as the source of a frame or iframe, e.g. a Google+ widget.
<!--
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;
// Set the options for the filter rule
var ruleOptions = {
resources: filter.RESOURCE_SUBDOCUMENT
}
filter.block.add('||google.com/*', ruleOptions);
}
This next example uses a custom function to make it easier to combine multiple resource types. In this case, it blocks all scripts, stylesheets and images from the google.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') {
// Function for mapping filter resources
function types(types) {
var urlfilter = opera.extension.urlfilter;
var contentType = 0;
var map = {
"other": urlfilter.RESOURCE_OTHER, // 1
"script": urlfilter.RESOURCE_SCRIPT, // 2
"image": urlfilter.RESOURCE_IMAGE, // 4
"stylesheet": urlfilter.RESOURCE_STYLESHEET, // 8
"object": urlfilter.RESOURCE_OBJECT, // 16
"subdocument": urlfilter.RESOURCE_SUBDOCUMENT, // 32
"document": urlfilter.RESOURCE_DOCUMENT, // 64
"refresh": urlfilter.RESOURCE_REFRESH, // 128
"xmlhttprequest": urlfilter.RESOURCE_XMLHTTPREQUEST, // 2048
"objectsubrequest": urlfilter.RESOURCE_OBJECT_SUBREQUEST, // 4096
"media": urlfilter.RESOURCE_MEDIA, // 16384
"font": urlfilter.RESOURCE_FONT // 32768
};
for (var i = 0, len = arguments.length; i < len; i++) {
contentType |= map[arguments[i]];
}
return contentType;
}
// Set the options for the filter rule
ruleOptions = {resources: types("script", "stylesheet", "image")};
/*
* This is equivalent to
* ruleOptions = {
* resources: opera.extension.urlfilter.RESOURCE_SCRIPT |
* opera.extension.urlfilter.RESOURCE_STYLESHEET |
* opera.extension.urlfilter.RESOURCE_IMAGE
* };
*/
opera.extension.urlfilter.block.add('||google.com/*', 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/
.