hide-if-svg-contains
The hide-if-svg-contains snippet hides any HTML element matching a CSS selector if it contains a SVG image with the given visible text.
Parameters
|
Name |
Description |
Mandatory |
|---|---|---|
|
search |
Text or regex pattern to match within SVG visible content. |
Yes |
|
selector |
CSS selector identifying which elements to hide. |
Yes |
|
searchSelector |
Target specific elements containing the matched text. Defaults to |
No |
|
optionalParameters |
Any number of |
No |
Default parameters
Even with no optional parameters, the snippet already applies the checks below when deciding whether text counts as visible. Pass any of them as an optional parameter to override the default.
|
Name |
Description |
Default |
|---|---|---|
|
|
Text nodes within this many pixels of the image root count as inside the viewport. Anything further out counts as invisible. |
|
|
|
Set to |
|
|
|
Text at or below this |
|
|
|
Text at or below this |
|
|
|
Delays running the snippet until the given state is reached. Accepts |
empty, runs immediately |
|
|
Text with this computed |
|
|
|
Text with this computed |
|
|
|
Text with this computed |
|
|
|
Text with this computed |
|
|
|
Text with this computed |
|
Examples
-
hide-if-svg-contains Sponsored div.parent div.child— scansdiv.childelements and hidesdiv.parentif the background image contains "Sponsored" -
hide-if-svg-contains Sponsored div.parent div.child '-opacity-alpha-threshold:0.5'— treats text as hidden at any opacity or alpha at or below0.5, rather than the default0.1. Use when the site fades the label instead of making it fully transparent -
hide-if-svg-contains Sponsored div.parent div.child '-font-size-threshold:4'— treats text as hidden at any font size at or below4 -
hide-if-svg-contains Sponsored div.parent div.child '-wait-until:load'— delays the snippet until theloadevent, for sites that inject the SVG late -
hide-if-svg-contains /.*/ div.parent 'div.parent div.label' 'color:rgb(255, 255, 255)'— hides anydiv.parentcontaining adiv.labelwhose background image matches, and whose font colour is not white. The descendant selector is quoted because it contains a space