optimize cleanup search query shop api extends part 2

This commit is contained in:
team2
2026-04-25 22:47:50 +02:00
parent 6cf8aac872
commit 2797834a5f
5 changed files with 119 additions and 12 deletions

View File

@@ -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) {