SLAMP CPT

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

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greatest.deepsurf.us/scripts/574274/1801204/SLAMP%20CPT.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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);
})();