IDRT

DZ+R

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         IDRT
// @namespace    http://tampermonkey.net/
// @version      20250410.1.0
// @description  DZ+R
// @author       xabd
// @license      azab
// @icon         https://www.google.com/s2/favicons?sz=64&domain=amazon.com
// @match        http://fc-spaceman-idrt-dub.aka.amazon.com/*
// @match        https://routing-tool-dub.aka.amazon.com/tote-route*
// ==/UserScript==

(function() {
    'use strict';

    const CONFIG = {
        ROUTING: {
            baseRoutes: ["dz-P-MANSORTTOTE", "dz-P-DOCKSORT", "dz-P-DECANT", "ATAC"]
        },
        IDRT: {
            baseDZs: ["dz-P-RPI-CF", "dz-P-ISS-exceptions", "dz-P-UPPREP", "dz-P-NONSORT"]
        }
    };

    const styles = `
        .routing-helper {
            position: fixed;
            top: 300px;
            left: -50px;
            right: -50px;
            background: #232F3E;
            padding: 10px 60px;
            z-index: 1000;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 20px;
            width: calc(100% + 100px);
        }

        .routing-button {
            background: #FF9900;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 10px 20px;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.2s ease;
            min-width: 180px;
            text-align: center;
        }

        .routing-button:hover {
            background: #FF8000;
            transform: translateY(-1px);
        }
    `;

    function addStyles() {
        const styleSheet = document.createElement("style");
        styleSheet.textContent = styles;
        document.head.appendChild(styleSheet);
    }

    function createContainer() {
        const container = document.createElement('div');
        container.className = 'routing-helper';
        return container;
    }

    function createButton(text) {
        const button = document.createElement('button');
        button.className = 'routing-button';
        button.textContent = text;
        return button;
    }

    function handleRoutingToolClick(value) {
        const input = document.querySelector('input[type="text"]');
        if (input) {
            input.value = value;
            input.dispatchEvent(new Event('input', { bubbles: true }));
            input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', keyCode: 13, which: 13 }));
        }
    }

    function handleIDRTClick(value) {
        const input = document.getElementById('scan_input');
        if (input) {
            input.value = value;
            input.dispatchEvent(new Event('input', { bubbles: true }));
            const form = input.closest('form');
            if (form) form.submit();
        }
    }

    function init() {
        const currentURL = window.location.href;

        // Vérification pour les pages de routing spécifiques
        if (currentURL.includes('/tote-route?jobName=RouteSingle') ||
            currentURL.includes('/tote-route?jobName=RouteMultipleHandScanner')) {

            addStyles();
            const container = createContainer();

            CONFIG.ROUTING.baseRoutes.forEach(route => {
                const button = createButton(route);
                button.addEventListener('click', () => handleRoutingToolClick(route));
                container.appendChild(button);
            });

            document.body.appendChild(container);
        }
        // Vérification pour IDRT
        else if (currentURL.includes('fc-spaceman-idrt-dub.aka.amazon.com')) {
            addStyles();
            const container = createContainer();

            CONFIG.IDRT.baseDZs.forEach(dz => {
                const button = createButton(dz);
                button.addEventListener('click', () => handleIDRTClick(dz));
                container.appendChild(button);
            });

            document.body.appendChild(container);
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();