Skip to content

brk0v/adblock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdBlock

adblock is a package for working with Adblock Plus filter rules. It can parse Adblock Plus filters and match URLs against them.

Install

$ go get -u github.com/bluele/adblock

Examples

package main

import (
  "fmt"
  "github.com/bluele/adblock"
)

func main() {
  ab, err := adblock.NewRules([]string{
    "||google.com/ads/$domain=black.example.com",
    "||example.com/",
    "@@||example.com/white/",
  }, nil)
  if err != nil {
    panic(err)
  }

  fmt.Println("http://google.com/ads/app.js", ab.ShouldBlock("http://google.com/ads/app.js", map[string]interface{}{
    "domain": "white.example.com",
  }))
  fmt.Println("http://google.com/ads/app.js", ab.ShouldBlock("http://google.com/ads/app.js", map[string]interface{}{
    "domain": "black.example.com",
  }))
  fmt.Println("http://example.com/", ab.ShouldBlock("http://example.com/", nil))
  fmt.Println("http://example.com/white/", ab.ShouldBlock("http://example.com/white/", nil))
}

Result:

http://google.com/ads/app.js false
http://google.com/ads/app.js true
http://example.com/ true
http://example.com/white/ true

Dependency

Author

Jun Kimura

About

Golang parser for Adblock Plus filters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.4%
  • Makefile 0.6%