TechnikEmpire / DistillNET

DistillNET is a library for matching and filtering HTTP requests and HTML response content using the Adblock Plus Filter format.
Mozilla Public License 2.0
16 stars 4 forks source link

DistillNET Example #18

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hello, could you please provide an example of how to implement DistillNET? I downloaded the project, studied the coded for a while, but no luck till now. Maybe an example would help.

Thanks, Antony

TechnikEmpire commented 6 years ago

@sola-fide What are you trying to accomplish? Did you see the test project in the repo? It demonstrates loading and executing complex URL filters, even Adblock plus filters.

ghost commented 6 years ago

I am trying to combine your project with CefSharp in order to remove advertisements from websites. Yes, I did see the test project.

TechnikEmpire commented 6 years ago

@sola-fide Do you know how to hook into CefSharp to gain the ability to inspect URL's before navigation occurs and then be able to either stop or permit that navigation? I'm trying to find out what specifically you're having a hard time with, because the sample application shows very simply how to load adblock plus easylist and then also check a url to see if it should be blocked or not based on the rules loaded.

ghost commented 6 years ago

Yes, I've managed to get all links of a website. However I'm still trying to filter them through DistillNET.

TechnikEmpire commented 6 years ago

@sola-fide If you're trying to filter out CSS objects, DistillNET does not yet filter CSS. It only filters URLs.

So, to filter all URLS (including resources being loaded), you'd create a custom RequestHandler:

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/Handlers/RequestHandler.cs

Then you'd use the DistillNET methods you see being called in the test program where you're simply checking to see if a URL should be blocked based on rules you've already loaded. If you get a result saying true, that it should be blocked, well then follow the CefSharp document for cancelling a load or navigation request.

Take note of OnBeforeResourceLoad where you can return CefReturnValue.Cancel, for example.

All the best with your project.