Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Add new scriptlet — for click action

Open Alex-302 opened this issue 5 years ago • 26 comments

Purposes:

  • disabling adware loaders on file hosthings;
  • closing modal windows/forms which require user's action(for example, some GDPR notifications)

Example rules:

intoupload.net#%#AG_onLoad(function() { setTimeout(function() { $('#chkIsAdd').click(); }, 300); });
consent.yahoo.com#%#AG_onLoad(function() { setTimeout(function() { document.querySelector("button[name='agree']").click(); }, 300); });
ndcmediagroep.nl#%#AG_onLoad(function() { setTimeout(function() { var el = document.querySelector('input[type="submit"][value="Ja, ik ga akkoord"]'); if(el) el.click(); }, 300); });
dokterdokter.nl#%#AG_onLoad(function() { var el=document.querySelector('a.button[href*="acceptCookies=true"]'); if(el) el.click(); });
bnr.nl#%#AG_onLoad(function() { setTimeout(function() { if(window.location.href.indexOf("/cookiewall") != -1){ var el = document.querySelector('form[action="/acceptcookie"] > a[name="#cookiewall"].accept'); if(el) el.click(); }}, 300); });

For their work, it is necessary to check some conditions(location/part of URL, existence of cookie, checkbox status) and delay(setTimeout)

Alex-302 avatar Jun 05 '19 13:06 Alex-302

https://github.com/NanoAdblocker/NanoCore2/blob/master/src/snippets.js, but any no have delay.

krystian3w avatar Aug 10 '19 14:08 krystian3w

For similar purposes a scriptlet for set cookie could be implemented too. For example: https://www.theverge.com/2019/9/4/20849999/amazon-soundbar-nebula-fire-tv-cube-edition-new-announcements embedded video isn't shown if _chorus_privacy_consent doesn't exist.

superlex avatar Sep 05 '19 00:09 superlex

Unlike JS rules, we're going to allow scriptlets in third-party filter lists, and it bothers me that we would provide scriptlets THAT powerful and easy to misuse.

A set-cookie scriptlet, on the other hand, is not that bad, and it actually looks a lot like set-constant.

@Alex-302 could you please check these websites -- would it be enough to use smth like set-cookie?

ameshkov avatar Sep 06 '19 14:09 ameshkov

@ameshkov many sites(for example, Dutch) generate cookies with calculated value(name is also can be changed). Cookie with random value does not accepted by the site.

Alex-302 avatar Sep 06 '19 17:09 Alex-302

But set-cookie will be useful in any case.

Alex-302 avatar Sep 06 '19 17:09 Alex-302

@ameshkov

Unlike JS rules, we're going to allow scriptlets in third-party filter lists, and it bothers me that we would provide scriptlets THAT powerful and easy to misuse.

Uhm I understand the problem.. What about defining more powerful scriptlets as Privileged resources (similar to Nano Adblocker), maybe only available to AG own filter lists? Otherwise, maybe it could be better to define them as js rules like #%#AG_setCookie() ..

@Alex-302

many sites(for example, Dutch) generate cookies with calculated value(name is also can be changed)

Yep, you're right, unfortunately.. Btw, it looks like other sites don't check cookie value: for example, theverge generates the cookie with setCookie('_chorus_privacy_consent', token, 365 * 20); but then it checks it with

var existingConsent = /_chorus_privacy_consent=\d{13}-\w{32};/.test(document.cookie);
if (existingConsent) return done();

so cookie value isn't important (for this purpose, I don't know if it brokes other features).

PS: Is it possible to set existingConsent as true?

superlex avatar Sep 09 '19 00:09 superlex

What about defining more powerful scriptlets as Privileged resources (similar to Nano Adblocker), maybe only available to AG own filter lists?

This makes sense indeed.

ameshkov avatar Sep 09 '19 08:09 ameshkov

ping

Alex-302 avatar Feb 05 '20 15:02 Alex-302

@ameshkov @slavaleleka No progress for a year. Do you need help for this scriplet?

oleedd avatar Jun 22 '20 16:06 oleedd

@oleedd we are not sure about implementing such risky scriptlet

slavaleleka avatar Jun 22 '20 16:06 slavaleleka

Why is it risky if only the AdGuard team uses it?

oleedd avatar Jun 22 '20 16:06 oleedd

risky for third-party lists like EasyList and maybe hard move scriplet from privileges high to full.

krystian3w avatar Jun 22 '20 17:06 krystian3w

Scriptlets are supposed to be useable by third party filter lists and that’s why we are very careful with that

ameshkov avatar Jun 22 '20 17:06 ameshkov

It is not a problem because you can disable risky scriplets for third-party filters.

oleedd avatar Jun 22 '20 17:06 oleedd

No one will check every hour to see if they're clicking right or wrong on something if list have high-profile privileges.

krystian3w avatar Jun 22 '20 17:06 krystian3w

I don't understand what you mean. I mean that risky (unsafe) scriplets may be forbidden for third-party filters. It is better than nothing.

