Skip to content
 
 

Latest commit

 

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP parser for Adblock Plus filters

Master Build Status

This is a fork of the abandoned Limonte\AdblockParser.

It has been edited to optimize performance, namely:

  • The object containing the rules can be saved to avoid the long time to create it.
  • Only run necessary rules; the generic rules and the rules applying specifically to the domain of the url.

It also separates responsibilities of classes better by having factories, services and DTOs.

Usage

To learn about Adblock Plus filter syntax check these links:

  1. Get filter rules somewhere: write them manually, read lines from a file downloaded from EasyList, etc.:

    $adblockEntries = [
        "||ads.example.com^",
        "@@||ads.example.com/notbanner^$~script",
    ];
  2. Create AdblockRules instance from the rules array:

    use Limonte\AdblockParser;
    
    $ruleAggregate = (new RuleAggregateFactory(new RuleFactory()))->createFromAdblockEntries($adblockEntries);
  3. Use this instance to check if an URL should be blocked or not:

    (new RuleApplier())->shouldBlock("http://ads.example.com", $ruleAggregate); // true
    (new RuleApplier())->shouldBlock("http://non-ads.example.com", $ruleAggregate); // false

Related projects


About

PHP parser for Adblock Plus filters

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages