1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

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:
Raymond Hill 2020-08-17 09:47:40 -04:00
parent a50c0a761e
commit d544543ab5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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,14 +77,16 @@
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, {
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) {
@ -93,5 +95,7 @@
},
});
}
return popup;
}
});
})();