// ==UserScript== // @name 希音SKU获取 // @namespace http://tampermonkey.net/ // @version 5.2 // @description 在编辑订单列表界面,点击对应的spu,点击编辑库存,然后摁下F2 // @author binning // @match https://sso.geiwohuo.com/* // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; // 库存查询请求函数 async function queryInventory(spuName) { const url = "https://sso.geiwohuo.com/spmp-api-prefix/spmp/product/inventory/query"; const headers = { "accept": "*/*", "accept-encoding": "gzip, deflate, br, zstd", "accept-language": "zh-CN,zh;q=0.9,de=0.8,zh-HK=0.7", "cache-control": "no-cache", "content-type": "application/json", "front-version": "20250207", "origin": "https://sso.geiwohuo.com", "origin-url": "https://sso.geiwohuo.com/#/spmp/commdities/list", "pragma": "no-cache", "referer": "https://sso.geiwohuo.com/", "x-bbl-route": "/spmp/commdities/list", "x-lt-language": "CN", "x-req-zone-id": "Asia/Shanghai", "user-agent": navigator.userAgent }; const body = JSON.stringify({ spu_name: spuName }); try { console.log("🔍 正在请求,SPU:", spuName); const res = await fetch(url, { method: "POST", headers: headers, body: body, credentials: "include", mode: "cors" }); const data = await res.json(); console.log("✅ 请求成功"); return data; } catch (err) { console.error("❌ 请求失败:", err); return null; } } // 全局关闭表格 window.closeTable = function() { const el = document.getElementById("spuTable"); if (el) el.remove(); }; // 解析数据 + 生成表格 function parseAndShowTable(data) { window.closeTable(); if (!data?.info?.skc_info) { console.log("暂无数据"); return; } const list = []; data.info.skc_info.forEach(skc => { const color = skc.sale_name; const skuCodes = skc.sku_info.map(item => item.sku_code).join(" "); list.push({ color, skuCodes }); }); // 表格结构(自动宽度 + 完整显示内容) let html = `
| 颜色 | SKU 编码 | 操作 |
|---|---|---|
| ${item.color} | ${item.skuCodes} |