mirror of https://github.com/gorhill/uBlock.git
Add argument to nowoif scriptlet
When a 3rd argument was provided, the scriplet would log information related to window popup operations, regardless of the value of the argument. The 3rd argument is now parsed in a formal manner. It is meant to be one or more space-separated tokens which are used to fine tune the behavior of the scriptlet. Tokens: log: Cause the scriptlet to log information regarding how window.open() is used by the page on which the scriptlet is used. Useful only to filter creators. obj: Use an `object` element instead of `iframe` element (default) as a decoy to be used in place of a popup window, when the page requires a valid `window` instance to be returned.
This commit is contained in:
parent
a50c0a761e
commit
d544543ab5
|
@ -27,7 +27,7 @@
|
|||
if ( arg2 === '{{2}}' ) { arg2 = ''; }
|
||||
let arg3 = '{{3}}';
|
||||
if ( arg3 === '{{3}}' ) { arg3 = ''; }
|
||||
const log = arg3 !== ''
|
||||
const log = /\blog\b/.test(arg3)
|
||||
? console.log.bind(console)
|
||||
: ( ) => { };
|
||||
const newSyntax = /^[01]?$/.test(arg1) === false;
|
||||
|
@ -77,21 +77,25 @@
|
|||
return target.apply(thisArg, args);
|
||||
}
|
||||
if ( autoRemoveAfter < 0 ) { return null; }
|
||||
const decoy1 = createDecoy('iframe', 'src', url);
|
||||
const decoy2 = createDecoy('object', 'data', url);
|
||||
const popup = decoy1.contentWindow || decoy2.contentWindow;
|
||||
const decoy = /\bobj\b/.test(arg3)
|
||||
? createDecoy('object', 'data', url)
|
||||
: createDecoy('iframe', 'src', url);
|
||||
let popup = decoy.contentWindow;
|
||||
Object.defineProperty(popup, 'closed', { value: false });
|
||||
if ( arg3 === '' ) { return popup; }
|
||||
return new Proxy(popup, {
|
||||
get: function(target, prop) {
|
||||
log('window.open / get', prop, '===', target[prop]);
|
||||
return target[prop];
|
||||
},
|
||||
set: function(target, prop, value) {
|
||||
log('window.open / set', prop, '=', value);
|
||||
target[prop] = value;
|
||||
},
|
||||
});
|
||||
if ( /\blog\b/.test(arg3) ) {
|
||||
popup = new Proxy(popup, {
|
||||
get: function(target, prop) {
|
||||
log('window.open / get', prop, '===', target[prop]);
|
||||
if ( prop === 'closed' ) { return false; }
|
||||
return target[prop];
|
||||
},
|
||||
set: function(target, prop, value) {
|
||||
log('window.open / set', prop, '=', value);
|
||||
target[prop] = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue