diff --git a/assets/resources/resources.txt b/assets/resources/resources.txt index 2ed367b6c..ab55da983 100644 --- a/assets/resources/resources.txt +++ b/assets/resources/resources.txt @@ -1547,30 +1547,70 @@ abort-current-inline-script.js application/javascript })(); -# https://github.com/uBlockOrigin/uAssets/commit/a6c77af4afb45800d4fd7c268a2a5eab5a64daf3#commitcomment-24611606 +# https://github.com/gorhill/uBlock/commit/b27848a060eee961e2403192097448467b3bc7b5 window.open-defuser.js application/javascript (function() { - var wo = window.open, - target = '{{1}}', - needle = '{{2}}'; - if ( target === '' || target === '{{1}}' ) { - target = false; + let arg1 = '{{1}}'; + if ( arg1 === '{{1}}' ) { arg1 = ''; } + let arg2 = '{{2}}'; + if ( arg2 === '{{2}}' ) { arg2 = ''; } + let arg3 = '{{3}}'; + if ( arg3 === '{{3}}' ) { arg3 = ''; } + const newSyntax = /^[01]?$/.test(arg1) === false; + let pattern = ''; + let targetResult = true; + let autoRemoveAfter = -1; + if ( newSyntax ) { + pattern = arg1; + if ( pattern.startsWith('!') ) { + targetResult = false; + pattern = pattern.slice(1); + } + autoRemoveAfter = parseInt(arg2); + if ( isNaN(autoRemoveAfter) ) { + autoRemoveAfter = -1; + } } else { - target = !(+target); + pattern = arg2; + if ( arg1 === '0' ) { + targetResult = false; + } } - if ( needle === '' || needle === '{{2}}' ) { - needle = '.?'; - } else if ( /^\/.+\/$/.test(needle) ) { - needle = needle.slice(1,-1); + if ( pattern === '' ) { + pattern = '.?'; + } else if ( /^\/.+\/$/.test(pattern) ) { + pattern = pattern.slice(1,-1); } else { - needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } - needle = new RegExp(needle); - window.open = (function(a) { - if ( needle.test(a) === target ) { - return wo.apply(window, arguments); + const rePattern = new RegExp(pattern); + window.open = new Proxy(window.open, { + apply: function(target, thisArg, args) { + const url = args[0]; + if ( rePattern.test(url) !== targetResult ) { + 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, { + get: function(target, prop) { + console.log('get', prop, '===', target[prop]); + return target[prop]; + }, + set: function(target, prop, value) { + console.log('set', prop, '=', value); + target[prop] = value; + }, + }); } - }).bind(window); + }); })();