RSS: FreshRSS Filter Articles by Title (Obsolete)

Add a button to filter articles based on whether their title contains the ⏳ emoji (after reading time generation)

目前為 2025-03-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.');
    }
})();