Add a button to filter articles based on whether their title contains the ⏳ emoji (after reading time generation)
当前为
// ==UserScript==
// @name RSS: FreshRSS Filter Articles by Title (Obsolete)
// @namespace http://tampermonkey.net/
// @version 1.9
// @homepage https://greasyfork.org/en/scripts/526410
// @description Add a button to filter articles based on whether their title contains the ⏳ emoji (after reading time generation)
// @author You
// @match http://192.168.1.2:1030/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Variable to track the hidden state
let isHidden = false;
// Function to filter divs
function filterDivs() {
const divs = document.querySelectorAll('.flux');
divs.forEach(div => {
const titleElement = div.querySelector('.title');
if (titleElement) {
const titleText = titleElement.textContent || titleElement.innerText;
if (!titleText.includes('⏳')) {
div.style.display = isHidden ? '' : 'none';
}
}
});
// Toggle the button text
const button = document.getElementById('filterButton');
if (button) {
button.textContent = isHidden ? '⏳' : '🌎';
}
// Toggle the hidden state
isHidden = !isHidden;
}
// Function to load all articles
async function loadAllArticles() {
const loadMoreButton = document.getElementById('load_more');
if (loadMoreButton && !loadMoreButton.disabled) {
// Show loading hint
const loadingHint = document.getElementById('loadingHint');
if (loadingHint) {
loadingHint.style.display = 'block';
}
loadMoreButton.click(); // Click the "Load more articles" button
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for articles to load
await loadAllArticles(); // Recursively load more articles
// Hide loading hint after loading is complete
if (loadingHint) {
loadingHint.style.display = 'none';
}
}
}
// Create the button
const button = document.createElement('a');
button.id = 'filterButton';
button.className = 'btn'; // Match the class of other navigation buttons
button.href = '#'; // Add a placeholder href to match the style
button.title = 'Filter by ⏳'; // Add a tooltip
button.textContent = '⏳'; // Use emoji directly
// Create the loading hint element
const loadingHint = document.createElement('div');
loadingHint.id = 'loadingHint';
loadingHint.textContent = 'Loading all articles...';
loadingHint.style.display = 'none'; // Initially hidden
loadingHint.style.marginTop = '10px';
loadingHint.style.fontStyle = 'italic';
loadingHint.style.color = '#666';
// Add click event listener to the button
button.addEventListener('click', async (e) => {
e.preventDefault(); // Prevent the default link behavior
// Load all articles before filtering
await loadAllArticles();
// Filter the articles
filterDivs();
});
// Find the last .group div and insert the button and loading hint after it
const lastGroupDiv = document.querySelector('.group:last-of-type');
if (lastGroupDiv) {
lastGroupDiv.parentNode.insertBefore(button, lastGroupDiv.nextSibling);
lastGroupDiv.parentNode.insertBefore(loadingHint, button.nextSibling);
} else {
console.error('Could not find the last .group element.');
}
})();