Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Add new scriptlet — trusted version of `set-constant` for none-predefined values

Open AdamWr opened this issue 4 years ago • 8 comments

Some of AG_defineProperty rules can't be converted to scriptlets, because in set-constant scriptlet we can use only predefined values, so I think that it would be nice if could use not only predefined values.

For example, maybe adding something like #%#//ag-scriptlet will be okay and it will be restricted to use it only in AdGuard filters, the same like $replace and other JS (#%#) rules. example.org#%#//ag-scriptlet("set-constant", "property", "value")

https://github.com/AdguardTeam/AdguardFilters/issues/88860

! Can't be changed to scriptlet, because in scriptlet we can use only predefined values, so it can't be set to "FREECONTENT"
fashion.appledaily.com.tw#%#AG_defineProperty('options.subscriptionContent', { value: "FREECONTENT" });

! typeof salon_config.live_ads is a "string", so it can't be changed to a scriptlet
salon.com#%#AG_defineProperty('salon_config.live_ads', {value: "0"});

! Can't be changed to scriptlet, because in scriptlet we can use only predefined values, so it can't be set to "no"
ultimedia.com#%#AG_defineProperty('dtkPlayer.infos.autoplay', {value: "no"});

! Probably it will be possible to change this rule to scriptlet when this issue will be fixed - https://github.com/AdguardTeam/Scriptlets/issues/65
pewgame.com#%#AG_defineProperty('app_vars.counter_value', {value: 5, writable: false});

! Can't be changed to scriptlet, because in scriptlet we can use only predefined values, so it can't be set to "document.location.protocol"
tnaflix.com#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });
pussyspace.com,pussyspace.net#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });
nakedteens.fun#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });
letfap.com#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });
zbporn.com#%#AG_defineProperty('exoDocumentProtocol', { value: document.location.protocol });
porndroids.com#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });

! Can't be changed to scriptlet, because in scriptlet we can use only predefined values, so it can't be set to "none"
gameflare.com#%#AG_defineProperty('GameflareAsdk.config.advert.network', {value: "none"});

AdamWr avatar Aug 05 '21 13:08 AdamWr

we will add new scriptlet agtrusted-set-constant to avoid predefined values due to https://github.com/AdguardTeam/Scriptlets/issues/106

slavaleleka avatar Aug 05 '21 13:08 slavaleleka

Before we do that, are you sure there're no alternative solutions on all these websites?

ameshkov avatar Aug 05 '21 22:08 ameshkov

We have alternative solutions for most of these rules, but sometimes it's not easy to find them and sometimes there may not be alternative solution (with current scriptlets).

AdamWr avatar Aug 06 '21 09:08 AdamWr

The thing is that JS rules will be fully deprecated rather soon so we'd better find ones:)

ameshkov avatar Aug 06 '21 09:08 ameshkov

We have a lot of JS rules, for example with AG_onLoad function, so it doesn't sound good.

AdamWr avatar Aug 06 '21 09:08 AdamWr

Yep, we should gradually remove them all

ameshkov avatar Aug 06 '21 10:08 ameshkov

! typeof salon_config.live_ads is a "string", so it can't be changed to a scriptlet salon.com#%#AG_defineProperty('salon_config.live_ads', {value: "0"});

so we need a possibility to set the needed type of value?

slavaleleka avatar Oct 13 '22 16:10 slavaleleka

#%#AG_defineProperty('exoDocumentProtocol', { value: window.document.location.protocol });

if I got it correctly, for such cases we need to get the value of window.document.location.protocol first, and after that to set the value to exoDocumentProtocol, right?

slavaleleka avatar Oct 13 '22 16:10 slavaleleka

The thing is that JS rules will be fully deprecated rather soon we should gradually remove them all

I'm curious about the reason. add-on store policy?

MasterKia avatar Apr 12 '23 15:04 MasterKia

Bad link, incompatible with Firefox and Safari without Google WebExtension (If these fails: https://addons.mozilla.org/en-US/firefox/addon/link-to-text-fragment/ may need rewrite origin CRX to XPI or user script for Tampemonkey/Violentmonkey/Greasymonkey: https://chrome.google.com/webstore/detail/link-to-text-fragment/pbcodcjpfjdpcineamnnmbkkmkdpajjg).

https://developer.mozilla.org/en-US/docs/Web/Text_fragments#browser_compatibility

krystian3w avatar Apr 13 '23 06:04 krystian3w