필터 작성 방법

애드블록 플러스의 현재 버전은 다양한 방식으로 필터를 "조정"할 수 있습니다. 이 문서는 현재 지원하는 필터의 옵션을 설명하고 있습니다.

선언 : 아래의 설명에 사용된 예시는 실제 사용된 사례와 관계없는 단순한 예시일뿐입니다.

애드블록 플러스 필터 소개

이 설명에서 소개된 옵션은 필터를 작성하려는 사용자에게 충분할 것입니다.

차단 필터

정의할 수 있는 대부분의 필터는 차단하려는 배너의 주소일 것입니다. 하지만 종종 이 주소는 페이지를 열 때마다 변경되기도 합니다. 예를 들어 배너의 주소가 http://example.com/ads/banner123.gif일 때 123은 임의의 숫자일 수 있습니다. 그리고 배너의 주소와 완전히 같은 필터는 도움이 되지 못하며, http://example.com/ads/banner*.gifhttp://example.com/ads/* 등의 필터에 의해 차단됩니다.

참고: 와일드 카드 문자에 의해 너무 많은 것을 대체할 수 없다는 것을 확인하십시오. 필터 http://example.com/*는 확실히 모든 배너를 차단하겠지만 example.com에서 보고자 하는 다른 모든 것들도 차단할 것입니다.

허용 필터

차단 필터로 인해 차단되지 않아야 할 콘텐츠가 차단되었을 때 사용하는 필터입니다. 문제를 일으키는 필터를 제거하지 않않아도 필터가 특정 주소에 적용되지 않도록 필터를 정의합니다.

필터를 적용해서는 안 되는 경우에 허용 필터가 필요합니다. 예를 들어 adv라는 필터가 http://example.com/advice.html를 차단해서 불편할 때 @@advice라는 허용 필터를 정의할 수 있습니다. 허용 필터는 차단 필터와 다르지 않으며 와일드 카드 문자 또는 정규 표현식을 사용할 수 있습니다. 허용 필터의 형식은 주소와 일치하는 부분 앞에 @@를 붙입니다.

Exception rules can do more. If you specify $document option you will get an exception for the entire page. For example, if your exception rule is @@||example.com^$document and you open some page from example.com — Adblock Plus will be entirely disabled on this page and nothing will be blocked.

주소 시작/끝 부분에 필터 일치

보통 애드블록 플러스는 모든 필터를 마치 필터의 시작과 끝에 와일드 카드 문자가 있는 것처럼 처리합니다. 필터 ad*ad*는 차이가 없고, 문제를 일으키지 않습니다. 그렇지만 주소의 시작 또는 끝에 필터를 일치하게 정의하고 싶을 때가 있습니다. 예를 들어 모든 플래시를 차단하려고 할 때 필터 swf를 추가하면 되지만 http://example.com/swf/index.html도 역시 차단될 것입니다.

이 문제에 대한 해결책은 파이프 기호를 필터 끝부분에 추가하여 주소과 일치하게 정의하는 것입니다. 예를 들어 필터 swf|http://example.com/annoyingflash.swf와 일치하지만 http://example.com/swf/index.html와는 일치하지 않습니다. 그리고 필터 |http://baddomain.example/http://baddomain.example/banner.gif와 일치하지만 http://gooddomain.example/analyze?http://baddomain.example 등의 필터에 의해 차단됩니다.

때때로 어떤 사용자는 http://example.com/banner.gif는 물론이고, https://example.com/banner.gifhttp://www.example.com/banner.gif도 차단하고 싶어합니다. 이것은 필터와 도메인 이름의 시작 부분에 일치하는 두 개의 파이프 기호를 필터의 맨앞에 붙임으로써 가능합니다. 필터 ||example.com/banner.gif는 같은 모든 주소를 차단하는 반면에 http://badexample.com/banner.gif 또는 http://gooddomain.example/analyze?http://example.com/banner.gif는 차단하지 않습니다 (애드블록 플러스 1.1 이상).

구분자 문자의 사용

