SLAMP CPT

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greatest.deepsurf.us/scripts/574274/1801204/SLAMP%20CPT.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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