Skip to content

Commit 6403dc8

Browse files
committed
Allow only one pair of property name - value per rule
1 parent a12558a commit 6403dc8

File tree

2 files changed

+4
-140
lines changed

2 files changed

+4
-140
lines changed

src/scriptlets/spoof-css.js

+4-24
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
* ```
2020
*
2121
* - `selectors` — string of comma-separated selectors to match
22-
* - `cssPropertyName` — CSS property name, separated by a comma
23-
* - `cssPropertyValue` — CSS property value, separated by a comma
22+
* - `cssPropertyName` — CSS property name
23+
* - `cssPropertyValue` — CSS property value
2424
* - `debug` — optional, if set to `debug`, will trigger debugger statement
2525
* when `getComputedStyle()` or `getBoundingClientRect()` methods is called
2626
*
@@ -33,24 +33,12 @@ import {
3333
* example.org#%#//scriptlet('spoof-css', '.adsbygoogle', 'display', 'block')
3434
* ```
3535
*
36-
* 2. Spoof CSS property value `display` to `block`, `visibility` to `visible` for all elements with class `adsbygoogle`:
37-
*
38-
* ```adblock
39-
* example.org#%#//scriptlet('spoof-css', '.adsbygoogle', 'display, visibility', 'block, visible')
40-
* ```
41-
*
42-
* 3. Spoof CSS property value `height` to `100` for all elements with class `adsbygoogle` and `advert`:
36+
* 2. Spoof CSS property value `height` to `100` for all elements with class `adsbygoogle` and `advert`:
4337
*
4438
* ```adblock
4539
* example.org#%#//scriptlet('spoof-css', '.adsbygoogle, .advert', 'height', '100')
4640
* ```
4741
*
48-
* 4. Spoof CSS property value `height` to `100`, `display` to `block`
49-
* for all elements with class `adsbygoogle` and `advert`:
50-
*
51-
* ```adblock
52-
* example.org#%#//scriptlet('spoof-css', '.adsbygoogle, .advert', 'height, display', '100, block')
53-
* ```
5442
*
5543
* @added unknown.
5644
*/
@@ -115,15 +103,7 @@ export function spoofCSS(source, selectors, cssPropertyName, cssPropertyValue, d
115103
propToValueMap.set(convertToCamelCase(arrayOfProperties[i]), arrayOfProperties[i + 1]);
116104
}
117105
} else if (cssPropertyName && cssPropertyValue) {
118-
const arrayOfCssNames = cssPropertyName.replace(/\s+/g, '').split(',');
119-
const arrayOfCssValues = cssPropertyValue.replace(/\s+/g, '').split(',');
120-
121-
for (let i = 0; i < arrayOfCssNames.length; i += 1) {
122-
if (arrayOfCssNames[i] === '') {
123-
break;
124-
}
125-
propToValueMap.set(convertToCamelCase(arrayOfCssNames[i]), arrayOfCssValues[i]);
126-
}
106+
propToValueMap.set(convertToCamelCase(cssPropertyName), cssPropertyValue);
127107
}
128108

129109
const spoofStyle = (cssProperty, realCssValue) => {

tests/scriptlets/spoof-css.test.js

-116
Original file line numberDiff line numberDiff line change
@@ -316,36 +316,6 @@ test('One selector and two properties, set by two separate scriptlets - getCompu
316316
matchStyle.remove();
317317
});
318318

