Etsy Price Rounder

Rounds prices to the nearest $0.25

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Etsy Price Rounder
// @version      1.99
// @description  Rounds prices to the nearest $0.25
// @author       JustAnOkapi
// @match        https://www.etsy.com/*
// @grant        none
// @license      MIT
// @namespace    https://greasyfork.org/users/1198856
// ==/UserScript==

(function() {
    'use strict';

    // Function to round all prices
    function roundPrices() {
        // Round prices in class
        const priceElements = document.querySelectorAll('.currency-value');
        for (const priceElement of priceElements) {
            const priceValue = parseFloat(priceElement.textContent);
            if (!isNaN(priceValue)) {
                const roundedPrice = Math.round(priceValue * 4) / 4;
                priceElement.textContent = roundedPrice.toFixed(2);
            }
        }
        // Round prices in text nodes
        const textNodes = document.createTreeWalker(
            document.body,
            NodeFilter.SHOW_TEXT,
            null,
            false
        );

        while (textNodes.nextNode()) {
            const node = textNodes.currentNode;
            const text = node.textContent;

            // Use a regular expression to match prices in different formats
            const roundedText = text.replace(/\$(\d+\.\d{2})/g, (match, price) => {
                const roundedPrice = Math.round(parseFloat(price) * 4) / 4;
                return '$' + roundedPrice.toFixed(2);
            });

            if (roundedText !== text) {
                node.textContent = roundedText;
            }
        }
    }

    // Always up to date
    const observer = new MutationObserver(roundPrices);
    observer.observe(document.body, { childList: true, subtree: true });
})();