필터에서 어떤 구분자 문자를 종종 허용해야 할 필요가 때가 있습니다. 예를 들어 http://example.com/http://example.com:8000/는 차단하지만 http://example.com.ar/는 차단하지 않는 필터를 작성할 수 있습니다. 이 때 ^ 기호는 단일한 구분자 문자를 위한 플레이스 홀더(빠져 있는 다른 것을 대신하는 기호나 텍스트의 일부)로서 사용되며, 필터 http://example.com^를 작성하면 됩니다 (애드블록 플러스 1.1 이상).

구분자 문자는 하나의 문자나 숫자 그리고 _ - . % 와 같은 일부 특수 문자를 제외한 모든 문자입니다. 주소의 끝은 역시 구분자로서 간주합니다. 다음의 예는 모든 구분자 문자가 빨간 글자로 표시되어 있습니다. http://example.com:8000/foo.bar?a=12&b=%D1%82%D0%B5%D1%81%D1%82. 그래서 이 주소는 ^example.com^ 또는 ^%D1%82%D0%B5%D1%81%D1%82^ 또는 ^foo.bar^ 등의 필터에 의해 차단됩니다.

주석

구독 필터의 이름, 필터 유지자, 저작권, 연락처, 구독 필터 정보, 필터에 대한 부가 설명 등 정보를 추가하기 위해 주석을 사용합니다. 느낌표(!)로 시작하는 줄의 모든 문자열은 주석으로 취급되며, 필터 목록에서 회색 글자로 나타납니다. 애드블록 플러스는 필터링 과정에서 일반 필터와 달리 주석은 무시합니다.

Special comments

Special comments will only have an effect in downloaded filter lists, not in custom filters. Special comments must be given at the top of the filter list right below the header. They can set a number of parameters for the filter list:

고급 기능

이 영역에서 설명하는 기능은 보통 고급 사용자나 필터 유지자에 의해 사용됩니다. 이 영역은 건너뛰어도 좋습니다.

필터 옵션 지정

필터의 동작을 변경하기 위해 많은 옵션을 선택할 수 있고, 형식은 필터 끝에 달러 기호($)를 붙이고 옵션을 덧붙입니다. 옵션이 여러 개일 때는 옵션을 쉼표(,)로 구분합니다.

