diff --git a/scripts/ebaypricer.js b/scripts/ebaypricer.js new file mode 100644 index 0000000..d7c56c6 --- /dev/null +++ b/scripts/ebaypricer.js @@ -0,0 +1,48 @@ +// ==UserScript== +// @name ebay pricer +// @namespace ebay-pricer +// @version 1.0 +// @description Adds shipping costs into the displayed ebay listing price. +// @author Stabosa87 +// @match https://www.ebay.com/* +// @grant none +// ==/UserScript== + +(function () { + function money(text) { + let m = text.match(/\$([\d.]+)/); + return m ? parseFloat(m[1]) : 0; + } + + function update() { + document.querySelectorAll("li.s-card").forEach(card => { + + if (card.dataset.priced) return; + + let pricel = card.querySelector(".s-card__price"); + if (!pricel) return; + + let price = money(pricel.textContent); + let shipping = 0; + + card.querySelectorAll(".s-card__attribute-row").forEach(row => { + if (row.textContent.includes("delivery") && row.textContent.includes("+$")) { + shipping = money(row.textContent); + } + }); + + if (shipping > 0) { + pricel.innerHTML += ` (or $${(price + shipping).toFixed(2)} total)`; + } + + card.dataset.priced = 1; + }); + } + + update(); + + new MutationObserver(update).observe(document.body, { + childList: true, + subtree: true + }); +})();