Files
snippets/miniflux_scripts/feed_count_sort_controls.js

32 lines
1.1 KiB
JavaScript

// feed count sort controls
(function() {
'use strict';
if (!window.location.href.match(/\/feeds$/)) return;
function parseTotal(feed) {
const spans = feed.querySelectorAll('.feed-entries-counter span[aria-hidden="true"]');
return spans[3] ? parseInt(spans[3].textContent, 10) : 0;
}
function sortFeeds(desc) {
const feeds = Array.from(document.querySelectorAll('article.item.feed-item'));
if (!feeds.length) return;
const parent = feeds[0].parentNode;
feeds
.sort((a, b) => desc
? parseTotal(b) - parseTotal(a)
: parseTotal(a) - parseTotal(b)
)
.forEach(f => parent.appendChild(f));
}
const navList = document.querySelector('nav[aria-label="Feeds Menu"] ul');
if (!navList) return;
['↑', '↓'].forEach((arrow, idx) => {
const li = document.createElement('li');
const btn = document.createElement('button');
btn.className = 'page-link';
btn.type = 'button';
btn.textContent = `Entries ${arrow}`;
btn.onclick = () => sortFeeds(idx === 1);
li.appendChild(btn);
navList.appendChild(li);
});
})();