AdguardTeam / AdguardTeam/Scriptlets

Improve `disable-newtab-links` - allow to prevent specific link

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

描述

Currently it prevents opening new tabs and windows only if there is `target` attribute in element.
Sometimes `target` attribute can be used in legitimate links, so I think that it would be nice to have an option to prevent only specific links.
Something similar like in `prevent-window-open` with ability to use `!` as negation - https://github.com/AdguardTeam/Scriptlets/blob/master/wiki/about-scriptlets.md#prevent-window-open

Example case:
```js
function simulateModifiedClick(url) {
try {
const link = document.createElement("a");
link.href = url;
link.rel = "noopener";

link.onclick = e => e.stopPropagation();
document.body.appendChild(link);

link.dispatchEvent(new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
ctrlKey: true,
metaKey: true,
button: 0
}));

link.remove();
} catch {
// Do nothing
}
}
simulateModifiedClick('test');
```

So for instance, `#%#//scriptlet('disable-newtab-links', 'test')` should allow to prevent all links with `test`.

貢獻指南

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

評估

這個 Issue 還沒有評估資料。

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

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