tablefilter

Adds filter dropdowns to the top row of any .table

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         tablefilter
// @namespace    crinfarr.io
// @version      2024-07-12
// @description  Adds filter dropdowns to the top row of any .table
// @author       Crinfarr
// @match        *://*/*
// @grant        none
// @run-at       context-menu
// ==/UserScript==

(function() {
    for (let table of document.getElementsByClassName("table")) {
        let headers = table.getElementsByTagName('thead')[0].children[0].children;
        for (let headeridx in headers) {
            let ipt = document.createElement('input');
            ipt.type = 'text';
            ipt.addEventListener("change", () => {
                for (let row of table.getElementsByTagName('tbody')[0].children) {
                    if (ipt.value == '') {
                        row.hidden = false;
                    }
                    let cell = row.children[headeridx]
                    let filters = ipt.value.split(/(?!<\\)\|\|/gm).map(s => s.trim());
                    if (filters.some((filter) => {
                        return cell.innerText.includes(filter);
                    })) {
                        console.log(`${cell.innerText} contains ${filters}`);
                        row.hidden = false;
                    } else {
                        console.log(`${cell.innerText} does not contain ${filters}`);
                        row.hidden = true;
                    }
                }
            });
            headers[headeridx].appendChild(ipt);
        }
    }
})();