AdguardTeam / AdguardTeam/Scriptlets

Improve 'trusted-replace-argument' — add new constant values

Đang mở
#562 0 bình luận 0 reaction 1 người được giao Được @maximtop nhận Xem trên GitHub
Priority: P4
Ngôn ngữ chính
JavaScript
Star
195
Fork
33
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Related to https://github.com/AdguardTeam/AdguardFilters/issues/232621

Steps to reproduce:
1. Add to user rules:
```adblock
example.org#%#//scriptlet('trusted-replace-argument', 'Promise', '0', 'noopPromiseResolve', 'isDetected')
```
2. Navigate to https://example.org/
3. In browser console run:
```js
(async () => {
const checkAdblock = () => {
console.log('Checking for adblock...');
return new Promise((resolve) => {
// Set to true by default for demonstration purposes
const isDetected = true;
resolve(isDetected);
});
};

const init = async () => {
const [result] = await Promise.all([
checkAdblock(),
]);

if (result) {
console.log('Adblock detected');
return;
}

console.log('Load content');
}

await init();
console.log('Script loaded');
})();
```

With current solution only `Checking for adblock...` is printed in console (the same for`noopCallbackFunc`, `noopFunc`, `falseFunc`).
Expected is:
```
Checking for adblock...
Load content
Script loaded
```
So, I think we could add functions which return callback with `false`/`true`, something like:
```js
const falseCallbackFunc = (callback) => { callback(false); };
const trueCallbackFunc = (callback) => { callback(true); };
```


And/Or we could add support for `valueWrapper` similar like in https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-scriptlets.md#set-constant

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.