From 8b4b8701b5bb79f2ccbb0c2a1a5b1bd18855ddb0 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Wed, 3 Sep 2025 11:58:45 +0000 Subject: [PATCH] feat(auto-summary-styler): handle tools recommandations --- miniflux_scripts/auto-summary-styler.js | 89 +++++++++++++++---------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/miniflux_scripts/auto-summary-styler.js b/miniflux_scripts/auto-summary-styler.js index 7b284dd..981b3f6 100644 --- a/miniflux_scripts/auto-summary-styler.js +++ b/miniflux_scripts/auto-summary-styler.js @@ -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); } -})(); \ No newline at end of file +})();