1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Add window.close scriptlet

Related feedback:
- https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847

AdGuard's rationale:
- https://github.com/AdguardTeam/Scriptlets/issues/158
This commit is contained in:
Raymond Hill 2021-12-13 08:14:30 -05:00
parent edd11e16fa
commit c198b9a748
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1270,6 +1270,30 @@
})();
// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
// https://github.com/AdguardTeam/Scriptlets/issues/158
/// window-close-if.js
(function() {
const arg1 = '{{1}}';
let reStr;
if ( arg1 === '{{1}}' || arg1 === '' ) {
reStr = '^';
} else if ( arg1.startWith('/') && arg1.endsWith('/') ) {
reStr = arg1.slice(1, -1);
} else {
reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
try {
const re = new RegExp(reStr);
if ( re.test(`${window.location.pathname}${window.location.search}`) ) {
window.close();
}
} catch(ex) {
console.log(ex);
}
})();
// https://github.com/gorhill/uBlock/issues/1228
/// window.name-defuser
(function() {