URL Filter syntax

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:

Enables special characters to be used for more flexible filtering. Note that all pattern matching is case sensitive.

Syntax:

Wildcard

* matches any character.

Hostname marker

|| matches the beginning of any hostname.

Separator wildcard

^ matches a single character from the following list:

! " # $ & ' ( ) * + , / : ; < = > ? @ [ \ ] ^ ` { | } ~

In other words, || matches any character in the ASCII subset that is not a letter, a digit, or one of the following:

_ - . %

For example, ||example.com^ will match match http://example.com:8080/, http://example.com/, https://subdomain.example.com/, etc. but not http://example.com.evil.com because ^ doesn't match . (period).

Example:

This example shows how we can convert whitelisting in Adblock Plus syntax to the Opera URL Filter syntax. The whitelisting rule will allow scripts from the ||ads.cnn.com/js.ng/*&cnn_intl_subsection=download URL and is taken from this list: https://easylist-downloads.adblockplus.org/easylist.txt

<!--
  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:
  // @@||ads.cnn.com/js.ng/*&cnn_intl_subsection=download$script
  filter.allow.add("||ads.cnn.com/js.ng/*&cnn_intl_subsection=download", {resources: filter.RESOURCE_SCRIPT});
}

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

Comments

  • photo

    Martin Kadlec

    Wednesday, September 5, 2012

    How can I make rule that blocks every url? Simple '*' doesn't work :/
  • photo

    Mike Taylor

    Wednesday, January 16, 2013

    @gwarser, updated thanks.
No new comments accepted.