mirror of https://github.com/gorhill/uBlock.git
Slightly improve nowoif scriptlet
Returns proxied self is no window object can be returned.
This commit is contained in:
parent
e3d06268da
commit
b98b2fc52b
|
@ -80,18 +80,32 @@
|
|||
const decoy = /\bobj\b/.test(arg3)
|
||||
? createDecoy('object', 'data', url)
|
||||
: createDecoy('iframe', 'src', url);
|
||||
let popup = decoy.contentWindow || decoy;
|
||||
Object.defineProperty(popup, 'closed', { value: false });
|
||||
let popup = decoy.contentWindow;
|
||||
if ( typeof popup === 'object' && popup !== null ) {
|
||||
Object.defineProperty(popup, 'closed', { value: false });
|
||||
} else {
|
||||
const noopFunc = (function(){}).bind(self);
|
||||
popup = new Proxy(self, {
|
||||
get: function(target, prop) {
|
||||
if ( prop === 'closed' ) { return false; }
|
||||
const r = Reflect.get(...arguments);
|
||||
if ( typeof r === 'function' ) { return noopFunc; }
|
||||
return target[prop];
|
||||
},
|
||||
set: function() {
|
||||
return Reflect.set(...arguments);
|
||||
},
|
||||
});
|
||||
}
|
||||
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];
|
||||
return Reflect.get(...arguments);
|
||||
},
|
||||
set: function(target, prop, value) {
|
||||
log('window.open / set', prop, '=', value);
|
||||
target[prop] = value;
|
||||
return Reflect.set(...arguments);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue