From 65a056107210796426033ebe2eebb89a98c93a23 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 17 Sep 2022 12:46:42 -0400 Subject: [PATCH] Slightly change behavior of window-close-if scriplet Related discussion: - https://github.com/uBlockOrigin/uBlock-issues/discussions/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. --- assets/resources/scriptlets.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index ecb65a28d..84ba5de84 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1267,20 +1267,24 @@ // https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847 // https://github.com/AdguardTeam/Scriptlets/issues/158 +// https://github.com/uBlockOrigin/uBlock-issues/discussions/2270 /// window-close-if.js (function() { const arg1 = '{{1}}'; let reStr; + let subject = ''; if ( arg1 === '{{1}}' || arg1 === '' ) { reStr = '^'; - } else if ( arg1.startsWith('/') && arg1.endsWith('/') ) { + } else if ( /^\/.*\/$/.test(arg1) ) { reStr = arg1.slice(1, -1); + subject = window.location.href; } else { reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + subject = `${window.location.pathname}${window.location.search}`; } try { const re = new RegExp(reStr); - if ( re.test(`${window.location.pathname}${window.location.search}`) ) { + if ( re.test(subject) ) { window.close(); } } catch(ex) {