SLAMP CPT

Universal Heatmap for Egypt, KSA, and UAE. No red if New Orders = 0.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/574274/1801204/SLAMP%20CPT.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

v// ==UserScript==
// @name         SLAMP CPT
// @namespace    http://tampermonkey.net/
// @version      2.8
// @description  Universal Heatmap for Egypt, KSA, and UAE. No red if New Orders = 0.
// @author       Gemini
// @match        https://eu.central.df.amazon.dev/slam*
// @grant        none
// @downloadURL  https://raw.githubusercontent.com/YOUR_USERNAME/YOUR_REPO/main/slam_heatmap.user.js
// @updateURL    https://raw.githubusercontent.com/YOUR_USERNAME/YOUR_REPO/main/slam_heatmap.user.js
// ==/UserScript==

(function() {
    'use strict';

    function applyHeatmap() {
        const headers = Array.from(document.querySelectorAll('th, [role="columnheader"]'));
        const cptIndex = headers.findIndex(h => h.textContent.includes('1st Cpt Date'));
        const newIndex = headers.findIndex(h => h.textContent.trim() === 'New');

        if (cptIndex === -1) return;

        const rows = document.querySelectorAll('tbody tr, [role="row"]');
        const now = new Date();

        rows.forEach(row => {
            if (row.querySelector('th')) return;
            const cells = Array.from(row.querySelectorAll('td, [role="gridcell"]'));
            const cptCell = cells[cptIndex];
            const newCell = (newIndex !== -1) ? cells[newIndex] : null;

            if (!cptCell) return;

            const cptText = cptCell.textContent.trim();
            const newCount = newCell ? (parseInt(newCell.textContent.trim()) || 0) : 1;

            if (!cptText || cptText === 'N/A' || !cptText.includes('T')) return;

            const cptDate = new Date(cptText);
            const diffInHours = (cptDate - now) / (1000 * 60 * 60);

            let bgColor = "";
            let borderColor = "";

            if (newCount === 0) {
                bgColor = "#e8f5e9"; // Done
                borderColor = "#388e3c";
            } else {
                if (diffInHours < 0) {
                    bgColor = "#fce4ec"; 
                    borderColor = "#e91e63";
                } else if (diffInHours <= 1) {
                    bgColor = "#ffcccc"; // RED
                    borderColor = "#d32f2f";
                } else if (diffInHours <= 2.5) {
                    bgColor = "#fff3e0"; // ORANGE
                    borderColor = "#f57c00";
                } else {
                    bgColor = "#e8f5e9"; // GREEN
                    borderColor = "#388e3c";
                }
            }

            cells.forEach(cell => {
                cell.style.setProperty('background-color', bgColor, 'important');
                cell.style.setProperty('border-bottom', `1px solid ${borderColor}`, 'important');
                cell.style.setProperty('color', '#000000', 'important');
            });
        });
    }

    function addHighlightButton() {
        if (document.getElementById('cpt-highlight-btn')) return;
        const btn = document.createElement('button');
        btn.id = 'cpt-highlight-btn';
        btn.innerText = '📊 Apply MENA Heatmap';
        btn.style.cssText = `position:fixed; top:15px; right:15px; z-index:10000; padding:10px 20px; background:#232f3e; color:#ffffff; border:2px solid #ff9900; border-radius:4px; font-weight:bold; cursor:pointer;`;
        btn.onclick = (e) => { e.preventDefault(); applyHeatmap(); };
        document.body.appendChild(btn);
    }

    document.addEventListener('click', () => setTimeout(applyHeatmap, 500));
    setInterval(applyHeatmap, 15000); 
    setTimeout(addHighlightButton, 2000);
})();