ElectricUnicycles.eu Filter Models + Focus

Filter model cards by name on electricunicycles.eu and focus input automatically

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ElectricUnicycles.eu Filter Models + Focus
// @namespace    Violentmonkey Scripts
// @version      1.1
// @description  Filter model cards by name on electricunicycles.eu and focus input automatically
// @author       You
// @match        https://www.electricunicycles.eu/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function addFilterInput() {
        const sortButton = document.getElementById('button_catalog_sort');
        if (!sortButton) return;

        // Create input element
        const input = document.createElement('input');
        input.type = 'text';
        input.placeholder = 'Filter models...';
        input.style.marginLeft = '10px';
        input.style.padding = '5px';
        input.style.fontSize = '14px';
        input.style.border = '1px solid #ccc';
        input.style.borderRadius = '4px';

        // Insert the input after the button
        sortButton.parentNode.insertBefore(input, sortButton.nextSibling);

        // Focus the input automatically
        input.focus();

        // Listen to input events
        input.addEventListener('input', function() {
            const filterText = input.value.trim().toLowerCase();
            const modelTitles = document.querySelectorAll('.model-name h4');

            modelTitles.forEach(h4 => {
                const card = h4.closest('.box-store-item');
                if (!card) return;

                const modelName = h4.textContent.trim().toLowerCase();
                if (filterText === '' || modelName.includes(filterText)) {
                    card.style.display = '';
                } else {
                    card.style.display = 'none';
                }
            });
        });
    }

    // Wait for the page to fully load
    window.addEventListener('load', function() {
        addFilterInput();
    });
})();