Scriptlets
Scriptlets copied to clipboard
Add new scriptlet — for click action
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
)
https://github.com/NanoAdblocker/NanoCore2/blob/master/src/snippets.js, but any no have delay.
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.
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 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.
But set-cookie
will be useful in any case.
@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?
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.
ping
@ameshkov @slavaleleka No progress for a year. Do you need help for this scriplet?
@oleedd we are not sure about implementing such risky scriptlet
Why is it risky if only the AdGuard team uses it?
risky for third-party lists like EasyList and maybe hard move scriplet from privileges high to full.
Scriptlets are supposed to be useable by third party filter lists and that’s why we are very careful with that
It is not a problem because you can disable risky scriplets for third-party filters.
No one will check every hour to see if they're clicking right or wrong on something if list have high-profile privileges.
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.
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.
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.
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.
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.
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.
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
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:
- Add support for "trusted" filters to CoreLibs (and tsurlfilter): https://github.com/AdguardTeam/CoreLibs/issues/1612
- 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 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)}});
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)}});
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.
https://github.com/AdguardTeam/Scriptlets/commit/a93958afe779aa6d9ca6fd2f8b37b3035638efb3#diff-f932db8ef1d6b21e9a9d0dc47911293beb2f34b88ef481b58d3fc2d217e3177fR37
mixed - typo:
button[name='check"]