eBay Shipping Cost Calculator

Adds shipping cost to item price in eBay search results

// ==UserScript==
// @name         eBay Shipping Cost Calculator
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Adds shipping cost to item price in eBay search results
// @author       none
// @match        https://www.ebay.com/sch/*
// @icon         https://www.ebay.com/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let processing = false;
    let debounceTimer;
    
    function addShippingToPrices() {
        if (processing) return;
        processing = true;
        
        // Only process new items that don't have totals yet
        const items = document.querySelectorAll('.s-item__wrapper:not(.processed)');
        
        items.forEach(item => {
            item.classList.add('processed');
            
            const priceEl = item.querySelector('.s-item__price');
            if (!priceEl) return;
            
            const shippingEl = item.querySelector('.s-item__shipping');
            if (!shippingEl) return;
            
            const priceText = priceEl.textContent.trim();
            const shippingText = shippingEl.textContent.trim();
            
            const price = parsePrice(priceText);
            const shipping = parseShipping(shippingText);
            
            if (price && shipping) {
                const total = price + shipping;
                let totalEl = item.querySelector('.s-item__total');
                if (!totalEl) {
                    totalEl = document.createElement('div');
                    totalEl.className = 's-item__total';
                    priceEl.parentNode.insertBefore(totalEl, priceEl.nextSibling);
                }
                totalEl.textContent = `Total: $${total.toFixed(2)}`;
                totalEl.style.color = '#e42648';
                totalEl.style.fontWeight = 'bold';
            }
        });
        
        processing = false;
    }
    
    function parsePrice(text) {
        const match = text.match(/\$([\d,.]+)/);
        if (!match) return null;
        return parseFloat(match[1].replace(/,/g, ''));
    }
    
    function parseShipping(text) {
        if (text.includes('Free')) return 0;
        const match = text.match(/\+\$([\d,.]+)/);
        if (!match) return null;
        return parseFloat(match[1].replace(/,/g, ''));
    }
    
    // Debounced handler for mutations
    function handleMutations() {
        clearTimeout(debounceTimer);
        debounceTimer = setTimeout(addShippingToPrices, 300);
    }
    
    // Run on initial load
    addShippingToPrices();
    
    // Only observe direct children of main container
    const container = document.querySelector('.srp-river-main');
    if (container) {
        const observer = new MutationObserver(handleMutations);
        observer.observe(container, { 
            childList: true, 
            subtree: false,
            attributes: false,
            characterData: false
        });
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址