mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
Improve prevent-window-open
scriptlet
As discussed with filter list maintainers.
This commit is contained in:
parent
ae5dc6299e
commit
7f11d6216e
1 changed files with 9 additions and 5 deletions
|
@ -2885,10 +2885,8 @@ function noWindowOpenIf(
|
|||
pattern = pattern.slice(1);
|
||||
}
|
||||
const rePattern = safe.patternToRegex(pattern);
|
||||
let autoRemoveAfter = parseInt(delay);
|
||||
if ( isNaN(autoRemoveAfter) ) {
|
||||
autoRemoveAfter = -1;
|
||||
}
|
||||
const autoRemoveAfter = parseInt(delay, 10) || 0;
|
||||
const setTimeout = self.setTimeout;
|
||||
const createDecoy = function(tag, urlProp, url) {
|
||||
const decoyElem = document.createElement(tag);
|
||||
decoyElem[urlProp] = url;
|
||||
|
@ -2909,7 +2907,13 @@ function noWindowOpenIf(
|
|||
return Reflect.apply(target, thisArg, args);
|
||||
}
|
||||
safe.uboLog(logPrefix, `Prevented (${args.join(', ')})`);
|
||||
if ( autoRemoveAfter < 0 ) { return null; }
|
||||
if ( delay === '' ) { return null; }
|
||||
if ( decoy === 'blank' ) {
|
||||
args[0] = 'about:blank';
|
||||
const r = Reflect.apply(target, thisArg, args);
|
||||
setTimeout(( ) => { r.close(); }, autoRemoveAfter);
|
||||
return r;
|
||||
}
|
||||
const decoyElem = decoy === 'obj'
|
||||
? createDecoy('object', 'data', ...args)
|
||||
: createDecoy('iframe', 'src', ...args);
|
||||
|
|
Loading…
Reference in a new issue