Greasy Fork

8chan Catalog Filter

Filter catalog threads using regex patterns

当前为 2025-04-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         8chan Catalog Filter
// @version      1.0
// @description  Filter catalog threads using regex patterns
// @match        *://8chan.moe/*/catalog.*
// @grant        none
// @license MIT
// @namespace https://greasyfork.org/users/1459581
// ==/UserScript==

(function() {
    'use strict';

    const config = {
        filters: [
            {
                pattern: /Arknights|AKG/i, // Example regex pattern
                action: 'setTop' // 'setTop' or 'remove'
            },
            // Add more filters as needed
            // {
            //     pattern: /banner submissions/i,
            //     action: 'remove'
            // }
        ]
    };

    function processCatalog() {
        const catalogDiv = document.getElementById('divThreads');
        if (!catalogDiv) return;

        const cells = Array.from(catalogDiv.querySelectorAll('.catalogCell'));
        const matchedCells = [];

        cells.forEach(cell => {
            const subject = cell.querySelector('.labelSubject')?.textContent || '';
            const message = cell.querySelector('.divMessage')?.textContent || '';
            const text = `${subject} ${message}`;

            config.filters.forEach(filter => {
                if (filter.pattern.test(text)) {
                    if (filter.action === 'remove') {
                        cell.style.display = 'none';
                    } else if (filter.action === 'setTop') {
                        matchedCells.push(cell);
                        cell.style.order = -1;
                    }
                }
            });
        });

        // Bring matched cells to top
        matchedCells.reverse().forEach(cell => {
            catalogDiv.insertBefore(cell, catalogDiv.firstChild);
        });
    }

    // Run on initial load
    processCatalog();

    // Optional: Add mutation observer to handle dynamic updates
    const observer = new MutationObserver(processCatalog);
    observer.observe(document.body, { childList: true, subtree: true });
})();