From c198b9a748265c0e1ce7f5bad4528d5bf6ce8161 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 13 Dec 2021 08:14:30 -0500 Subject: [PATCH] Add `window.close` scriptlet Related feedback: - https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847 AdGuard's rationale: - https://github.com/AdguardTeam/Scriptlets/issues/158 --- assets/resources/scriptlets.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 391fa88b6..c53adcae9 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1270,6 +1270,30 @@ })(); +// https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847 +// https://github.com/AdguardTeam/Scriptlets/issues/158 +/// window-close-if.js +(function() { + const arg1 = '{{1}}'; + let reStr; + if ( arg1 === '{{1}}' || arg1 === '' ) { + reStr = '^'; + } else if ( arg1.startWith('/') && arg1.endsWith('/') ) { + reStr = arg1.slice(1, -1); + } else { + reStr = arg1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + try { + const re = new RegExp(reStr); + if ( re.test(`${window.location.pathname}${window.location.search}`) ) { + window.close(); + } + } catch(ex) { + console.log(ex); + } +})(); + + // https://github.com/gorhill/uBlock/issues/1228 /// window.name-defuser (function() {