AdguardTeam / AdguardTeam/Scriptlets

Add new scriptlet — 'prevent-click'

Đang mở
#449 2 bình luận 0 reaction 1 người được giao Được @maximtop nhận Xem trên GitHub
Feature request 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ả

Recently I have noticed that some websites uses `click()` to open popups.
For example:
```js
(() => {
const url = '/popup';
const createElm = document.createElement("a");
createElm.href = url;
createElm.target = "_blank";
createElm.click();
/*
do something, for example load video player
*/
console.log('something');
})();
```

We could add a scriptlet to prevent `click` if clicked element has specific attribute (like `href`) with specific content.
For example (might need improvements, just an idea):
```js
(() => {
const preventClick = (element, content) => {
const wrapper = (target, thisArg, args) => {
const match = content.split(':');
const [attribute, text] = match;
if(thisArg.matches(element) && thisArg[attribute].includes(text)) {
return;
}
return Reflect.apply(target, thisArg, args);
};
const handler = {
apply: wrapper
};
window.HTMLElement.prototype.click = new Proxy(window.HTMLElement.prototype.click, handler);
};
// Prevent clicking "a" element if "href" contains "popup"
preventClick('a', 'href:popup');
})();
```

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.