optimize cleanup search query shop api extends part 2
This commit is contained in:
@@ -179,6 +179,59 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
cleanupEmptyBlocks(container);
|
||||
}
|
||||
|
||||
function hasVisibleContentAfterNode(container, markerNode) {
|
||||
const walker = document.createTreeWalker(
|
||||
container,
|
||||
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
|
||||
null
|
||||
);
|
||||
|
||||
let afterMarker = false;
|
||||
|
||||
while (walker.nextNode()) {
|
||||
const node = walker.currentNode;
|
||||
|
||||
if (node === markerNode) {
|
||||
afterMarker = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!afterMarker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
if (node.parentElement?.closest('.think')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((node.textContent || '').trim() !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.nodeType !== Node.ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.classList?.contains('think') || node.closest?.('.think')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.tagName === 'BR') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((node.textContent || '').trim() !== '' || hasMeaningfulChildContent(node)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function cleanupThinkSpans(container) {
|
||||
if (!container) {
|
||||
return;
|
||||
@@ -191,12 +244,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasNonThinkContent(container)) {
|
||||
removeThinkSpansOnly(container);
|
||||
const lastThink = thinkSpans[thinkSpans.length - 1];
|
||||
|
||||
if (!hasVisibleContentAfterNode(container, lastThink)) {
|
||||
keepOnlyLastThink(container);
|
||||
return;
|
||||
}
|
||||
|
||||
keepOnlyLastThink(container);
|
||||
removeThinkSpansOnly(container);
|
||||
}
|
||||
|
||||
function renderBubbleContent(bubble, raw) {
|
||||
|
||||
Reference in New Issue
Block a user