eBay Hide Price Range Items

Hide eBay listings that have price ranges. Based on https://greasyfork.org/en/scripts/28968-pricerangeitemhider by Lars Simonsen, fixed with Claude.ai for 2025 ebay updated code.

// ==UserScript==
// @name         eBay Hide Price Range Items
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Hide eBay listings that have price ranges. Based on https://greasyfork.org/en/scripts/28968-pricerangeitemhider by Lars Simonsen, fixed with Claude.ai for 2025 ebay updated code.
// @author       Claude
// @match        https://www.ebay.co.uk/*
// @match        https://www.ebay.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Add CSS styles
    $('head').append('<style>' +
        '.hiddenRangeItem { background-color: #eee; }' +
        '.showHiddenRangeItem { cursor: pointer; background-color: #eee; border: 1px solid #ddd; margin: 1em; padding: 0.25em; text-align: center; }' +
        '.showHiddenRangeItem.showing { color: white; background-color: black; }' +
        '.showHiddenRangeItem.hiding .hideIt, .showHiddenRangeItem.showing .showIt { display: none; }' +
    '</style>');

    function hideRangeItem($el) {
        $el.addClass('hiddenRangeItem').hide().before('<div class="showHiddenRangeItem hiding"><span class="showIt">Show</span><span class="hideIt">Hide</span> price range item</div>');
        $el.prev('.showHiddenRangeItem').click(function() {
            $(this).toggleClass('showing hiding').next('.hiddenRangeItem').slideToggle();
        });
    }

    function hideRangeItems() {
        // Look for price rows that contain " to " text between price spans
        $('.s-card__attribute-row').each(function() {
            const $row = $(this);
            const $priceSpans = $row.find('.s-card__price');

            // Check if this row has multiple price spans and contains " to "
            if ($priceSpans.length > 1) {
                // Check if any span in this row contains " to "
                let hasToSpan = false;
                $priceSpans.each(function() {
                    if ($(this).text().trim() === 'to') {
                        hasToSpan = true;
                        return false; // break out of each loop
                    }
                });

                if (hasToSpan) {
                    // Find the parent li element (the actual item container)
                    const $item = $row.closest('li.s-card');
                    if ($item.length && !$item.hasClass('hiddenRangeItem')) {
                        console.log('Hiding price range item:', $item.find('.s-card__title').text().trim());
                        hideRangeItem($item);
                    }
                }
            }
        });
    }

    // Run initially and then periodically to catch dynamically loaded content
    $(document).ready(function() {
        hideRangeItems();
        setInterval(hideRangeItems, 2000);
    });

    // Also run when new content is loaded (for infinite scroll, etc.)
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes.length) {
                setTimeout(hideRangeItems, 500);
            }
        });
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();