💰 Real Coupon Finder - Amazon

Auto-fetch real Amazon coupons from CouponFollow & apply best one!

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         💰 Real Coupon Finder - Amazon
// @namespace    https://1lm.me/codecopilot
// @version      1.1
// @description  Auto-fetch real Amazon coupons from CouponFollow & apply best one!
// @match        *://www.amazon.*/*
// @grant        GM_xmlhttpRequest
// @connect      couponfollow.com
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const waitForPrice = (selector, callback) => {
        const el = document.querySelector(selector);
        if (el) return callback(el);
        setTimeout(() => waitForPrice(selector, callback), 500);
    };

    const parsePrice = (text) => {
        const match = text.replace(/[^0-9.,]/g, '').match(/[\d.,]+/);
        if (!match) return null;
        return parseFloat(match[0].replace(',', ''));
    };

    const fetchCoupons = (callback) => {
        GM_xmlhttpRequest({
            method: "GET",
            url: "https://www.couponfollow.com/site/amazon.com",
            onload: function (response) {
                const parser = new DOMParser();
                const doc = parser.parseFromString(response.responseText, "text/html");
                const coupons = Array.from(doc.querySelectorAll('.coupon-code-block .coupon-code-text'))
                    .map(el => el.textContent.trim())
                    .filter(code => /^[A-Z0-9]{4,}$/.test(code));
                callback(coupons);
            }
        });
    };

    const injectButton = (priceElement, price) => {
        const btn = document.createElement('button');
        btn.textContent = '🔍 Fetch Real Coupons';
        btn.style = 'margin-top:10px;padding:8px 14px;background:#ff9900;color:#fff;border:none;border-radius:4px;cursor:pointer;';
        priceElement.parentElement.appendChild(btn);

        const resultBox = document.createElement('div');
        resultBox.style = 'margin-top:10px;font-weight:bold;';
        priceElement.parentElement.appendChild(resultBox);

        btn.onclick = () => {
            resultBox.textContent = '⏳ Fetching coupons...';
            fetchCoupons((codes) => {
                if (codes.length === 0) {
                    resultBox.textContent = '❌ No coupons found';
                } else {
                    resultBox.innerHTML = `✅ Found <b>${codes.length}</b> coupons<br><code>${codes.join('</code> <code>')}</code>`;
                }
            });
        };
    };

    waitForPrice('.a-price .a-offscreen', (el) => {
        const price = parsePrice(el.textContent);
        if (price) injectButton(el, price);
    });

})();