Skip to content

Commit c198b9a

Browse files
committed
Add window.close scriptlet
Related feedback: - uBlockOrigin/uAssets#10323 (comment) AdGuard's rationale: - AdguardTeam/Scriptlets#158
1 parent edd11e1 commit c198b9a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

assets/resources/scriptlets.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,30 @@
12701270
})();
12711271

12721272

1273+
// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
1274+
// https://github.com/AdguardTeam/Scriptlets/issues/158
1275+
/// window-close-if.js
1276+
(function() {
1277+
const arg1 = '{{1}}';
1278+
let reStr;
1279+
if ( arg1 === '{{1}}' || arg1 === '' ) {
1280+
reStr = '^';
1281+
} else if ( arg1.startWith('/') && arg1.endsWith('/') ) {
1282+
reStr = arg1.slice(1, -1);
1283+
} else {
1284+
reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1285+
}
1286+
try {
1287+
const re = new RegExp(reStr);
1288+
if ( re.test(`${window.location.pathname}${window.location.search}`) ) {
1289+
window.close();
1290+
}
1291+
} catch(ex) {
1292+
console.log(ex);
1293+
}
1294+
})();
1295+
1296+
12731297
// https://github.com/gorhill/uBlock/issues/1228
12741298
/// window.name-defuser
12751299
(function() {

0 commit comments

Comments
 (0)