*/ads/*$script,match-case

예를 들어 */ads/*라는 필터가 있고, scriptmatch-case에 관한 옵션을 적용하였습니다.

정규 표현식의 사용

필터의 주소 일치 여부를 더욱 섬세하게 통제하려면 정규 표현식을 사용할 수 있습니다. 예를 들어 필터 /banner\d+/banner123banner321와 일치하지만 banners와는 일치하지 않습니다. 정규 표현식의 작성 방법을 배우려면 정규 표현식에 관한 문서를 검토하십시오.

참고: 필터 처리의 이유로 정규 표현식을 가급적 사용하지 않는 것을 권장합니다.

요소 숨김 필터

일반 선택자

때때로 차단할 수 없는 광고를 발견할 것입니다. 왜냐하면 그것들은 웹 페이지 자체에 텍스트로서 포함되어 있기 때문입니다. 만약 웹 페이지의 소스 코드를 보게 된다면 다음과 같은 것을 발견하게 될 것입니다.

<div class="textad">
Cheapest tofu, only here and now!
</div>
<div id="sponsorad">
Really cheap tofu, click here!
</div>
<textad>
Only here you get the best tofu!
</textad>

웹 페이지를 다운로드할 필요가 있고 광고는 어쩔 수 없이 다운로드됩니다. 이 때 할 수 있는 일은 광고를 숨겨서 그것을 보지 않을 수 있습니다. 요소 숨김이 의미하는 것은 다음과 같습니다.

위의 첫번째 광고는 class 속성이"textad"인 div 요소 내부에 포함되어 있습니다. 필터 ##.textad는 정확히 이 조합을 숨길 것입니다. 여기서 ##는 요소 숨김 필터를 표시하며 반면에 나머지는 숨길 요소를 확인하는 선택자입니다. 이와 마찬가지로 id 속성에 의해 요소를 숨길 수 있습니다. ###sponsorad는 두번째 광고를 숨길 것입니다. 그리고 요소 이름을 지정할 필요는 없습니다. 마찬가지로 필터 ##textad는 작동할 것입니다. 오직 요소 이름에 의해 요소를 숨길 수 있습니다. 예를 들어 {4}는 세번째 광고를 숨기게 됩니다.

부가 기능 Element Hiding Helper는 올바른 요소를 선택할 수 있게 도우며, 페이지의 소스 코드를 보지 않고도 대응하는 필터를 작성할 수 있습니다. 그럼에도 불구하고 기본 HTML 지식은 유용합니다.

참고 : 요소 숨김은 차단 필터와 전혀 다르게 작동합니다. 그래서 요소 숨김 필터는 와일드 카드 문자를 지원하지 않습니다.

특정 도메인에 필터 한정

필터가 다른 사이트에는 적용되지 않고 지정한 사이트의 특정 광고를 숨기길 원합니다. 예를 들어 필터 ##.sponsor는 몇몇 사이트의 일치하는 요소를 숨깁니다. 그러나 example.com##.sponsor와 같이 필터를 작성하면 http://example.com/http://something.example.com/에는 적용하지만 http://example.org/에는 적용되지 않습니다. 또한 domain1.example,domain2.example,domain3.example##.sponsor 등의 필터에 의해 차단됩니다.

도메인 이름 앞에 "~"가 붙으면 필터는 이 도메인의 페이지에는 적용되지 않습니다 (애드블록 플러스 1.1 이상). 예를 들어 ~example.com##.sponsor는 "example.com"를 제외한 모든 도메인의 페이지에 적용됩니다. 그리고 example.com,~foo.example.com##.sponsor는 하위 도메인 "foo.example.com"를 제외한 도메인 "example.com"에만 적용됩니다.

참고 : 요소 숨김이 실행되는 방식 때문에 모든 도메인 이름에 필터를 한정할 수 있습니다. 주소에서 도메인 이름 이외의 부분을 이용할 수 없으며, 또한 다음 예시처럼 domain 부분으로 domain.example,domain.test를 대체할 수 없습니다.

참고: 도메인을 한정하는 요소 숨김 필터는 브라우저의 사용자 인터페이스 요소를 숨기기 위해 사용될 수도 있습니다. 예를 들어 필터 필터 browser##menuitem#javascriptConsole는 파이어폭스의 도구 메뉴에서 자바스크립트 콘솔 항목을 숨깁니다.

속성 선택자

일부 광고는 텍스트 광고에 id나 class 속성이 없습니다. 그래서 width가 80%인 표를 숨기기 위한 ##table[width="80%"]와 같이 다른 속성들을 이용할 수 있습니다. 만약 문자열 "adv"를 포함하는 title 속성의 모든 div 요소를 숨기기 위한 ##div[title*="adv"]와 같이 속성의 모든 값을 지정하고 싶지 않으면 속성의 시작과 끝 부분을 확인하면 됩니다. 예를 들어 ##div[title^="adv"][title$="ert"]는 "adb"로 시작하고, "ert"로 끝나는 div 요소를 숨깁니다. 보시다시피 width 속성이 80%이고, bgcolor 속성이 white인 표와 일치하는table[width="80%"][bgcolor="white"]처럼 다양한 조건을 이용할 수도 있습니다.

고급 선택자

일반적으로 어떤 파이어폭스에서 지원하는 CSS 선택자는 요소 숨김을 위해 사용됩니다. 예를 들어 ##.adheader + * 필터는 class가 "adheader"인 div 요소 다음에 오는 어떤 요소를 숨깁니다. CSS 목록의 전체 목록은 W3C CSS 규격을 참고하십시오 (파이어폭스에서 아직 모든 선택자를 지원하지 않음). Please keep in mind that browsers are slower to process these selectors than selectors based on class or id attribute only.

참고 : 이 기능은 고급 사용자만을 위한 것입니다. 그것을 사용하기 위해 CSS 선택자와 호환되어야 합니다. 애드블록 플러스는 작성한 선택자의 구문을 확인할 수 없습니다. 만약 틀린 CSS 구문을 사용하면 다른 타당한 필터에도 부정적인 영향을 끼칩니다. CSS 오류에 대한 자바스크립트 콘솔을 확인하십시오.

Extended CSS selectors (Adblock Plus specific)

Sometimes the standard CSS selectors aren't powerful enough to hide an advertisement. For those cases we have added some new selectors, namely :-abp-has(), :-abp-contains() and :-abp-properties() (requires Adblock Plus 1.13.3 or higher for Chrome and Opera).

When writing an element hiding filter that makes use of these extended selectors you must use the #?# syntax, e.g. example.com#?#selector. But it's important to note that doing so carries a performance impact, so do so sparingly and make sure those filters are specific to as few domains and elements as possible.

:-abp-properties()

:-abp-properties(properties) will select elements based upon stylesheet properties. For example :-abp-properties(width:300px;height:250px;) will select elements that have a corresponding CSS rule in a stylesheet which sets the width and height to the values 300px and 250px respectively. Property names are matched case-insensitively. Furthermore, wildcards can be used so that :-abp-properties(width:*px;height:250px;) will match any width specified in pixels and a height of 250 pixels.

You can also use regular expressions by surrounding the properties expression with "/". For example, :-abp-properties(/width:30[2-8]px;height:250px;/) will match widths between 302 and 308 pixels and a height of 250 pixels.

Note: The older syntax for the CSS property filters is deprecated and will be automatically converted to the new format . The syntax to select the style properties remain the same. For example, [-abp-properties='width:300px;height:250px;'] will be converted to :-abp-properties(width:300px;height:250px;).

:-abp-properties() will also select elements using the style properties found in their pseudo-elements, like ::before and ::after. For example, :-abp-properties(content:'Advertisment') will match elements where the string Advertisment is found in either their ::before or ::after pseudo element.

:-abp-has()

:-abp-has(selector) will select elements based on their content. For example :-abp-has(> div > a.advertiser) will select elements that contain as a direct descendant a <div> that contains an <a> with the class advertiser. The inner selector can be relative to the element scope, and can use any of the pseudo-selectors, including :-abp-has() and will determine whether the selection will occur.

:-abp-contains()

:-abp-contains(text) will select elements based on their text content. For example, div.sidebar > span:-abp-contains(Advertisment) will select the <span> elements within a <div>, with a class of sidebar that contains the word "Advertisment". In practice, you'd want to combine this with a :-abp-has() to select the outer container — something like div.sidebar > div:-abp-has(span:-abp-contains(Advertisment)) to select the container that would contain an advertisement label.

허용 필터

허용 필터는 특정 도메인에 적용된 필터를 사용 중지시킵니다. 이 필터는 필터 목록을 변경할 수 없는 구독 필터를 적용할 때 대체로 유용합니다. 예를 들어 필터 ##.textad는 도메인 example.com에서 example.com#@#.textad와 같이 허용 필터를 작성합니다. ##div.textad와 example.com#@#div.textad는 단일한 필터 ~example.com##.textad와 같은 효과를 냅니다. 일반 요소 숨김 필터를 변경할 수 없을 때만 허용 필터를 사용할 것을 권장하며, 특별히 필요한 도메인에 한정해서 허용 필터를 적용해야 할 경우에도 바람직합니다. These exceptions will be applied to advanced pseudo-selector rules as well.

Generic / Specific filters

With the $generichide and $genericblock filter options the distinction between generic and specific filters becomes important.

We classify a filter to be specific if it matches one or more domains or matches a sitekey. If a filter has no domains specified (or only domain exceptions) and no sitekey then it counts as generic. For example, example.com##.textad is a specific filter, whereas both ##.textad and ~example.com##.textad are generic.

Note that with blocking rules the domain must be specified under the $domain option for them to be considered specific. For example, ||example.com^ is considered generic whereas */ads/*$domain=example.com is site-specific.

Implementing a sitekey on the server

For a sitekey-restricted filter to apply, a webpage needs to return base64-encoded versions of the public key and a signature which Adblock Plus can validate. Currently, this means including them in both the HTTP response header (X-Adblock-Key: abcdpublickeydcba_abcdsignaturedcba) and the root tag of the document (<html data-adblockkey="abcdpublickeydcba_abcdsignaturedcba">).

First you need to create a private RSA key (preferably 512 bit to keep the transfer volume low) and then a DER representation of the public key.

The data used for creating the signature is a concatenated list of request variables (namely URI, host and user agent) separated by the NUL character "\0". For example:

  /index.html?q=foo\0www.example.com\0Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0

Finally, generate the signature for this string by using the signature algorithm SEC_OID_ISO_SHA_WITH_RSA_SIGNATURE (default when using OpenSSL).