mirror of https://github.com/gorhill/uBlock.git
Add support to remove attributes in xml-prune scriptlet
Related issue: - https://github.com/uBlockOrigin/uAssets/issues/18244
This commit is contained in:
parent
9801093117
commit
f8c4b8e52d
|
@ -2087,7 +2087,6 @@ function xmlPrune(
|
||||||
const out = [];
|
const out = [];
|
||||||
for ( let i = 0; i < xpr.snapshotLength; i++ ) {
|
for ( let i = 0; i < xpr.snapshotLength; i++ ) {
|
||||||
const node = xpr.snapshotItem(i);
|
const node = xpr.snapshotItem(i);
|
||||||
if ( node.nodeType !== 1 ) { continue; }
|
|
||||||
out.push(node);
|
out.push(node);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -2097,12 +2096,18 @@ function xmlPrune(
|
||||||
if ( selectorCheck !== '' && xmlDoc.querySelector(selectorCheck) === null ) {
|
if ( selectorCheck !== '' && xmlDoc.querySelector(selectorCheck) === null ) {
|
||||||
return xmlDoc;
|
return xmlDoc;
|
||||||
}
|
}
|
||||||
const elems = queryAll(xmlDoc, selector);
|
const items = queryAll(xmlDoc, selector);
|
||||||
if ( elems.length !== 0 ) {
|
if ( items.length !== 0 ) {
|
||||||
if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${elems.length} nodes`); }
|
if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${items.length} items`); }
|
||||||
for ( const elem of elems ) {
|
for ( const item of items ) {
|
||||||
elem.remove();
|
if ( item.nodeType === 1 ) {
|
||||||
if ( log ) { safeSelf().uboLog(`xmlPrune: ${elem.nodeName} removed`); }
|
item.remove();
|
||||||
|
} else if ( item.nodeType === 2 ) {
|
||||||
|
item.ownerElement.removeAttribute(item.nodeName);
|
||||||
|
}
|
||||||
|
if ( log ) {
|
||||||
|
safeSelf().uboLog(`xmlPrune: ${item.constructor.name}.${item.nodeName} removed`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
|
|
Loading…
Reference in New Issue