nova regra removeCustomAttr

This commit is contained in:
Renan Bernordi 2025-01-23 17:05:56 -03:00
parent d4ab2c4cd8
commit 761b2dde52
2 changed files with 37 additions and 1 deletions

View file

@ -79,6 +79,7 @@ return [
'navdmp.com',
'getblue.io',
'smartocto.com',
'cdn.pn.vg'
'cdn.pn.vg',
'static.vocstatic.com'
]
];

View file

@ -623,6 +623,41 @@ class URLAnalyzer
}
}
}
if (isset($domainRules['removeCustomAttr'])) {
foreach ($domainRules['removeCustomAttr'] as $attrPattern) {
if (strpos($attrPattern, '*') !== false) {
// For wildcard attributes (e.g. data-*) / Para atributos com wildcard (ex: data-*)
$elements = $xpath->query('//*');
if ($elements !== false) {
$pattern = '/^' . str_replace('*', '.*', $attrPattern) . '$/';
foreach ($elements as $element) {
if ($element->hasAttributes()) {
$attrs = [];
foreach ($element->attributes as $attr) {
if (preg_match($pattern, $attr->name)) {
$attrs[] = $attr->name;
}
}
foreach ($attrs as $attr) {
$element->removeAttribute($attr);
}
}
}
$this->activatedRules[] = "removeCustomAttr: $attrPattern";
}
} else {
// For non-wildcard attributes / Para atributos sem wildcard
$elements = $xpath->query("//*[@$attrPattern]");
if ($elements !== false && $elements->length > 0) {
foreach ($elements as $element) {
$element->removeAttribute($attrPattern);
}
$this->activatedRules[] = "removeCustomAttr: $attrPattern";
}
}
}
}
}
/**