Amazon Orders - Stats

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();
})();