From f8c4b8e52d9e93e0419eb8b0891084e59be0616b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 5 Jun 2023 08:51:20 -0400 Subject: [PATCH] Add support to remove attributes in xml-prune scriptlet Related issue: - https://github.com/uBlockOrigin/uAssets/issues/18244 --- assets/resources/scriptlets.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 729dd7c09..df070abf7 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -2087,7 +2087,6 @@ function xmlPrune( const out = []; for ( let i = 0; i < xpr.snapshotLength; i++ ) { const node = xpr.snapshotItem(i); - if ( node.nodeType !== 1 ) { continue; } out.push(node); } return out; @@ -2097,12 +2096,18 @@ function xmlPrune( if ( selectorCheck !== '' && xmlDoc.querySelector(selectorCheck) === null ) { return xmlDoc; } - const elems = queryAll(xmlDoc, selector); - if ( elems.length !== 0 ) { - if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${elems.length} nodes`); } - for ( const elem of elems ) { - elem.remove(); - if ( log ) { safeSelf().uboLog(`xmlPrune: ${elem.nodeName} removed`); } + const items = queryAll(xmlDoc, selector); + if ( items.length !== 0 ) { + if ( log ) { safeSelf().uboLog(`xmlPrune: removing ${items.length} items`); } + for ( const item of items ) { + if ( item.nodeType === 1 ) { + 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) {