Writing Adblock plus Filters

Source: Internet
Author: User
ArticleDirectory
    • Basic Rules
    • Limiting rules to certain domains
    • Attribute selectors
    • Advanced selectors
    • Simplified element hiding syntax

[Use Adblock plus to edit filtering rules]

See the Chinese version below: (however, the Chinese version is not the latest version, and some rules are incorrect)

Http://code.google.com/p/adblock-chinalist/wiki/Writing_Adblock_Plus_filters

Original English version (recommended ):

Http://adblockplus.org/en/filters

Here is an example of text ad:

Im520 text ad removal exercise:

Ox.com # Div # ad_text

Or

Ox.com # Div. ad_text

It's easy to keep away from it. # indicates removing element ads. Div indicates the element Div. # ad_text and. ad_text indicate the elements whose ID and class are ad_text.

The following sections are used by individuals in the original English text:

Element hidingbasic rules

Sometimes you will find advertisements that can't be blocked because they are embedded as text in the web page itself. if you look at the source code of the web page you might find something like this:

< Div Class = " Textad " > Cheapest tofu, only here and now !   </ Div >   < Div ID = " Sorad " > Really cheap tofu, click here !   </ Div >   < Textad > Only here you Get The best tofu !   </ Textad >  

You need to download the web page so you will necessarily download the advertisements. all you can do here is to hide the advertisement so you don't need to see it. that's what element hiding is meant.

The first advertisement above is contained inside a div element with Class Attribute "textad". The following rule will hide exactly this combination:# Div. textad. Here # marks an element hiding rule while the rest is a selector identifying the elements that need to be hidden. You can hide elements by their ID attribute Similarly,# Div # SoradWill hide the second advertisement. You don't need to specify the element name, the rule##* # SoradWill work just as well. And you can hide elements by element name only, e.g.# TextadFor the third advertisement.

The element hiding helper extension helps selecting the correct element and writing the corresponding rule without having to view the source code of the page. Basic HTML knowledge is useful nevertheless.

Note: Element hiding works very differently from normal filters. This has the implication that No wildcards are supported in element hiding rules.

Limiting rules to certain domains

Usually you want to hide a specific ad on one specific site, you don't want your rule to be applied on other sites. For example the rule# *. Worker sorMight hide valid code on some sites. But if you write itExample.com # *. Worker sorIt will be applied onHttp://example.com/AndHttp://something.example.com/But not onHttp://example.org/. You can also specify multiple domains-simply separate them with commas:Domain1.example, domain2.example, domain3.example ## *. extends sor.

If a domain name is preceded "~ ", The rule willNotBe Applied on pages from this domain (requires Adblock plus 1.1 or higher). For example,~ Example.com # *. Worker sorWill be applied on pages from any domain but "example.com" andExample.com ,~ Foo.example.com # *. Worker sorMakes the rule apply on "example.com" domain with the exception of "foo.example.com" subdomain.

Note: Due to the way how element hiding is implemented, you really can only limit it to full domain names. You cannot use any other part of the address and you cannot useDomainAs a replacementDomain. example, domain. Test.

Note: Element hiding rules with domain limitation can be used to hide browser's user interface elements as well. For example the filter ruleBrowser # menuitem # javascriptconsoleWill hide the Javascript console entry in Firefox's Tools menu.

Attribute selectors

Some advertisers don't make it easy for you-their text advertisements have neither an ID nor a class attribute. You can use other attributes to hide those, for example# Table [width = "80%"]Will hide tables with width attribute set to 80%. If you don't want to specify the full value of the attribute,# Div [Title * = "adv"]Will hide all DIV elements with title attribute containing the string "adv". You can also check the beginning and the end of an attribute, for example# Div [Title ^ = "adv"] [Title $ = "ERT"]Will hide DIV elements with title starting with "adv" and ending with "ERT". As you see, you can also use multiple conditions-Table [width = "80%"] [bgcolor = "white"]Will match tables with width attribute set to 80% and bgcolor attribute set to white.

Advanced selectors

In general, any CSS selector supported by Firefox can be used for element hiding. For example the following rule will hide anything following a div element with Class "adheader ":# Div. adheader + *. For a full list of CSS list see W3C CSS specification (note that not all selectors are supported by Firefox yet ).

Note: This functionality is for advanced users only, you should be comfortable with CSS selectors to use it. adblock plus won't be able to check the syntax of the selector you are adding, if you use invalid CSS syntax you might break other (valid) rules you have. check JavaScript console for CSS errors.

Simplified element hiding syntax

Adblock plus supports simplified element hiding syntax (e.g.# Div (ID = Foo)) For backwards compatibility only. Using this syntax is discouraged, usual CSS selectors are preferred. Support for this syntax might be removed at some point.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.