Skip to content

Loading…

How do I write a Source Target filter #1383

Closed
davidhedlund opened this Issue · 20 comments

4 participants

@davidhedlund

I want twitter.com to be available but not from external domains. How do I define that twitter.com should not be allowed from example.com?

In RequestPolicy I can do this but I don't know if it's even possible in uBlock. I know this can be done from My Rules in uBlock but I wan't to do it from my filter instead, so it can be used for Adblock Plus too.

@hotdogman

I am by no means good at writing ABP filters, but I gave it a shot.
I don't like the "solution" I came up with, because it allows twitter.com/i/jot, which is supposed to be blocked by EasyPrivacy, Fanboy Annoyance, Fanboy Social, and Fanboy Ultimate.
||twitter.com^
@@||twitter.com$~third-party
Feel free to try for a better solution on your own.
https://adblockplus.org/en/filters
https://adblockplus.org/en/filter-cheatsheet

@davidhedlund

@hotdogman thank you but I need to block twitter.com from example.com. To give you an idea:

||example.com twitter.com^

@hotdogman

||twitter.com^ blocks all requests to twitter.com, from any website.
@@||twitter.com$~third-party allows all requests to twitter.com, from twitter.com.
~third-party means do not apply to third-party (only apply to first-party), and @@|| means allow

I need to block twitter.com from example.com

I believe the option you're looking for is $domain

https://adblockplus.org/en/filter-cheatsheet#options
Domain option
Domain option restricts the filter to a set of domains (here example.com). It also allows to disable the rule on dome domains (here on foo.example.com)
||ads.example.com^$domain=example.com|~foo.example.info

This should block all requests to twitter.com from example.com
||twitter.com^$domain=example.com

I repeat, I'm not good with writing filters, so take whatever I say with a grain of salt.

@davidhedlund

@hotdogman Yeah. Thank you once again.

@gorhill

I don't like the "solution" I came up with, because it allows twitter.com/i/jot

Could always use the important filter option to override the exception:

||twitter.com/i/jot$important
@hotdogman

Could always use the important filter option to override the exception

I believe @davidhedlund was looking for something that also works in ABP, which doesn't have support for $important.

@thegoodthings

||twitter.com^
@@||twitter.com$~third-party

Rather than block all twitter.com requests, then whitelist first-party, wouldn't a simpler ||twitter.com^$third-party rule work?

@hotdogman

Yes, yes it would.

@davidhedlund

@hotdogman @one23

How do I write filters to
1) Block ad_*_radomly_assigned_number.
2) Block everything in the entire HTML page except just the element "player".

<!DOCTYPE html>
<html lang="en" class="">
<head></head>
<body>

<div id="main">

<div id="ad_185_random_assigned_number">Ad goes here.</div>


<div id="player">Video player placed here</div>


<div id="ad_34_random_assigned_number">Ad goes here.</div>


</div>

</body>
</html>
@thegoodthings

@davidhedlund, you can use any valid CSS selector.

##[id^="ad_"] would work for your first example, although it would be expensive (considered a high-high generic), so I'd recommend you qualify it with a domain (e.g. example.com##[id^="ad_"]).

For your second, that's a task probably better suited to a user-script or similar, rather than uBlock.

@davidhedlund

@one23 Neat! Do you know how I block a file permanently from a domain?

Say example.com/spam.js

@thegoodthings

That's an easy one! Just add two pipes in front to block a specific domain/resource.
||example.com/spam.js

@davidhedlund

@one23 Thank you. I'm trying to learn new Adblock Plus filter techniques.

@thegoodthings

@davidhedlund No problem - glad I could help you!

You can always look at the default filter lists to see how they block certain things and use them as examples to make your own rules, and be sure to look at the links on filter syntax that @hotdogman posted earlier on this issue for even more info.

@davidhedlund

@one23

||a.b.c.domain.com^ did not block a.b.c.domain.com completely. How do I write a global block for a given sub domain?

@thegoodthings

What do you mean 'completely'? Filter ||a.b.c.domain.com^ should block all resources from 'a.b.c.domain.com'. If you are using this uBlock then the strict filtering feature of uBlock Origin won't be available, if that's what you're referring to.

@gorhill

Bad filter: ||http://a.b.c.domain.com/js/flipbook/flipbook_controller-min.js^.

Good filter: |http://a.b.c.domain.com/js/flipbook/flipbook_controller-min.js.

Read carefully the doc you linked to above, it explains what is || and ^.

@davidhedlund

@gorhill Thank you.

@davidhedlund

@gorhill @one23 I was just confused and posted an issue that describe that in #1385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.