Tokopedia results filter

Instant refiltering for Tokopedia results by exact string (case-insensitive)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Tokopedia results filter
// @namespace    http://tampermonkey.net/
// @version      2025-12-29
// @description  Instant refiltering for Tokopedia results by exact string (case-insensitive)
// @author       You
// @match        https://www.tokopedia.com/search*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tokopedia.com
// @grant        none
// @license      WTFPL
// ==/UserScript==

(function() {
    'use strict';

    const filter = (str) => {
        const results = [...document.querySelectorAll('div[data-ssr="contentProductsSRPSSR"] a')];
        results.forEach(el => {el.parentNode.style.display = ""});
        if (str) {
            results
                .filter(el => !el.innerText.match(new RegExp(str, "i")))
                .forEach(el => {el.parentNode.style.display = 'none'});
        }
    }

    const div = document.createElement('div');
    div.id = 'topedfilter';
    div.style.position = 'fixed';
    div.style.bottom = 0;
    div.style.right = 0;
    div.style.padding = '20px';
    div.style.backgroundColor = 'deepskyblue';
    div.style.zIndex = 1000;

    const filterInput = document.createElement('input');
    filterInput.placeholder = 'Filter...';
    filterInput.addEventListener('keyup', (e) => {
        filter(filterInput.value);
    });

    div.appendChild(filterInput);
    document.body.appendChild(div);

    let lastScrollPos = window.scrollY;

    document.addEventListener('scroll', () => {
        if (Math.abs(window.scrollY - lastScrollPos) < 20) return;
        lastScrollPos = window.scrollY;
        if (filterInput.value) {
            filter(filterInput.value);
        }
    });
})();