AdguardTeam / AdguardTeam/Scriptlets

Add new scriptlet — 'prevent-click'

未關閉
#449 2 則留言 0 個 reaction 已指派 1 人 已被 @maximtop 認領 在 GitHub 檢視
Feature request Priority: P4
主要語言
JavaScript
星號
195
分支
33
PR 合併指標
30 天內沒有已合併 PR

描述

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');
})();
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。