snippets/miniflux_scripts/feed_classifier.js

56 lines
1.8 KiB
JavaScript

(function() {
'use strict';
// Check if the URL matches the specific pattern
if (!window.location.href.match(/\/feed\/\d+\/entries\/all$/)) {
return; // Exit if the URL does not match
}
function calculateAndDisplayStatus() {
const entries = Array.from(document.querySelectorAll('article.item.entry-item'));
const totalEntries = entries.length;
if (totalEntries === 0) return;
let starredCount = 0;
entries.forEach(entry => {
const isStarred = entry.querySelector('li.item-meta-icons-star button[data-value="star"]') !== null;
if (isStarred) {
starredCount++;
}
});
const percentageStarred = (starredCount / totalEntries) * 100;
let statusEmoji = '';
let statusText = '';
if (totalEntries < 10) {
statusEmoji = '💭';
statusText = 'Thinking';
} else if (percentageStarred > 40) {
statusEmoji = '😍';
statusText = 'Interesting';
} else if (percentageStarred > 20) {
statusEmoji = '🤔';
statusText = 'Thinking';
} else {
statusEmoji = '🥱';
statusText = 'Boring';
}
// Calculate the score as a ratio
const score = `${starredCount}/${totalEntries}`;
const feedHeader = document.querySelector('section.page-header');
const statusElement = document.createElement('span');
statusElement.style.fontSize = '1.5em';
statusElement.style.marginLeft = '10px';
statusElement.textContent = `${statusEmoji} ${score} - ${statusText}`;
feedHeader.appendChild(statusElement);
}
window.addEventListener('load', calculateAndDisplayStatus);
})();