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

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.
This commit is contained in:
Raymond Hill 2022-09-17 12:46:42 -04:00
parent 9a8835a042
commit 65a0561072
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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) {