mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +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:
parent
9a8835a042
commit
65a0561072
@ -1267,20 +1267,24 @@
|
|||||||
|
|
||||||
// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
|
// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
|
||||||
// https://github.com/AdguardTeam/Scriptlets/issues/158
|
// https://github.com/AdguardTeam/Scriptlets/issues/158
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/discussions/2270
|
||||||
/// window-close-if.js
|
/// window-close-if.js
|
||||||
(function() {
|
(function() {
|
||||||
const arg1 = '{{1}}';
|
const arg1 = '{{1}}';
|
||||||
let reStr;
|
let reStr;
|
||||||
|
let subject = '';
|
||||||
if ( arg1 === '{{1}}' || arg1 === '' ) {
|
if ( arg1 === '{{1}}' || arg1 === '' ) {
|
||||||
reStr = '^';
|
reStr = '^';
|
||||||
} else if ( arg1.startsWith('/') && arg1.endsWith('/') ) {
|
} else if ( /^\/.*\/$/.test(arg1) ) {
|
||||||
reStr = arg1.slice(1, -1);
|
reStr = arg1.slice(1, -1);
|
||||||
|
subject = window.location.href;
|
||||||
} else {
|
} else {
|
||||||
reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
subject = `${window.location.pathname}${window.location.search}`;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const re = new RegExp(reStr);
|
const re = new RegExp(reStr);
|
||||||
if ( re.test(`${window.location.pathname}${window.location.search}`) ) {
|
if ( re.test(subject) ) {
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user