319-
test('One selector and two properties - getComputedStyle', (assert) => {
320-
const matchClassName = 'testClassFewProps';
321-
322-
const matchElem = createElem(matchClassName);
323-
const cssProperty = 'display: none !important; visibility: hidden !important;';
324-
const matchStyle = addStyle(`.${matchClassName} { ${cssProperty} }`);
325-
326-
const cssNameProperty = 'display, visibility';
327-
const cssValueProperty = 'block, visible';
328-
329-
const scriptletArgs = [`.${matchClassName}`, cssNameProperty, cssValueProperty];
330-
runScriptlet(name, scriptletArgs);
331-
332-
const computedStyle = window.getComputedStyle(matchElem);
333-
const elStyleDisplay = computedStyle.display;
334-
const elStylePropValDisplay = computedStyle.getPropertyValue('display');
335-
const elStyleVisibility = computedStyle.visibility;
336-
const elStylePropValVisibility = computedStyle.getPropertyValue('visibility');
337-
338-
assert.strictEqual(elStyleDisplay, 'block', 'display style is set to block');
339-
assert.strictEqual(elStylePropValDisplay, 'block', 'display style is set to block - getPropertyValue');
340-
assert.strictEqual(elStyleVisibility, 'visible', 'visibility style is set to visible');
341-
assert.strictEqual(elStylePropValVisibility, 'visible', 'visibility style is set to visible - getPropertyValue');
342-
assert.strictEqual(window.hit, 'FIRED');
343-
344-
clearGlobalProps('hit');
345-
matchElem.remove();
346-
matchStyle.remove();
347-
});
348-
349319
test('Two selectors and one property - getComputedStyle', (assert) => {
350320
const matchClassNameFirst = 'testClassFirst';
351321
const matchClassNameSecond = 'testClassSecond';
@@ -421,64 +391,6 @@ test('Two selectors divided by escaped comma and one property - getComputedStyle
421391
matchStyle.remove();
422392
});
423393

424-
test('Two selectors and two properties - getComputedStyle', (assert) => {
425-
const matchClassNameFirst = 'testClassFirst';
426-
const matchClassNameSecond = 'testClassSecond';
427-
428-
const matchElemFirst = createElem(matchClassNameFirst);
429-
const matchElemSecond = createElem(matchClassNameFirst);
430-
const cssProperty = 'display: none !important; visibility: hidden !important;';
431-
const matchStyle = addStyle(
432-
`
433-
.${matchClassNameFirst} { ${cssProperty} }
434-
.${matchClassNameSecond} { ${cssProperty} }
435-
`,
436-
);
437-
438-
const cssNameProperty = 'display, visibility';
439-
const cssValueProperty = 'block, visible';
440-
441-
const scriptletArgs = [`.${matchClassNameFirst}, .${matchClassNameSecond}`, cssNameProperty, cssValueProperty];
442-
runScriptlet(name, scriptletArgs);
443-
444-
const computedStyleSecond = window.getComputedStyle(matchElemSecond);
445-
const elStyleDisplaySecond = computedStyleSecond.display;
446-
const elStylePropValDisplaySecond = computedStyleSecond.getPropertyValue('display');
447-
const elStyleVisibilitySecond = computedStyleSecond.visibility;
448-
const elStylePropValVisibilitySecond = computedStyleSecond.getPropertyValue('visibility');
449-
450-
const computedStyleFirst = window.getComputedStyle(matchElemFirst);
451-
const elStyleDisplayFirst = computedStyleFirst.display;
452-
const elStylePropValDisplayFirst = computedStyleFirst.getPropertyValue('display');
453-
const elStyleVisibilityFirst = computedStyleFirst.visibility;
454-
const elStylePropValVisibilityFirst = computedStyleFirst.getPropertyValue('visibility');
455-
456-
assert.strictEqual(elStyleDisplayFirst, 'block', 'display style is set to block');
457-
assert.strictEqual(elStylePropValDisplayFirst, 'block', 'display style is set to block - getPropertyValue');
458-
assert.strictEqual(elStyleVisibilityFirst, 'visible', 'visibility style is set to visible');
459-
assert.strictEqual(
460-
elStylePropValVisibilityFirst,
461-
'visible',
462-
'visibility style is set to visible - getPropertyValue',
463-
);
464-
465-
assert.strictEqual(elStyleDisplaySecond, 'block', 'display style is set to block');
466-
assert.strictEqual(elStylePropValDisplaySecond, 'block', 'display style is set to block - getPropertyValue');
467-
assert.strictEqual(elStyleVisibilitySecond, 'visible', 'visibility style is set to visible');
468-
assert.strictEqual(
469-
elStylePropValVisibilitySecond,
470-
'visible',
471-
'visibility style is set to visible - getPropertyValue',
472-
);
473-
474-
assert.strictEqual(window.hit, 'FIRED');
475-
476-
clearGlobalProps('hit');
477-
matchElemFirst.remove();
478-
matchElemSecond.remove();
479-
matchStyle.remove();
480-
});
481-
482394
test('One selector and one property - getComputedStyle getOwnPropertyDescriptor', (assert) => {
483395
const matchClassName = 'testClassGetOwnPropertyDescriptor';
484396

@@ -553,34 +465,6 @@ test('One selector and one property - getBoundingClientRect top', (assert) => {
553465
matchStyle.remove();
554466
});
555467

556-
test('One selector and two properties - getBoundingClientRect', (assert) => {
557-
const EXPECTED_HEIGHT = 555;
558-
const EXPECTED_WIDTH = 666;
559-
const matchClassName = 'testClassClientRect';
560-
561-
const matchElem = createElem(matchClassName);
562-
const cssProperty = 'height: 100px !important; width: 100px !important;';
563-
const matchStyle = addStyle(`.${matchClassName} { ${cssProperty} }`);
564-
565-
const cssNameProperty = 'height, width';
566-
const cssValueProperty = `${EXPECTED_HEIGHT}, ${EXPECTED_WIDTH}`;
567-
568-
const scriptletArgs = [`.${matchClassName}`, cssNameProperty, cssValueProperty];
569-
runScriptlet(name, scriptletArgs);
570-
571-
const boundingClientRect = matchElem.getBoundingClientRect();
572-
const elStyleHeight = boundingClientRect.height;
573-
const elStyleWidth = boundingClientRect.width;
574-
575-
assert.strictEqual(elStyleHeight, EXPECTED_HEIGHT, `height is set to ${EXPECTED_HEIGHT}`);
576-
assert.strictEqual(elStyleWidth, EXPECTED_WIDTH, `width is set to ${EXPECTED_HEIGHT}`);
577-
assert.strictEqual(window.hit, 'FIRED');
578-
579-
clearGlobalProps('hit');
580-
matchElem.remove();
581-
matchStyle.remove();
582-
});
583-
584468
test('Native code check', (assert) => {
585469
const matchClassName = 'testClassNativeCode';
586470
const matchElem = createElem(matchClassName);

0 commit comments

Comments
 (0)