SOURCE

// ==UserScript==
// @name         沃尔玛上架产品删除脚本
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  沃尔玛上架产品删除脚本
// @match        https://seller.walmart.com/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 页面加载完后再渲染
    window.addEventListener('load',function() {
        // 创建容器
        const container = document.createElement('div');
        container.style.position = 'fixed';
        container.style.top = '10px';
        container.style.right = '10px';
        container.style.zIndex = '1000';
        container.style.backgroundColor = '#f0f0f0'; // 灰色背景
        container.style.padding = '10px';
        container.style.borderRadius = '5px';
        container.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';

        // 创建文件上传控件
        const fileInput = document.createElement('input');
        fileInput.type = 'file';
        fileInput.accept = '.xlsx, .xls'; // 只接受Excel文件
        fileInput.style.marginRight = '5px';

        // 创建删除进度显示
        const progressDisplay = document.createElement('div');
        progressDisplay.innerText = '已删除数量: 0';
        progressDisplay.style.marginTop = '10px';

        // 创建按钮
        const button = document.createElement('button');
        button.innerText = '开始删除';
        button.style.padding = '5px 10px';
        button.style.border = 'none';
        button.style.borderRadius = '3px';
        button.style.backgroundColor = '#007bff'; // 按钮颜色
        button.style.color = '#fff';
        button.style.cursor = 'pointer';

        // 添加控件到容器
        container.appendChild(fileInput);
        container.appendChild(button);
        container.appendChild(progressDisplay);

        // 将容器添加到文档中
        document.body.appendChild(container);

        button.addEventListener('click',async function() {
            const file = fileInput.files[0];
            if (!file) {
                alert('请上传一个Excel文件。');
                return;
            }

            const reader = new FileReader();
            reader.onload = async (e) => {
                const data = new Uint8Array(e.target.result);
                const workbook = XLSX.read(data,{ type: 'array' });

                // 获取第一个工作表
                const firstSheetName = workbook.SheetNames[0];
                const worksheet = workbook.Sheets[firstSheetName];

                // 获取SKU编号列表
                const jsonData = XLSX.utils.sheet_to_json(worksheet,{ header: 1 });
                // 取第一列并过滤空值
                const skus = jsonData.map(row => row[0]).filter(Boolean);

                if (skus.length === 0) {
                    alert('没有找到SKU编号。');
                    return;
                }

                // 删除SKU,在每100个sku时执行请求
                let deletedCount = 0;
                // 用于记录错误数量
                let totalErrors = 0;

                for (let i = 0; i < skus.length; i += 100) {
                    const currentSkus = skus.slice(i,i + 100);
                    const requestBody = JSON.stringify({ skus: currentSkus });
                    const contentLength = new Blob([requestBody]).size;

                    const cookieString = document.cookie;
                    const xsrfTokenMatch = cookieString.match(/XSRF-TOKEN=([^;]+)/);
                    const xsrfToken = xsrfTokenMatch ? xsrfTokenMatch[1] : null;

                    try {
                        const response = await fetch('https://seller.walmart.com/aurora/v1/items',{
                            method: 'DELETE',
                            headers: {
                                'cookie': cookieString,
                                'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"',
                                'x-xsrf-token': xsrfToken,
                                'authority': 'seller.walmart.com',
                                'method': 'DELETE',
                                'path': '/aurora/v1/items',
                                'scheme': 'https',
                                'accept': 'application/json',
                                'accept-encoding': 'gzip, deflate, br',
                                'accept-language': 'zh-CN,zh;q=0.9',
                                'content-length': contentLength,
                                'content-type': 'application/json',
                                'origin': 'https://seller.walmart.com',
                                'referer': 'https://seller.walmart.com/catalog/list-items?filters=%257B%2522offerLifeCycleStatus%2522%253A%255B%2522RETIRED%2522%255D%257D&sortField=productName&sortOrder=asc',
                                'sec-ch-ua-mobile': '?0',
                                'sec-fetch-dest': 'empty',
                                'sec-fetch-mode': 'cors',
                                'sec-fetch-site': 'same-origin',
                                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
                                'wm_aurora.market': 'US',
                                'wm_qos.correlation_id': '3f150947-81e1-437d-a2ac-feb6b725ca9a',
                                'wm_svc.name': 'Walmart Marketplace'
                            },
                            body: requestBody
                        });

                        const responseData = await response.json();
                        deletedCount += currentSkus.length;
                        progressDisplay.innerText = `已删除数量: ${deletedCount}`;

                        // 检查错误数量并累加
                        if (responseData.status === "OK") {
                            totalErrors += responseData.payload.errorCount;
                        } else {
                            console.error('删除请求未成功,请检查响应。',responseData);
                        }

                        // 等待60秒再执行下一次请求
                        await new Promise(resolve => setTimeout(resolve,60000));
                    } catch (error) {
                        // 如果发生错误,则停止请求
                        console.error('请求失败:',error);
                        break;
                    }
                }

                // 操作完成,弹出提示
                alert(`删除完成,已删除数量: ${deletedCount},错误数量: ${totalErrors}`);
            };

            reader.readAsArrayBuffer(file);
        });
    });
})();

console 命令行工具 X clear

                    
>
console