Skip to content

Commit

Permalink
Remove debug argument
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Jan 26, 2024
1 parent 5034934 commit 8cce776
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/scriptlets/spoof-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8cce776

Please sign in to comment.