AdguardTeam / AdguardTeam/Scriptlets

Add new scriptlet — 'prevent-click'

オープン
#449 コメント 2 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。