Amazon Batch Tool UI Panel PRO

UI面板版:批量ASIN/品牌工具

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Amazon Batch Tool UI Panel PRO
// @namespace    asin-link-generator
// @version      3.0
// @description  UI面板版:批量ASIN/品牌工具
// @match        *://*.amazon.com/*
// @match        *://*.amazon.ca/*
// @match        *://*.amazon.co.uk/*
// @match        *://*.amazon.de/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    const MAX_TABS = 20;

    function getAmazonBaseURL() {
        const host = location.hostname;
        if (host.endsWith('.com')) return 'https://www.amazon.com';
        if (host.endsWith('.ca')) return 'https://www.amazon.ca';
        if (host.endsWith('.co.uk')) return 'https://www.amazon.co.uk';
        if (host.endsWith('.de')) return 'https://www.amazon.de';
        return null;
    }

    function extractASINs(input) {
        const matches = input.match(/[A-Z0-9]{10}/gi) || [];
        return [...new Set(matches.map(a => a.toUpperCase()))];
    }

    function splitBrands(input) {
        return [...new Set(
            input.split(/[\n,;|]+/)
                .map(b => b.trim())
                .filter(Boolean)
        )];
    }

    function openLinks(urls) {
        if (urls.length > MAX_TABS) {
            alert(`最多打开 ${MAX_TABS} 个标签页`);
            urls = urls.slice(0, MAX_TABS);
        }
        urls.forEach(url => window.open(url));
    }

    // ===== UI 面板 =====
    const panel = document.createElement('div');
    panel.style = `
        position: fixed;
        right: 20px;
        top: 50px;
        width: 280px;
        background: white;
        border: 1px solid #ddd;
        border-radius: 10px;
        padding: 15px;
        z-index: 9999;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
        font-size: 14px;
    `;

    panel.innerHTML = `
        <div style="font-weight:bold;margin-bottom:10px;">Batch Tool PRO</div>
        <textarea id="inputBox" placeholder="输入ASIN/品牌(支持任意格式)" style="width:100%;height:80px;margin-bottom:10px;"></textarea>
        <button id="btnDetail" style="width:100%;margin-bottom:5px;">打开详情页</button>
        <button id="btnSearch" style="width:100%;margin-bottom:5px;">ASIN搜索</button>
        <button id="btnBrand" style="width:100%;margin-bottom:5px;">品牌搜索</button>
        <button id="btnClear" style="width:100%;">清空</button>
    `;

    document.body.appendChild(panel);

    const inputBox = document.getElementById('inputBox');

    document.getElementById('btnDetail').onclick = () => {
        const base = getAmazonBaseURL();
        const asins = extractASINs(inputBox.value);
        if (base && asins.length) {
            openLinks(asins.map(a => `${base}/dp/${a}`));
        } else {
            alert('未识别ASIN');
        }
    };

    document.getElementById('btnSearch').onclick = () => {
        const base = getAmazonBaseURL();
        const asins = extractASINs(inputBox.value);
        if (base && asins.length) {
            const query = asins.join('%7C');
            window.open(`${base}/s?rh=p_78%3A${query}`);
        } else {
            alert('未识别ASIN');
        }
    };

    document.getElementById('btnBrand').onclick = () => {
        const base = getAmazonBaseURL();
        const brands = splitBrands(inputBox.value);
        if (base && brands.length) {
            openLinks(brands.map(b => `${base}/s?rh=p_4%3A${encodeURIComponent(b)}`));
        }
    };

    document.getElementById('btnClear').onclick = () => {
        inputBox.value = '';
    };

})();