Skip to content

Commit

Permalink
Slightly change behavior of window-close-if scriplet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Sep 17, 2022
1 parent 9a8835a commit 65a0561
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions assets/resources/scriptlets.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 65a0561

Please sign in to comment.