Amazon Orders - Stats

Counts the number of orders and the total spent on Amazon.fr

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Amazon Orders - Stats
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Counts the number of orders and the total spent on Amazon.fr
// @author       MERCRED
// @match        https://www.amazon.fr/your-orders/orders*
// @match        https://www.amazon.us/your-orders/orders*
// @match        https://www.amazon.de/your-orders/orders*
// @match        https://www.amazon.it/your-orders/orders*
// @match        https://www.amazon.es/your-orders/orders*
// @match        https://www.amazon.nl/your-orders/orders*
// @match        https://www.amazon.se/your-orders/orders*
// @match        https://www.amazon.pl/your-orders/orders*
// @match        https://www.amazon.in/your-orders/orders*
// @match        https://www.amazon.com/your-orders/orders*
// @match        https://www.amazon.com.mx/your-orders/orders*
// @match        https://www.amazon.co.uk/your-orders/orders*
// @match        https://www.amazon.co.jp/your-orders/orders*
// @match        https://www.amazon.com.au/your-orders/orders*
// @match        https://www.amazon.com.be/your-orders/orders*
// @grant        none
// @icon         https://upload.wikimedia.org/wikipedia/commons/d/de/Amazon_icon.png
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let currency = '€';

    function parsePrice(text) {
        if (!text) return 0;
        let matchCurrency = text.match(/[€$£]/);
        if (matchCurrency) currency = matchCurrency[0];

        text = text.replace(/[\s€$£]/g, '').replace(',', '.');
        let value = parseFloat(text);
        return isNaN(value) ? 0 : value;
    }

    function analyzeOrders() {
        let orders = document.querySelectorAll("div.order-card.js-order-card");
        let total = 0;

        orders.forEach(order => {
            let priceEl = Array.from(order.querySelectorAll("span.a-size-base.a-color-secondary.aok-break-word"))
                .find(el => /[€$£]/.test(el.innerText));

            if (priceEl) {
                let text = priceEl.innerText.trim();
                let numbers = text.match(/[\d.,]+/g);
                if (numbers && numbers.length > 0) {
                    let num = numbers[numbers.length - 1];
                    total += parsePrice(num);
                }
            }
        });

        return { count: orders.length, total };
    }

    function createUI(stats) {
        let ui = document.createElement("div");
        ui.id = "amazon-orders-stats";
        ui.style.position = "fixed";
        ui.style.top = "150px";
        ui.style.left = "10px";
        ui.style.background = "white";
        ui.style.border = "2px solid #232f3e";
        ui.style.borderRadius = "8px";
        ui.style.padding = "10px";
        ui.style.zIndex = "9999";
        ui.style.boxShadow = "0 2px 6px rgba(0,0,0,0.3)";
        ui.style.fontSize = "14px";
        ui.style.fontFamily = "Arial, sans-serif";
        ui.innerHTML = `
            <b>📦 Amazon Stats</b><br>
            Orders : ${stats.count}<br>
            Total : ${stats.total.toFixed(2)} ${currency}
        `;
        document.body.appendChild(ui);
    }

    function init() {
        let tries = 0;
        let timer = setInterval(() => {
            let orders = document.querySelectorAll("div.order-card.js-order-card");
            if (orders.length > 0) {
                clearInterval(timer);
                let stats = analyzeOrders();
                createUI(stats);
            } else {
                tries++;
                if (tries > 40) clearInterval(timer);
            }
        }, 500);
    }

    init();
})();