Skip to content

Commit

Permalink
Improve nowoif scriptlet
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uAssets#6019
  • Loading branch information
gorhill authored and JustOff committed Dec 13, 2020
1 parent 0e8ad12 commit 3473e11
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions assets/resources/resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,17 @@ window.open-defuser.js application/javascript
pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
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, {
apply: function(target, thisArg, args) {
log('window.open:', ...args);
Expand All @@ -1595,15 +1606,11 @@ window.open-defuser.js application/javascript
return target.apply(thisArg, args);
}
if ( autoRemoveAfter < 0 ) { return null; }
const iframe = document.createElement('iframe');
iframe.src = url;
iframe.style.setProperty('display','none', 'important');
iframe.style.setProperty('height','1px', 'important');
iframe.style.setProperty('width','1px', 'important');
document.body.appendChild(iframe);
setTimeout(( ) => iframe.remove(), autoRemoveAfter * 1000);
if ( arg3 === '' ) { return iframe.contentWindow; }
return new Proxy(iframe.contentWindow, {
const decoy1 = createDecoy('iframe', 'src', url);
const decoy2 = createDecoy('object', 'data', url);
const popup = decoy1.contentWindow || decoy2.contentWindow;
if ( arg3 === '' ) { return popup; }
return new Proxy(popup, {
get: function(target, prop) {
log('window.open / get', prop, '===', target[prop]);
return target[prop];
Expand Down

1 comment on commit 3473e11

@JustOff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag #272.

Please sign in to comment.