snippets/miniflux_scripts/feed_organizer.js

42 lines
1.2 KiB
JavaScript

(function() {
'use strict';
function groupItemsByAuthor() {
const items = document.querySelectorAll('.item.entry-item');
if (!items.length) {
setTimeout(groupItemsByAuthor, 500); // Retry after 500 ms
return;
}
const grouped = {};
items.forEach(item => {
const author = item.querySelector('.item-meta-info-title a').innerText.trim();
if (!grouped[author]) {
grouped[author] = [];
}
grouped[author].push(item);
});
const container = document.querySelector('.items');
while (container.firstChild) {
container.removeChild(container.firstChild);
}
Object.keys(grouped).forEach(author => {
const block = document.createElement('div');
block.classList.add('author-block');
const header = document.createElement('h2');
header.textContent = author;
block.appendChild(header);
grouped[author].forEach(item => {
block.appendChild(item);
});
container.appendChild(block);
});
}
setTimeout(groupItemsByAuthor, 500); // Delay after initial page loading
})();