look for left/right branch content only up to common ancestor
This commit is contained in:
parent
86c1676614
commit
8beb2f5279
@ -131,17 +131,17 @@ function extractBlockContent(blockStartNode, blockEndNode) {
|
|||||||
const contentFragment = blockStartNode.ownerDocument.createDocumentFragment()
|
const contentFragment = blockStartNode.ownerDocument.createDocumentFragment()
|
||||||
|
|
||||||
/** @type {Element[]} */
|
/** @type {Element[]} */
|
||||||
const repeatedPatternArray = []
|
const blockContent = []
|
||||||
|
|
||||||
// get start branch "right" content
|
// get start branch "right" content
|
||||||
for(const startAncestor of startAncestry){
|
for(const startAncestor of startAncestryToCommonAncestor){
|
||||||
if(startAncestor === startChild)
|
if(startAncestor === startChild)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
let sibling = startAncestor.nextSibling
|
let sibling = startAncestor.nextSibling
|
||||||
|
|
||||||
while(sibling) {
|
while(sibling) {
|
||||||
repeatedPatternArray.push(sibling)
|
blockContent.push(sibling)
|
||||||
sibling = sibling.nextSibling;
|
sibling = sibling.nextSibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,38 +150,38 @@ function extractBlockContent(blockStartNode, blockEndNode) {
|
|||||||
let sibling = startChild.nextSibling
|
let sibling = startChild.nextSibling
|
||||||
|
|
||||||
while(sibling !== endChild) {
|
while(sibling !== endChild) {
|
||||||
repeatedPatternArray.push(sibling)
|
blockContent.push(sibling)
|
||||||
sibling = sibling.nextSibling;
|
sibling = sibling.nextSibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get end branch "left" content
|
// get end branch "left" content
|
||||||
for(const endAncestor of [...endAncestry].reverse()){
|
for(const endAncestor of [...endAncestryToCommonAncestor].reverse()){
|
||||||
if(endAncestor === endChild)
|
if(endAncestor === endChild)
|
||||||
continue; // already taken care of
|
continue; // already taken care of
|
||||||
|
|
||||||
let sibling = endAncestor.previousSibling
|
let sibling = endAncestor.previousSibling
|
||||||
|
|
||||||
const reversedRepeatedPatternArrayContribution = []
|
const reversedBlockContentContribution = []
|
||||||
|
|
||||||
while(sibling) {
|
while(sibling) {
|
||||||
reversedRepeatedPatternArrayContribution.push(sibling)
|
reversedBlockContentContribution.push(sibling)
|
||||||
sibling = sibling.previousSibling;
|
sibling = sibling.previousSibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
const repeatedPatternArrayContribution = reversedRepeatedPatternArrayContribution.reverse()
|
const blockContentContribution = reversedBlockContentContribution.reverse()
|
||||||
|
|
||||||
repeatedPatternArray.push(...repeatedPatternArrayContribution)
|
blockContent.push(...blockContentContribution)
|
||||||
|
|
||||||
if(endAncestor === blockEndNode)
|
if(endAncestor === blockEndNode)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//console.log('repeatedPatternArray', repeatedPatternArray.map(n => n.textContent))
|
//console.log('blockContent', blockContent.map(n => n.textContent))
|
||||||
|
|
||||||
|
|
||||||
for(const sibling of repeatedPatternArray) {
|
for(const sibling of blockContent) {
|
||||||
sibling.parentNode?.removeChild(sibling)
|
sibling.parentNode?.removeChild(sibling)
|
||||||
contentFragment.appendChild(sibling)
|
contentFragment.appendChild(sibling)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user