feat(auto-summary-styler): handle tools recommandations

This commit is contained in:
2025-09-03 11:58:45 +00:00
parent 8c2fe82238
commit 8b4b8701b5

View File

@@ -11,43 +11,60 @@
const allElements = content.querySelectorAll('*');
allElements.forEach(element => {
if (element.textContent.includes('RÉSUMÉ AUTO') && !element.dataset.processed) {
// Find the actual container (could be this element or a parent)
let container = element;
while (container && !['P', 'DIV', 'ARTICLE'].includes(container.tagName)) {
container = container.parentElement;
}
if (container) {
container.dataset.processed = 'true';
// Style the whole fucking container
Object.assign(container.style, {
margin: '12px 0',
padding: '10px',
background: 'rgb(51 85 67)',
borderLeft: '3px solid rgb(71 180 103)',
fontFamily: 'Geist Mono',
whiteSpace: 'pre-wrap'
});
if (!element || element.dataset.processed) return;
const txt = element.textContent || '';
const m = txt.match(/---\s*(RÉSUMÉ AUTO|RECOMMANDATIONS)\s*---/i);
if (!m) return;
// Clean and add header
container.innerHTML = container.innerHTML
.replace(/---\s*RÉSUMÉ AUTO\s*---/gi, '')
.replace(/^\s*RÉSUMÉ AUTO\s*/gi, '');
const header = document.createElement('div');
header.textContent = 'RÉSUMÉ AUTO';
Object.assign(header.style, {
fontWeight: 'bold',
marginBottom: '8px',
color: 'rgb(71 180 103)',
fontSize: '0.9em'
});
container.insertBefore(header, container.firstChild);
}
let container = element;
while (container && !['P', 'DIV', 'ARTICLE', 'SECTION', 'LI'].includes(container.tagName)) {
container = container.parentElement;
}
if (!container || container.dataset.processed) return;
const type = m[1].toUpperCase().includes('RÉSUMÉ') ? 'resume' : 'reco';
const wrapper = document.createElement('div');
container.parentElement.insertBefore(wrapper, container);
wrapper.appendChild(container);
while (wrapper.nextElementSibling && ['P','DIV','UL','OL','PRE','BLOCKQUOTE','TABLE'].includes(wrapper.nextElementSibling.tagName)) {
const next = wrapper.nextElementSibling;
if ((next.textContent || '').match(/---\s*(RÉSUMÉ AUTO|RECOMMANDATIONS)\s*---/i)) break;
wrapper.appendChild(next);
}
wrapper.dataset.processed = 'true';
Object.assign(wrapper.style, {
margin: '12px 0',
padding: '10px',
background: type === 'resume' ? 'rgb(51 85 67)' : 'rgb(46 61 88)',
borderLeft: type === 'resume' ? '3px solid rgb(71 180 103)' : '3px solid rgb(99 155 255)',
fontFamily: 'Geist Mono',
whiteSpace: 'pre-wrap'
});
const textIterator = document.createNodeIterator(wrapper, NodeFilter.SHOW_TEXT);
let t;
while ((t = textIterator.nextNode())) {
t.nodeValue = t.nodeValue
.replace(/---\s*RÉSUMÉ AUTO\s*---/gi, '')
.replace(/^\s*RÉSUMÉ AUTO\s*/gi, '')
.replace(/---\s*RECOMMANDATIONS\s*---/gi, '')
.replace(/^\s*RECOMMANDATIONS\s*/gi, '');
}
const header = document.createElement('div');
header.textContent = type === 'resume' ? 'RÉSUMÉ AUTO' : 'RECOMMANDATIONS';
Object.assign(header.style, {
fontWeight: 'bold',
marginBottom: '8px',
color: type === 'resume' ? 'rgb(71 180 103)' : 'rgb(99 155 255)',
fontSize: '0.9em'
});
wrapper.insertBefore(header, wrapper.firstChild);
});
}
@@ -56,4 +73,4 @@
} else {
window.addEventListener('load', styleAutoSummaries);
}
})();
})();