eBay Price + Shipping

Adds shipping cost to item price in eBay search results

// ==UserScript==
// @name         eBay Price + Shipping
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds shipping cost to item price in eBay search results
// @match        https://www.ebay.com/sch/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to add shipping to price without repeating calculations
    function addShippingToPrice() {
        // Select all items in search results
        const items = document.querySelectorAll('.s-item');

        items.forEach((item) => {
            // Skip items that have already been updated
            if (item.classList.contains('shipping-added')) return;

            // Find the price and shipping elements
            const priceElement = item.querySelector('.s-item__price');
            const shippingElement = item.querySelector('.s-item__shipping');

            if (priceElement && shippingElement) {
                // Parse the prices and shipping cost
                const priceText = priceElement.innerText.replace(/[^0-9.]/g, '');
                const shippingText = shippingElement.innerText.includes("Free")
                    ? "0"
                    : shippingElement.innerText.replace(/[^0-9.]/g, '');

                const price = parseFloat(priceText);
                const shipping = parseFloat(shippingText);

                if (!isNaN(price) && !isNaN(shipping)) {
                    // Add shipping to price and update the display
                    const totalPrice = (price + shipping).toFixed(2);
                    priceElement.innerText = `$${totalPrice}`;

                    // Mark item as updated to prevent re-calculation
                    item.classList.add('shipping-added');
                }
            }
        });
    }

    // Run function on page load and when new items load (e.g., scroll loading)
    addShippingToPrice();
    document.addEventListener('scroll', addShippingToPrice);
})();