diff --git a/miniflux_scripts/entries_duration_filter.js b/miniflux_scripts/entries_duration_filter.js index f3a24b3..279ccd5 100644 --- a/miniflux_scripts/entries_duration_filter.js +++ b/miniflux_scripts/entries_duration_filter.js @@ -30,43 +30,57 @@ document.querySelectorAll('article.item.entry-item').forEach(entry => { const mins = parseMinutes(entry.querySelector('.item-meta-info-reading-time span')); - if (mins !== null) { - if (mins <= SHORT_MAX) { - stylize(entry, { - bg: 'rgb(37, 44, 39)', - border: 'rgb(79, 194, 20)', - hoverBorder: 'rgb(129, 255, 50)', - hoverGlow: 'rgba(129, 255, 50, .8)', - }); - entry.dataset.readCategory = 'short'; - } else if (mins >= LONG_MIN) { - stylize(entry, { - bg: 'rgb(44, 39, 37)', - border: 'rgb(194, 79, 20)', - hoverBorder: 'rgb(255, 129, 50)', - hoverGlow: 'rgba(255, 129, 50, .8)', - }); - entry.dataset.readCategory = 'long'; - } + if (mins === null) return; + if (mins <= SHORT_MAX) { + stylize(entry, { + bg: 'rgb(37, 44, 39)', + border: 'rgb(79, 194, 20)', + hoverBorder: 'rgb(129, 255, 50)', + hoverGlow: 'rgba(129, 255, 50, .8)', + }); + entry.dataset.readCategory = 'short'; + } else if (mins >= LONG_MIN) { + stylize(entry, { + bg: 'rgb(44, 39, 37)', + border: 'rgb(194, 79, 20)', + hoverBorder: 'rgb(255, 129, 50)', + hoverGlow: 'rgba(255, 129, 50, .8)', + }); + entry.dataset.readCategory = 'long'; } }); function addFilter(label, category) { const nav = document.querySelector('.page-header nav ul'); - if (!nav) return; + const entries = document.querySelectorAll('article.item.entry-item'); + if (!nav || entries.length === 0) return; // no content -> no button + + const mapping = { + short: { border: 'rgb(79, 194, 20)', bg: 'rgb(37, 44, 39)' }, + long: { border: 'rgb(194, 79, 20)', bg: 'rgb(44, 39, 37)' }, + all: { border: '#ccc', bg: '#ccc' }, + }; + const m = mapping[category]; + const btn = document.createElement('button'); btn.textContent = `Filter: ${label}`; Object.assign(btn.style, { marginLeft: '10px', padding: '5px 10px', - border: '1px solid rgb(79, 194, 20)', + border: `1px solid ${m.border}`, borderRadius: '5px', - backgroundColor: 'rgb(37, 44, 39)', - color: '#fff', + backgroundColor: m.bg, + color: category === 'all' ? '#000' : '#fff', cursor: 'pointer', }); + btn.addEventListener('mouseover', () => { + btn.style.borderColor = category === 'all' ? '#999' : m.border; + }); + btn.addEventListener('mouseout', () => { + btn.style.borderColor = m.border; + }); btn.onclick = () => { - document.querySelectorAll('article.item.entry-item').forEach(e => { + entries.forEach(e => { e.style.display = (category === 'all' || e.dataset.readCategory === category) ? '' : 'none'; }); };