mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 23:42:39 +01:00
Improve prevent-window-open
scriptlet
As discussed with filter list maintainers.
This commit is contained in:
parent
ae5dc6299e
commit
7f11d6216e
@ -2885,10 +2885,8 @@ function noWindowOpenIf(
|
|||||||
pattern = pattern.slice(1);
|
pattern = pattern.slice(1);
|
||||||
}
|
}
|
||||||
const rePattern = safe.patternToRegex(pattern);
|
const rePattern = safe.patternToRegex(pattern);
|
||||||
let autoRemoveAfter = parseInt(delay);
|
const autoRemoveAfter = parseInt(delay, 10) || 0;
|
||||||
if ( isNaN(autoRemoveAfter) ) {
|
const setTimeout = self.setTimeout;
|
||||||
autoRemoveAfter = -1;
|
|
||||||
}
|
|
||||||
const createDecoy = function(tag, urlProp, url) {
|
const createDecoy = function(tag, urlProp, url) {
|
||||||
const decoyElem = document.createElement(tag);
|
const decoyElem = document.createElement(tag);
|
||||||
decoyElem[urlProp] = url;
|
decoyElem[urlProp] = url;
|
||||||
@ -2909,7 +2907,13 @@ function noWindowOpenIf(
|
|||||||
return Reflect.apply(target, thisArg, args);
|
return Reflect.apply(target, thisArg, args);
|
||||||
}
|
}
|
||||||
safe.uboLog(logPrefix, `Prevented (${args.join(', ')})`);
|
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'
|
const decoyElem = decoy === 'obj'
|
||||||
? createDecoy('object', 'data', ...args)
|
? createDecoy('object', 'data', ...args)
|
||||||
: createDecoy('iframe', 'src', ...args);
|
: createDecoy('iframe', 'src', ...args);
|
||||||
|
Loading…
Reference in New Issue
Block a user