Skip to content

Commit 65a0561

Browse files
committed
Slightly change behavior of window-close-if scriplet
Related discussion: - uBlockOrigin/uBlock-issues#2270 If the argument to the window-close-if scriptlet is a regex, the match will be against the whole location URL, otherwise the match will be against the part+query part of the location URL.
1 parent 9a8835a commit 65a0561

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

assets/resources/scriptlets.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,20 +1267,24 @@
12671267

12681268
// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
12691269
// https://github.com/AdguardTeam/Scriptlets/issues/158
1270+
// https://github.com/uBlockOrigin/uBlock-issues/discussions/2270
12701271
/// window-close-if.js
12711272
(function() {
12721273
const arg1 = '{{1}}';
12731274
let reStr;
1275+
let subject = '';
12741276
if ( arg1 === '{{1}}' || arg1 === '' ) {
12751277
reStr = '^';
1276-
} else if ( arg1.startsWith('/') && arg1.endsWith('/') ) {
1278+
} else if ( /^\/.*\/$/.test(arg1) ) {
12771279
reStr = arg1.slice(1, -1);
1280+
subject = window.location.href;
12781281
} else {
12791282
reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1283+
subject = `${window.location.pathname}${window.location.search}`;
12801284
}
12811285
try {
12821286
const re = new RegExp(reStr);
1283-
if ( re.test(`${window.location.pathname}${window.location.search}`) ) {
1287+
if ( re.test(subject) ) {
12841288
window.close();
12851289
}
12861290
} catch(ex) {

0 commit comments

Comments
 (0)