oleedd avatar Jun 22 '20 17:06 oleedd

It is not a problem because you can disable risky scriplets for third-party filters.

Yeah, well, that's what we would like to avoid -- adding another layer of complexity by dividing scriptlets into risky and not that risky.

If you want this for your own filter list - you can use good old JS rules just like @Alex-302 examples. This type of rules is allowed in the user filter or in trusted custom lists.

ameshkov avatar Jun 22 '20 18:06 ameshkov

In this case, you should decide at opening an issue - will be a scriplet implemented or not. The thing is someone don't want to fix some issues because this scriplet isn't ready.

oleedd avatar Jun 22 '20 18:06 oleedd

I'd like to keep such issues open just to keep track of them.

This helps us understand which rules are problematic and cannot be replaced by the current scriptlets lib.

ameshkov avatar Jun 22 '20 19:06 ameshkov

We needed something that could be used by third-party lists. Second, scriptlets are easier to understand for an average filters maintainer. And third, unlike JS rules, it will still be possible to continue using scriptlets in the Chrome extensions after Google switches to Manifest V3.

ameshkov avatar Jun 22 '20 19:06 ameshkov

https://www.ptt.cc/bbs/Gossiping/index.html This site will still jump into a verification page even if over18=1 is pre-set.

www.ptt.cc#%#//scriptlet('set-cookie-reload','over18','1')

So I still need to manually click "Yes" once when I first enter the page.

bestpika avatar Mar 09 '21 06:03 bestpika

Scriptlet wasn't published for addons (also signed beta releases from ~21 December 2020): https://github.com/AdguardTeam/Scriptlets/issues/111 (end of work in January 2021).

Maybe possible use in beta/alpha apps:

  • https://adguard.com/en/beta.html
  • https://adguard.com/zh_cn/test.html

Look here if any Filter "list" started accept 18+ walls: https://github.com/AdguardTeam/FiltersCompiler/issues/99

krystian3w avatar Mar 09 '21 07:03 krystian3w

It seems that auto-clicking is one of the most popular custom JS rules that we have.

Here's what we'll do about that:

  1. Add support for "trusted" filters to CoreLibs (and tsurlfilter): https://github.com/AdguardTeam/CoreLibs/issues/1612
  2. As a temporary solution for existing JS rules that use click() we'll come up with a helper JS function that can be used in AdGuard filters exclusively. Once the scriptlet is ready, we'll simply replace these rules with the new scriptlet rules.

@Alex-302 @AdamWr please help me locating those rules so that we could come up with a good JS helper.

ameshkov avatar Mar 16 '22 08:03 ameshkov

@ameshkov maybe something like that(condition with cookie or URL part + MutationObserver with timeout)

#%#AG_onLoad(function() {var b=new MutationObserver(function() {var c=document.querySelector('button[title="Akzeptieren"]'); c&&(b.disconnect(),c.click()) });b.observe(document, {childList: !0,subtree: !0});setTimeout(function() {b.disconnect()}, 1E4)});
#%#AG_onLoad(function(){if(window.location.href.includes("consentUUID")){var g=new MutationObserver(function(){var b=document.querySelector('button[title*="Accepter" i]');b&&(g.disconnect(),b.click())});g.observe(document,{childList:!0,subtree:!0});setTimeout(function(){g.disconnect()},1E4)}});

Alex-302 avatar Mar 16 '22 20:03 Alex-302

In some cases a rule with a click on an element does not work or works incorrectly. The item is detected in the console, but no click occurs through the rule.

For example:

https://www.lvz.de/

not working:

#%#AG_onLoad(function() {var b=new MutationObserver(function() {var c=document.querySelector('button[title="Alle akzeptieren"]'); c&&(b.disconnect(),c.click()) });b.observe(document, {childList: !0,subtree: !0});setTimeout(function() {b.disconnect()}, 1E4)});

working correctly:

#%#AG_onLoad(function(){if(window.location.href.match(/consentUUID|privacy/)){var b=new MutationObserver(function(){var a=document.querySelector('button[title="Alles ablehnen"]');a&&(b.disconnect(),a.click())});b.observe(document,{childList:!0,subtree:!0}),setTimeout(function(){b.disconnect()},1E4)}});

jellizaveta avatar Sep 23 '22 10:09 jellizaveta

https://github.com/AdguardTeam/Scriptlets/issues/23#issuecomment-1256065149 I guess it's related to the conditions and we had similar rules instead of one. So, if we want to click several elements, it should be handled in one rule and function.


The clicker rule should accept Regex in conditions.

zloyden avatar Sep 23 '22 11:09 zloyden

https://github.com/AdguardTeam/Scriptlets/commit/a93958afe779aa6d9ca6fd2f8b37b3035638efb3#diff-f932db8ef1d6b21e9a9d0dc47911293beb2f34b88ef481b58d3fc2d217e3177fR37

mixed - typo:

button[name='check"]

krystian3w avatar Dec 13 '22 10:12 krystian3w