// ==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 = `
`; list.forEach((item, idx) => { html += ` `; }); html += `
颜色SKU 编码操作
${item.color} ${item.skuCodes}
`; document.body.insertAdjacentHTML("beforeend", html); window.allSkuList = list; } // 全局复制方法 window.copySingle = function(text, idx) { navigator.clipboard.writeText(text); const btn = document.getElementById(`copyBtn-${idx}`); if (btn) { btn.textContent = "已复制"; btn.classList.add("copied"); setTimeout(() => { btn.textContent = "复制"; btn.classList.remove("copied"); }, 1000); } console.log("✅ 复制成功"); }; window.copyAll = function() { let content = ""; window.allSkuList.forEach(item => { content +=( `${item.skuCodes}`+" "); }); navigator.clipboard.writeText(content); const btn = document.getElementById("copyAllBtn"); if (btn) { btn.textContent = "已复制全部"; btn.style.background = "#28a745"; setTimeout(() => { btn.textContent = "复制全部"; btn.style.background = "#007bff"; }, 1000); } console.log("✅ 全部复制成功"); }; // ESC 关闭 document.addEventListener("keydown", (e) => { if (e.key === "Escape") { window.closeTable(); } }); // F2 触发 document.addEventListener("keydown", async (e) => { if (e.key === "F2") { e.preventDefault(); try { const spuEl = document.querySelector("#LAYOUT_CONTENT > div.so-modal.so-modal-position.so-modal-show > div > div > div.so-card-body > div > div:nth-child(1) > div.mt-\\[10px\\].min-w-0.flex-1 > div:nth-child(2)"); if (!spuEl) { console.log("❌ 未找到SPU元素"); return; } const text = spuEl.textContent.trim(); const spu = text.split(":")[1]?.trim(); if (!spu) { console.log("❌ SPU 格式错误"); return; } const res = await queryInventory(spu); if (res) parseAndShowTable(res); } catch (err) { console.error("❌ 异常:", err); } } }); console.log("✅ 脚本加载完成 · F2查询 · ESC关闭"); })();