Working with filters

Adblock Plus comes equipped with several pre-installed filter lists. These filter lists are designed to improve the browsing experience by blocking unwanted content. They include:

  • Acceptable Ads: This list allows certain non-intrusive ads to ensure that websites relying on advertising can still generate revenue.

  • EasyList: The primary filter list that blocks most ads, automatically adjusting based on the user's browser language settings.

  • ABP Anti-circumvention Filter List: Specifically targets and blocks ads that attempt to circumvent ad blockers.

In addition to the pre-installed filter lists, Adblock Plus offers users the ability to create their own custom filters. Custom filters enhance your control over what gets blocked, allowing for a personalized browsing experience.

Creating Filters

Filters in Adblock Plus are categorized into different types, each serving a unique purpose:

  1. Blocking Filters: These are used at the network level to decide whether a request to load certain content should be blocked. They are the first line of defense against unwanted content.

  2. Content Filters: Also known as hiding filters, these are often referred to as element hiding filters. They are used to hide specific elements on a webpage, such as intrusive ad banners or pop-ups.

  3. Exception Filters: These filters are crucial for allowing certain requests or unhiding elements on specific websites. They are used to override other filters based on specific conditions.

Both blocking and hiding filters can be overridden by exception filters, which act as a 'whitelist' under certain conditions.

Follow these steps to create your own filters in Adblock Plus:

  1. Access the Adblock Plus Settings page in your browser.

  2. For versions 3.4 and higher, supporting browsers like Chrome, Edge, Firefox, Opera, and Yandex Browser:

    • Click the Adblock Plus icon and select the gear icon in the upper-right corner.

    • Navigate to the Advanced tab and find 'Create and edit your filter list'.

    • Click 'Start creating my filter list', enter your filter, and hit 'Save'.

Basic Filter Rules

The simplest form of a filter is the address of the request you want to block. However, due to the dynamic nature of web addresses, it is often more effective to use more general filters. For instance, http://example.com/ads/banner*.gif blocks all GIF banners in the ads directory of example.com.

Note: Overusing wildcards can be counterproductive. For example, a filter like http://example.com/* could unintentionally block all content from 'example.com', including necessary website features.

Defining Exception Rules

Exception rules are essential when you find that a filter is blocking something it shouldn't. They allow you to define scenarios where the normal blocking rules should not apply. These rules are similar to regular filter rules and can include wildcards or regular expressions for flexibility.

Example 1: If your filter adv unintentionally blocks http://example.com/advice.html, you can create an exception rule @@advice to allow this specific page.

Example 2: Suppose a filter blocks access to http://example.com/admin. You can create an exception rule @@admin to ensure that this important administrative page remains accessible.

Matching at the Beginning or End of an Address

Adblock Plus generally interprets filters as having implied wildcards at the beginning and end. However, there are instances where you need a filter to match only at the start or end of an address.

Example 1: To block only Flash files and not HTML pages that contain 'swf' in their address, use a filter like swf|. This filter blocks http://example.com/annoyingflash.swf but not http://example.com/swf/index.html.

Example 2: If you wish to block a specific domain but not URLs containing that domain as a parameter, use a filter like |http://baddomain.example/. This filter blocks http://baddomain.example/banner.gif but not http://gooddomain.example/analyze?http://baddomain.example.

Marking Separator Characters

In some scenarios, you might need to allow any separator character in a filter. The caret symbol (^) is used as a placeholder for a single separator character in such cases.

Example: A filter like http://example.com^ effectively blocks both http://example.com/ and http://example.com:8000/, but not http://example.com.ar/.

Comments

Rules that start with exclamation marks (!) are considered comments and are ignored by Adblock Plus during the filtering process. Comments are useful for adding descriptions, notes, or authorship details to your filters.

Advanced Features

Specifying Filter Options

Adblock Plus allows you to specify additional options to modify the behavior of a filter. These options are appended after a dollar sign ($) at the end of the filter and separated by commas.

Example: /ads/*$script,match-case specifies that the filter /ads/* should apply only to scripts and be case-sensitive.

The available options include:

  • Type options: Specify the types of elements a filter can block, such as script, image, stylesheet, and others.

  • Inverse type options: Indicate what types of requests the filter should not apply to, like ~script, ~image, etc.

  • Restriction to third-party/first-party requests: Filters can be restricted to either third-party or first-party requests using third-party or ~third-party.

  • Domain restrictions: Filters can be restricted to specific domains using domain=example.com. You can specify multiple domains or exclude certain domains using ~.

  • Sitekey restrictions: These allow filters to be applied only to pages with a specific public key and signature.

Example: ||example.com/banner.gif$domain=example.com|example.net restricts the filter to example.com and example.net domains.

Content Security Policies

Content Security Policies (CSP) can be set via filters to control the type of content that is allowed to load on a webpage. This feature is crucial in preventing certain types of content from loading, thereby enhancing security and user experience.

Example: The filter option csp=script-src: 'none' injects a CSP header of script-src: 'none' into the matching filter requests, effectively blocking all scripts in the document. This is particularly useful when dealing with advanced ad circumvention techniques.

Redirecting Requests to Internal Resources

The rewrite= option allows you to redirect requests to internal resources, deactivating them without causing errors. This feature is useful for handling requests in a way that doesn’t break page functionality.

Example 1: The filter $rewrite=abp-resource:blank-js sends an empty JavaScript file in place of the original request. This can be used to neutralize JavaScript-based ads or trackers.

Example 2: For an image request, $rewrite=abp-resource:1x1-transparent-gif can replace it with a transparent 1x1 pixel GIF, effectively removing visual ads without affecting layout.

Using Regular Expressions

Adblock Plus supports regular expressions in filters, allowing for more complex and flexible matching patterns. Regular expressions are a powerful tool for creating precise filters.

Example 1: The regex filter /banner\d+/ matches any URL containing 'banner' followed by any digit, such as 'banner123'.

Example 2: To block URLs with specific file names, a regex like /\d{3}banner\.gif/ matches any '.gif' file name that starts with three digits and follows with 'banner'.

Special Comments

Special comments in Adblock Plus are used in downloaded filter lists to set parameters like the homepage, title, update interval, and version. These comments do not affect the actual blocking behavior but provide meta-information about the filter list.

Example: A comment like ! Expires: 5 days sets the update interval for the filter list to 5 days, ensuring the list is regularly updated for effectiveness.

Content Filters

Content filters are crucial for dealing with ads embedded as text in webpages. They include element hiding and snippet filters, which target specific elements or run code snippets to block complex ads.

Element Hiding Filters:

  • Basic Rules: Element hiding filters use CSS selectors to hide elements. They follow the structure <domains><separator><body>.

  • Limiting Rules to Certain Domains: You can specify domains to restrict the application of these rules.

  • Attribute Selectors: These are used when ads don’t have distinct IDs or classes. For example, ##div[title*="adv"] hides divs with titles containing 'adv'.

Snippet Filters:

  • Implementation: They allow running JavaScript code snippets on specified domains.

  • Example: A snippet filter like example.com#$#snippet would run the 'snippet' code on pages from 'example.com'.

Exception Rules:

  • Usage: These are used to deactivate existing rules on particular domains.

  • Example: The rule example.com#@#.textad deactivates the hiding rule for elements with class 'textad' on 'example.com'.

Last updated