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

Improve nowoif scriptlet

Related issue:
- https://github.com/uBlockOrigin/uAssets/issues/ 6019
This commit is contained in:
Raymond Hill 2020-08-16 13:18:40 -04:00
parent 29448a9294
commit 071b15cf94
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -58,6 +58,17 @@
pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
} }
const rePattern = new RegExp(pattern); const rePattern = new RegExp(pattern);
const createDecoy = function(tag, urlProp, url) {
const decoy = document.createElement('iframe');
decoy[urlProp] = url;
decoy.style.setProperty('height','1px', 'important');
decoy.style.setProperty('position','fixed', 'important');
decoy.style.setProperty('top','-1px', 'important');
decoy.style.setProperty('width','1px', 'important');
document.body.appendChild(decoy);
setTimeout(( ) => decoy.remove(), autoRemoveAfter * 1000);
return decoy;
};
window.open = new Proxy(window.open, { window.open = new Proxy(window.open, {
apply: function(target, thisArg, args) { apply: function(target, thisArg, args) {
log('window.open:', ...args); log('window.open:', ...args);
@ -66,15 +77,11 @@
return target.apply(thisArg, args); return target.apply(thisArg, args);
} }
if ( autoRemoveAfter < 0 ) { return null; } if ( autoRemoveAfter < 0 ) { return null; }
const iframe = document.createElement('iframe'); const decoy1 = createDecoy('iframe', 'src', url);
iframe.src = url; const decoy2 = createDecoy('object', 'data', url);
iframe.style.setProperty('display','none', 'important'); const popup = decoy1.contentWindow || decoy2.contentWindow;
iframe.style.setProperty('height','1px', 'important'); if ( arg3 === '' ) { return popup; }
iframe.style.setProperty('width','1px', 'important'); return new Proxy(popup, {
document.body.appendChild(iframe);
setTimeout(( ) => iframe.remove(), autoRemoveAfter * 1000);
if ( arg3 === '' ) { return iframe.contentWindow; }
return new Proxy(iframe.contentWindow, {
get: function(target, prop) { get: function(target, prop) {
log('window.open / get', prop, '===', target[prop]); log('window.open / get', prop, '===', target[prop]);
return target[prop]; return target[prop];