Last active
May 26, 2026 13:41
-
-
Save pedrolamas/debcf696ed94890e083595eff5276f96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Show Totals | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2026-02-23 | |
| // @description show totals | |
| // @author Pedro Lamas | |
| // @match https://www.johnpyeauctions.co.uk/Event/LotDetails/* | |
| // @match https://www.johnpyeauctions.co.uk/Event/Details/* | |
| // @match https://www.johnpyeauctions.co.uk/Browse* | |
| // @match https://www.johnpyeauctions.co.uk/Account/Bidding/Watching | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=johnpyeauctions.co.uk | |
| // @grant GM_getValue | |
| // @grant GM_setValue | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const CACHE_KEY = 'jpa_shipping_cache'; | |
| const CACHE_TTL_MS = 10 * 24 * 60 * 60 * 1000; // 10 days | |
| const now = Date.now(); | |
| const getValue = (x) => +(/[$€£](\d+\.\d+)/.exec(x.innerText)[1]); | |
| const getListingIdAndShippingCost = (listingElement) => { | |
| const listingId = listingElement.getAttribute('data-listingid'); | |
| const shippingTableElement = listingElement.getElementsByClassName("shipping-table")[0]; | |
| if (shippingTableElement) { | |
| const shippingCost = getValue(shippingTableElement); | |
| cache[listingId] = { | |
| value: shippingCost, | |
| timestamp: now | |
| }; | |
| return { | |
| listingId, | |
| shippingCost | |
| }; | |
| } | |
| return { | |
| listingId, | |
| shippingCost: cache[listingId]?.value ?? 7.99 | |
| }; | |
| } | |
| const updateObservedElementTotal = (element, calculateTotal) => { | |
| element.nextElementSibling.innerText = ` // ${element.previousSibling.textContent.trim()}${calculateTotal(+element.innerText).toFixed(2)}`; | |
| }; | |
| const vatOnlyOnBuyersPremium = /VAT Only Payable on Buyers Premium/.test(document.title); | |
| const rawCache = GM_getValue(CACHE_KEY, {}); | |
| const cache = Object.fromEntries( | |
| Object.entries(rawCache).filter(([, entry]) => now - entry.timestamp <= CACHE_TTL_MS) | |
| ) | |
| const listingElements = document.querySelectorAll('div[data-listingid]'); | |
| for (const listingElement of listingElements) { | |
| const { listingId, shippingCost } = getListingIdAndShippingCost(listingElement); | |
| const calculateTotal = vatOnlyOnBuyersPremium | |
| ? (value) => value + (value * 0.25 + shippingCost) * 1.2 | |
| : (value) => (value * 1.25 + shippingCost) * 1.2; | |
| const bidAmountElement = document.getElementById("BidAmount"); | |
| if (bidAmountElement && bidAmountElement.type != "hidden") { | |
| const updateBidAmountTotal = () => { | |
| bidAmountElement.nextElementSibling.innerText = calculateTotal(+bidAmountElement.value).toFixed(2); | |
| } | |
| bidAmountElement.oninput = updateBidAmountTotal; | |
| updateBidAmountTotal(); | |
| } | |
| const elementsToObserve = listingElement.querySelectorAll('span.NumberPart'); | |
| const observer = new MutationObserver(() => { | |
| for (const element of elementsToObserve) { | |
| updateObservedElementTotal(element, calculateTotal); | |
| } | |
| }); | |
| for (const element of elementsToObserve) { | |
| element.insertAdjacentHTML("afterEnd", "<span></span>"); | |
| updateObservedElementTotal(element, calculateTotal); | |
| observer.observe(element, { childList: true }); | |
| } | |
| } | |
| GM_setValue(CACHE_KEY, cache); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment