diff --git a/dist/build.txt b/dist/build.txt index 15c0d6ac..6de51c39 100644 --- a/dist/build.txt +++ b/dist/build.txt @@ -1 +1 @@ -version=1.6.18 \ No newline at end of file +version=1.6.20 \ No newline at end of file diff --git a/dist/redirects.yml b/dist/redirects.yml index 410125d6..aba166ba 100644 --- a/dist/redirects.yml +++ b/dist/redirects.yml @@ -1,6 +1,6 @@ # # AdGuard Scriptlets (Redirects Source) -# Version 1.6.18 +# Version 1.6.20 # - title: 1x1-transparent.gif description: |- diff --git a/dist/scriptlets.corelibs.json b/dist/scriptlets.corelibs.json index afd93630..5b556cec 100644 --- a/dist/scriptlets.corelibs.json +++ b/dist/scriptlets.corelibs.json @@ -1,5 +1,5 @@ { - "version": "1.6.18", + "version": "1.6.20", "scriptlets": [ { "names": [ @@ -422,7 +422,7 @@ "ubo-window-close-if.js", "ubo-window-close-if" ], - "scriptlet": "function forceWindowClose(source,args){function hit(source,message){if(!0===source.verbose){try{var log=console.log.bind(console),trace=console.trace.bind(console),prefix=source.ruleText||\"\";if(source.domainName){var ruleStartIndex;source.ruleText.indexOf(\"#%#//\")>-1?ruleStartIndex=source.ruleText.indexOf(\"#%#//\"):source.ruleText.indexOf(\"##+js\")>-1&&(ruleStartIndex=source.ruleText.indexOf(\"##+js\"));var rulePart=source.ruleText.slice(ruleStartIndex);prefix=\"\".concat(source.domainName).concat(rulePart)}message&&(-1===message.indexOf(\"log: \")?log(\"\".concat(prefix,\" message:\\n\").concat(message)):log(message.slice(\"log: \".length))),log(\"\".concat(prefix,\" trace start\")),trace&&trace(),log(\"\".concat(prefix,\" trace end\"))}catch(e){}\"function\"==typeof window.__debug&&window.__debug(source)}}function toRegExp(){var input=arguments.length>0&&void 0!==arguments[0]?arguments[0]:\"\",DEFAULT_VALUE=\".?\",FORWARD_SLASH=\"/\";if(\"\"===input)return new RegExp(DEFAULT_VALUE);if(input[0]===FORWARD_SLASH&&input[input.length-1]===FORWARD_SLASH)return new RegExp(input.slice(1,-1));var escaped=input.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\");return new RegExp(escaped)}var updatedArgs=args?[].concat(source).concat(args):[source];try{(function(source){var path=arguments.length>1&&void 0!==arguments[1]?arguments[1]:\"\",log=console.log.bind(console);if(\"function\"==typeof window.close){var closeImmediately=function(){try{hit(source),window.close()}catch(e){log(e)}};if(\"\"===path)closeImmediately();else{var pathRegexp=toRegExp(path),currentPath=\"\".concat(window.location.pathname).concat(window.location.search);pathRegexp.test(currentPath)&&closeImmediately()}}else source.verbose&&log(\"window.close() is not a function so 'close-window' scriptlet is unavailable\")}).apply(this,updatedArgs)}catch(e){console.log(e)}}" + "scriptlet": "function forceWindowClose(source,args){function hit(source,message){if(!0===source.verbose){try{var log=console.log.bind(console),trace=console.trace.bind(console),prefix=source.ruleText||\"\";if(source.domainName){var ruleStartIndex;source.ruleText.indexOf(\"#%#//\")>-1?ruleStartIndex=source.ruleText.indexOf(\"#%#//\"):source.ruleText.indexOf(\"##+js\")>-1&&(ruleStartIndex=source.ruleText.indexOf(\"##+js\"));var rulePart=source.ruleText.slice(ruleStartIndex);prefix=\"\".concat(source.domainName).concat(rulePart)}message&&(-1===message.indexOf(\"log: \")?log(\"\".concat(prefix,\" message:\\n\").concat(message)):log(message.slice(\"log: \".length))),log(\"\".concat(prefix,\" trace start\")),trace&&trace(),log(\"\".concat(prefix,\" trace end\"))}catch(e){}\"function\"==typeof window.__debug&&window.__debug(source)}}function toRegExp(){var input=arguments.length>0&&void 0!==arguments[0]?arguments[0]:\"\",DEFAULT_VALUE=\".?\",FORWARD_SLASH=\"/\";if(\"\"===input)return new RegExp(DEFAULT_VALUE);if(input[0]===FORWARD_SLASH&&input[input.length-1]===FORWARD_SLASH)return new RegExp(input.slice(1,-1));var escaped=input.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\");return new RegExp(escaped)}var updatedArgs=args?[].concat(source).concat(args):[source];try{(function(source){var path=arguments.length>1&&void 0!==arguments[1]?arguments[1]:\"\",log=console.log.bind(console);if(\"function\"==typeof window.close){var closeImmediately=function(){try{hit(source),window.close()}catch(e){log(e)}},closeByExtension=function(){var extCall=function(){dispatchEvent(new Event(\"adguard:scriptlet-close-window\"))};window.addEventListener(\"adguard:subscribed-to-close-window\",extCall,{once:!0}),setTimeout((function(){window.removeEventListener(\"adguard:subscribed-to-close-window\",extCall,{once:!0})}),5e3)};(function(){if(\"\"===path)return!0;var pathRegexp=toRegExp(path),currentPath=\"\".concat(window.location.pathname).concat(window.location.search);return pathRegexp.test(currentPath)})()&&(closeImmediately(),navigator.userAgent.indexOf(\"Chrome\")>-1&&closeByExtension())}else source.verbose&&log(\"window.close() is not a function so 'close-window' scriptlet is unavailable\")}).apply(this,updatedArgs)}catch(e){console.log(e)}}" }, { "names": [ @@ -447,4 +447,4 @@ "scriptlet": "function noTopics(source,args){var updatedArgs=args?[].concat(source).concat(args):[source];try{(function(source){Document instanceof Object!=0&&Object.prototype.hasOwnProperty.call(Document.prototype,\"browsingTopics\")&&Document.prototype.browsingTopics instanceof Function!=0&&(Document.prototype.browsingTopics=function(){return function(){if(\"undefined\"!=typeof Response){var response=new Response(arguments.length>0&&void 0!==arguments[0]?arguments[0]:\"{}\",{status:200,statusText:\"OK\"});return Promise.resolve(response)}}(\"[]\")},function(source,message){if(!0===source.verbose){try{var log=console.log.bind(console),trace=console.trace.bind(console),prefix=source.ruleText||\"\";if(source.domainName){var ruleStartIndex,AG_SCRIPTLET_MARKER=\"#%#//\",UBO_SCRIPTLET_MARKER=\"##+js\";source.ruleText.indexOf(AG_SCRIPTLET_MARKER)>-1?ruleStartIndex=source.ruleText.indexOf(AG_SCRIPTLET_MARKER):source.ruleText.indexOf(UBO_SCRIPTLET_MARKER)>-1&&(ruleStartIndex=source.ruleText.indexOf(UBO_SCRIPTLET_MARKER));var rulePart=source.ruleText.slice(ruleStartIndex);prefix=\"\".concat(source.domainName).concat(rulePart)}var LOG_MARKER=\"log: \";message&&(-1===message.indexOf(LOG_MARKER)?log(\"\".concat(prefix,\" message:\\n\").concat(message)):log(message.slice(LOG_MARKER.length))),log(\"\".concat(prefix,\" trace start\")),trace&&trace(),log(\"\".concat(prefix,\" trace end\"))}catch(e){}\"function\"==typeof window.__debug&&window.__debug(source)}}(source))}).apply(this,updatedArgs)}catch(e){console.log(e)}}" } ] -} +} \ No newline at end of file diff --git a/dist/scriptlets.js b/dist/scriptlets.js index a1c0999c..41a3299e 100644 --- a/dist/scriptlets.js +++ b/dist/scriptlets.js @@ -1,7 +1,7 @@ /** * AdGuard Scriptlets - * Version 1.6.18 + * Version 1.6.20 */ (function () { @@ -5648,6 +5648,9 @@ * @description * Closes the browser tab immediately. * + * > `window.close()` usage is restricted in Chrome. In this case + * tab will only be closed if using AdGuard browser extension. + * * **Syntax** * ``` * example.org#%#//scriptlet('close-window'[, path]) @@ -5691,14 +5694,36 @@ } }; - if (path === '') { - closeImmediately(); - } else { + var closeByExtension = function closeByExtension() { + var extCall = function extCall() { + dispatchEvent(new Event('adguard:scriptlet-close-window')); + }; + + window.addEventListener('adguard:subscribed-to-close-window', extCall, { + once: true + }); + setTimeout(function () { + window.removeEventListener('adguard:subscribed-to-close-window', extCall, { + once: true + }); + }, 5000); + }; + + var shouldClose = function shouldClose() { + if (path === '') { + return true; + } + var pathRegexp = toRegExp(path); var currentPath = "".concat(window.location.pathname).concat(window.location.search); + return pathRegexp.test(currentPath); + }; - if (pathRegexp.test(currentPath)) { - closeImmediately(); + if (shouldClose()) { + closeImmediately(); + + if (navigator.userAgent.indexOf('Chrome') > -1) { + closeByExtension(); } } } @@ -15184,14 +15209,36 @@ } }; - if (path === "") { - closeImmediately(); - } else { + var closeByExtension = function closeByExtension() { + var extCall = function extCall() { + dispatchEvent(new Event("adguard:scriptlet-close-window")); + }; + + window.addEventListener("adguard:subscribed-to-close-window", extCall, { + once: true + }); + setTimeout(function () { + window.removeEventListener("adguard:subscribed-to-close-window", extCall, { + once: true + }); + }, 5e3); + }; + + var shouldClose = function shouldClose() { + if (path === "") { + return true; + } + var pathRegexp = toRegExp(path); var currentPath = "".concat(window.location.pathname).concat(window.location.search); + return pathRegexp.test(currentPath); + }; + + if (shouldClose()) { + closeImmediately(); - if (pathRegexp.test(currentPath)) { - closeImmediately(); + if (navigator.userAgent.indexOf("Chrome") > -1) { + closeByExtension(); } } } diff --git a/dist/umd/scriptlets.umd.js b/dist/umd/scriptlets.umd.js index 10eb5534..c99cd489 100644 --- a/dist/umd/scriptlets.umd.js +++ b/dist/umd/scriptlets.umd.js @@ -1,7 +1,7 @@ /** * AdGuard Scriptlets - * Version 1.6.18 + * Version 1.6.20 */ (function (factory) { @@ -5650,6 +5650,9 @@ * @description * Closes the browser tab immediately. * + * > `window.close()` usage is restricted in Chrome. In this case + * tab will only be closed if using AdGuard browser extension. + * * **Syntax** * ``` * example.org#%#//scriptlet('close-window'[, path]) @@ -5693,14 +5696,36 @@ } }; - if (path === '') { - closeImmediately(); - } else { + var closeByExtension = function closeByExtension() { + var extCall = function extCall() { + dispatchEvent(new Event('adguard:scriptlet-close-window')); + }; + + window.addEventListener('adguard:subscribed-to-close-window', extCall, { + once: true + }); + setTimeout(function () { + window.removeEventListener('adguard:subscribed-to-close-window', extCall, { + once: true + }); + }, 5000); + }; + + var shouldClose = function shouldClose() { + if (path === '') { + return true; + } + var pathRegexp = toRegExp(path); var currentPath = "".concat(window.location.pathname).concat(window.location.search); + return pathRegexp.test(currentPath); + }; - if (pathRegexp.test(currentPath)) { - closeImmediately(); + if (shouldClose()) { + closeImmediately(); + + if (navigator.userAgent.indexOf('Chrome') > -1) { + closeByExtension(); } } } @@ -15186,14 +15211,36 @@ } }; - if (path === "") { - closeImmediately(); - } else { + var closeByExtension = function closeByExtension() { + var extCall = function extCall() { + dispatchEvent(new Event("adguard:scriptlet-close-window")); + }; + + window.addEventListener("adguard:subscribed-to-close-window", extCall, { + once: true + }); + setTimeout(function () { + window.removeEventListener("adguard:subscribed-to-close-window", extCall, { + once: true + }); + }, 5e3); + }; + + var shouldClose = function shouldClose() { + if (path === "") { + return true; + } + var pathRegexp = toRegExp(path); var currentPath = "".concat(window.location.pathname).concat(window.location.search); + return pathRegexp.test(currentPath); + }; + + if (shouldClose()) { + closeImmediately(); - if (pathRegexp.test(currentPath)) { - closeImmediately(); + if (navigator.userAgent.indexOf("Chrome") > -1) { + closeByExtension(); } } } diff --git a/wiki/about-scriptlets.md b/wiki/about-scriptlets.md index 3f78addd..b4b11194 100644 --- a/wiki/about-scriptlets.md +++ b/wiki/about-scriptlets.md @@ -297,6 +297,9 @@ defaults to match all callbacks; invalid regular expression will cause exit and Closes the browser tab immediately. +> `window.close()` usage is restricted in Chrome. In this case +tab will only be closed if using AdGuard browser extension. + **Syntax** ``` example.org#%#//scriptlet('close-window'[, path])