From 8cce7768179c21bfa3aace7e2ad484b4ff44eac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wr=C3=B3blewski?= Date: Fri, 26 Jan 2024 17:05:38 +0100 Subject: [PATCH] Remove debug argument --- src/scriptlets/spoof-css.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/scriptlets/spoof-css.js b/src/scriptlets/spoof-css.js index da8b571cd..7035650c7 100644 --- a/src/scriptlets/spoof-css.js +++ b/src/scriptlets/spoof-css.js @@ -15,15 +15,16 @@ import { * ### Syntax * * ```text - * example.org#%#//scriptlet('spoof-css', selectors, cssNameProperty, cssNameValue[, shouldDebug]) + * example.org#%#//scriptlet('spoof-css', selectors, cssNameProperty, cssNameValue) * ``` * * - `selectors` — string of comma-separated selectors to match * - `cssPropertyName` — CSS property name * - `cssPropertyValue` — CSS property value - * - `debug` — optional, if set to `debug`, will trigger debugger statement - * when `getComputedStyle()` or `getBoundingClientRect()` methods is called * + * > Call with `debug` as `cssPropertyName` and `truthy` value as `cssPropertyValue` will trigger debugger statement + * > when `getComputedStyle()` or `getBoundingClientRect()` methods is called. + * > It may be useful for debugging but it is not allowed for prod versions of filter lists. * * ### Examples * @@ -39,12 +40,18 @@ import { * example.org#%#//scriptlet('spoof-css', '.adsbygoogle, .advert', 'height', '100') * ``` * + * 3. To invoke debugger statement: + * + * ```adblock + * example.org#%#//scriptlet('spoof-css', '.adsbygoogle', 'debug', 'true') + * ``` + * * * @added unknown. */ /* eslint-enable max-len */ -export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, debug) { +export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue) { if (!selectors) { return; } @@ -73,6 +80,8 @@ export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, d return `${firstPart}${secondPart[0].toUpperCase()}${secondPart.slice(1)}`; } + const shouldDebug = !!(cssPropertyName === 'debug' && cssPropertyValue); + const propToValueMap = new Map(); /** @@ -102,7 +111,7 @@ export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, d } propToValueMap.set(convertToCamelCase(arrayOfProperties[i]), arrayOfProperties[i + 1]); } - } else if (cssPropertyName && cssPropertyValue) { + } else if (cssPropertyName && cssPropertyValue && !shouldDebug) { propToValueMap.set(convertToCamelCase(cssPropertyName), cssPropertyValue); } @@ -131,7 +140,7 @@ export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, d }; const getComputedStyleWrapper = (target, thisArg, args) => { - if (debug === 'debug') { + if (shouldDebug) { debugger; // eslint-disable-line no-debugger } const style = Reflect.apply(target, thisArg, args); @@ -186,7 +195,7 @@ export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, d window.getComputedStyle = new Proxy(window.getComputedStyle, getComputedStyleHandler); const getBoundingClientRectWrapper = (target, thisArg, args) => { - if (debug === 'debug') { + if (shouldDebug) { debugger; // eslint-disable-line no-debugger } const rect = Reflect.apply(target, thisArg, args);