Amazon 购买数量高亮

[EN] Highlights purchase quantity on Amazon | [CN] 高亮显示Amazon商品购买数量

// ==UserScript==
// @name         Amazon 购买数量高亮
// @namespace    https://gf.qytechs.cn/zh-CN/users/your-profile-id
// @version      1.1.0
// @description  [EN] Highlights purchase quantity on Amazon | [CN] 高亮显示Amazon商品购买数量
// @author       再见梵高 <[email protected]>
// @license      MIT
// @match          *://www.amazon.com/*
// @match          *://www.amazon.ca/*
// @match          *://www.amazon.co.uk/*
// @match          *://www.amazon.de/*
// @match          *://www.amazon.fr/*
// @match          *://www.amazon.it/*
// @match          *://www.amazon.es/*
// @icon         https://www.amazon.com/favicon.ico
// @grant        GM_addStyle
// @supportURL   mailto:[email protected]
// ==/UserScript==

(function() {
    'use strict';

    const CONFIG = {
        highlightClass: 'amz-pq-highlight',
        styleRules: {
            color: '#FF4444',
            fontSize: '18px',
            fontWeight: '900',
            textShadow: '0 0 3px rgba(255,68,68,0.4)',
            animation: 'pulse 1s ease-in-out infinite'
        },
        textPatterns: [
            /\d+\+?\s?(?:bought|purchased|sold)/i,
            /multiple\s+times/i,
            /past\s+(?:month|week)/i
        ]
    };

    GM_addStyle(`
        .${CONFIG.highlightClass} {
            color: ${CONFIG.styleRules.color} !important;
            font-size: ${CONFIG.styleRules.fontSize} !important;
            font-weight: ${CONFIG.styleRules.fontWeight} !important;
            text-shadow: ${CONFIG.styleRules.textShadow} !important;
            animation: ${CONFIG.styleRules.animation} !important;
        }
        @keyframes pulse {
            0%,100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }
        .social-proofing-faceout-title-text .${CONFIG.highlightClass} {
            display: inline-block;
        }
    `);

    function checkText(text) {
        return CONFIG.textPatterns.some(p => p.test(text));
    }

    function processElement(el) {
        if (el.classList.contains(CONFIG.highlightClass)) return;
        const text = el.textContent.trim();
        if (!checkText(text)) return;

        const parent = el.closest([
            '.a-row.a-size-base',
            '#socialProofingAsinFaceout_feature_div',
            '.social-proofing-faceout'
        ].join(','));
        if (!parent) return;

        const wrapper = document.createElement('span');
        wrapper.className = CONFIG.highlightClass;
        wrapper.innerHTML = el.innerHTML;
        el.parentNode.replaceChild(wrapper, el);
    }

    function applyHighlight() {
        document.querySelectorAll([
            'span.a-color-secondary',
            'span.a-text-bold',
            'span.social-proofing-faceout-title-text'
        ].join(',')).forEach(processElement);
    }

    applyHighlight();

    const observer = new MutationObserver(mutations => {
        mutations.some(m => m.addedNodes.length && applyHighlight());
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true,
        attributes: false
    });

    const events = ['page:change', 'spa-navigate', 'DOMContentLoaded'];
    events.forEach(e => window.addEventListener(e, applyHighlight));
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址