mirror of https://github.com/gorhill/uBlock.git
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/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) {
|
||||
|
|
Loading…
Reference in New Issue