feat(auto-summary-styler): handle tools recommandations
This commit is contained in:
@@ -11,43 +11,60 @@
|
|||||||
const allElements = content.querySelectorAll('*');
|
const allElements = content.querySelectorAll('*');
|
||||||
|
|
||||||
allElements.forEach(element => {
|
allElements.forEach(element => {
|
||||||
if (element.textContent.includes('RÉSUMÉ AUTO') && !element.dataset.processed) {
|
if (!element || element.dataset.processed) return;
|
||||||
// Find the actual container (could be this element or a parent)
|
const txt = element.textContent || '';
|
||||||
let container = element;
|
const m = txt.match(/---\s*(RÉSUMÉ AUTO|RECOMMANDATIONS)\s*---/i);
|
||||||
while (container && !['P', 'DIV', 'ARTICLE'].includes(container.tagName)) {
|
if (!m) return;
|
||||||
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'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean and add header
|
let container = element;
|
||||||
container.innerHTML = container.innerHTML
|
while (container && !['P', 'DIV', 'ARTICLE', 'SECTION', 'LI'].includes(container.tagName)) {
|
||||||
.replace(/---\s*RÉSUMÉ AUTO\s*---/gi, '')
|
container = container.parentElement;
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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 {
|
} else {
|
||||||
window.addEventListener('load', styleAutoSummaries);
|
window.addEventListener('load', styleAutoSummaries);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Reference in New Issue
Block a user