Skip to content

Commit f8c4b8e

Browse files
committed
Add support to remove attributes in xml-prune scriptlet
Related issue: - uBlockOrigin/uAssets#18244
1 parent 9801093 commit f8c4b8e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

assets/resources/scriptlets.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,6 @@ function xmlPrune(
20872087
const out = [];
20882088
for ( let i = 0; i < xpr.snapshotLength; i++ ) {
20892089
const node = xpr.snapshotItem(i);
2090-
if ( node.nodeType !== 1 ) { continue; }
20912090
out.push(node);
20922091
}
20932092
return out;
@@ -2097,12 +2096,18 @@ function xmlPrune(
20972096
if ( selectorCheck !== '' && xmlDoc.querySelector(selectorCheck) === null ) {
20982097
return xmlDoc;
20992098
}
2100-
const elems = queryAll(xmlDoc, selector);
2101-
if ( elems.length !== 0 ) {
2102-
if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${elems.length} nodes`); }
2103-
for ( const elem of elems ) {
2104-
elem.remove();
2105-
if ( log ) { safeSelf().uboLog(`xmlPrune: ${elem.nodeName} removed`); }
2099+
const items = queryAll(xmlDoc, selector);
2100+
if ( items.length !== 0 ) {
2101+
if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${items.length} items`); }
2102+
for ( const item of items ) {
2103+
if ( item.nodeType === 1 ) {
2104+
item.remove();
2105+
} else if ( item.nodeType === 2 ) {
2106+
item.ownerElement.removeAttribute(item.nodeName);
2107+
}
2108+
if ( log ) {
2109+
safeSelf().uboLog(`xmlPrune: ${item.constructor.name}.${item.nodeName} removed`);
2110+
}
21062111
}
21072112
}
21082113
} catch(ex) {

0 commit comments

Comments
 (0)