[Suggestion] Conditionals

Various discussions related to Adblock Plus development
Post Reply
chris13524
Posts: 1
Joined: Mon Mar 14, 2016 3:37 am

[Suggestion] Conditionals

Post by chris13524 »

I don't think it is possible currently, but is it possible to have conditions? As an example use, say you want to only show ads on YouTube channels you are subscribed to. This could be easily accomplished by checking if the document contains "data-is-subscribed="true"". If it doesn't, remove ads.

I'm not really familiar with the Adblock rule syntax, but I'm thinking this could be added right in the filter rule. In addition to doing the kind of "regex" pattern thing for the domain, conditions could be added as well. The usual ||, &&, and ! could be used. Something such as "youtube.com && $document.contains(data-is-subscribed="true")" would be sufficient to define an exception rule. Of course the syntax would have to be adjusted for backwards compatibility and stuff.
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: [Suggestion] Conditionals

Post by lewisje »

I'm tempted to link yet again to the old thread about the HTML filtering suggestion, which was rejected for performance reasons, but instead I should say that it's difficult to figure out how to implement this in a way that isn't ad-hoc (for example, not relying on implicit assumptions about the particular setup of particular websites at a particular time) and is secure (something like $condition=(<boolean-coercible JS expression>) could be a nasty vector for code injection, but maybe that could be mitigated by only supporting it in custom filters).

Reading the cookies or localStorage set by a website might work, and I could imagine a restricted key-value syntax working for that, like

Code: Select all

$condition(<key>=<value)
$condition(<key>!=<value>)
$condition(<key>$=<partialValue>&&<key>^=<partialValue2>||<key2>*=<partialValue3>)
etc., and I see that the Chrome extension, at least, has the necessary permissions to read cookies and localStorage.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
choice
Posts: 1
Joined: Sun Apr 24, 2016 1:07 pm

Re: [Suggestion] Conditionals

Post by choice »

I've thought the same thing and looked into the source to try and implement a youtube subscription conditional.
An acceptable set-up for this would be chained filters.
Currently the following works (hides the subscription button if you have subscribed):

Code: Select all

##.yt-uix-subscription-button[data-is-subscribed="True"]
Now, If you define a new type of filter regex that implements chaining (for example's sake, let's set the chaining separator to

Code: Select all

;
, meaning the last matcher will be used and applied, we could do something like:

Code: Select all

##.yt-uix-subscription-button[data-is-subscribed="True"];@@||youtube.com^$document
.

If someone from the devs could give me pointers on how to approach chainability (I should create a new Regexp type, along with implementing it in filterNotifier if I've understood things correctly), I think we could figure out a solution that isn't horribly ugly and helps people help content creators (I'm not a content creator myself, but I'd love to have this as a possibility).

Things to consider:
Should the second matcher have domain options? I think maybe not, mainly because of weird override scenarios and legiibilty, so you'd define the domain before the first selector:

Code: Select all

||youtube.com##.yt-uix-subscription-button[data-is-subscribed="True"];@@^$document
However, all of the filter creation isn't well documented so I might be misinterpreting some of your syntax.

I'd love to get feedback and input from devs on this.
User avatar
mapx
Posts: 21940
Joined: Thu Jan 06, 2011 2:01 pm

Re: [Suggestion] Conditionals

Post by mapx »

The devs can be contacted on their irc channel
blog/adblock-plus-development-irc-channel-is-now-open

You can file an issue ("change" type) on the bug tracker
https://issues.adblockplus.org

adblock plus on github ==> https://github.com/adblockplus/
Post Reply