// ==UserScript==
// @name 抖店达人助手
// @namespace https://github.com/yourusername
// @version 2.3.6
// @author WechatID:fmtprint
// @description 抖店达人拓展好帮手
// @license MIT
// @match https://buyin.jinritemai.com/dashboard/servicehall/business-homepage?sec_shop_id*
// @connect shop_api.uinstall.eu.org
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
const n = {
templates: [],
productSettings: {},
productIds: [],
contactInfo: {
phone: "",
wechat: ""
},
activeTemplateId: ""
}, t = "INVITE_CARD_CONFIG";
function o() {
const o = GM_getValue(t, n);
return {
templates: o.templates || n.templates,
productSettings: o.productSettings || {},
productIds: o.productIds || [],
contactInfo: {
phone: o.contactInfo?.phone || "",
wechat: o.contactInfo?.wechat || ""
},
activeTemplateId: o.activeTemplateId || n.activeTemplateId
};
}
function e(n) {
GM_setValue(t, n);
}
function i(n, t) {
let o;
return (...e) => {
clearTimeout(o), o = window.setTimeout((() => n(...e)), t);
};
}
function c() {
const n = document.querySelector(".shop-config-overlay");
if (n) n.style.display = "block", n.querySelector(".shop-config-panel").style.display = "flex"; else {
const n = (function() {
const n = document.createElement("div");
n.className = "shop-config-overlay", n.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:1000;display:none;";
const t = document.createElement("div");
t.className = "shop-config-panel", t.style.cssText = "position:fixed;top:0;right:0;width:960px;height:100vh;background:white;box-shadow:-2px 0 8px rgba(0,0,0,0.15);z-index:1001;display:flex;flex-direction:column;font-size:14px;";
const c = document.createElement("style");
c.textContent = "\n .shop-config-panel .header { padding:16px 24px; border-bottom:1px solid #f0f0f0; display:flex; justify-content:space-between; align-items:center; background:white; }\n .shop-config-panel .content { flex:1; overflow-y:auto; padding:16px; background-color:#fafbfc; display:flex; gap:16px; }\n .shop-config-panel .footer { padding:16px 24px; border-top:1px solid #f0f0f0; text-align:right; background:white; }\n .shop-config-panel h3 { margin:0; color:#000000d9; font-weight:500; font-size:16px; }\n .shop-config-panel .form-block { background:white; border-radius:2px; padding:16px; margin-bottom:16px; }\n .shop-config-panel .highlight-text { font-size:14px; font-weight:500; color:#000000d9; margin-bottom:16px; display:flex; align-items:center; }\n .shop-config-panel .form-row { display:flex; margin-bottom:16px; }\n .shop-config-panel .form-label { width:120px; text-align:right; padding-right:16px; color:#898b8f; line-height:32px; }\n .shop-config-panel .form-content { flex:1; }\n .shop-config-panel input[type=\"text\"], .shop-config-panel textarea { width:288px; padding:4px 11px; border:1px solid #d9d9d9; border-radius:2px; font-size:14px; }\n .shop-config-panel textarea.large { width:100%; height:160px; resize:none; }\n .shop-config-panel .checkbox-group { display:flex; flex-wrap:wrap; gap:16px; }\n .shop-config-panel .checkbox-wrapper { display:inline-flex; align-items:center; cursor:pointer; user-select:none; }\n .shop-config-panel .checkbox-inner { position:relative; width:16px; height:16px; border:1px solid #d9d9d9; border-radius:2px; margin-right:8px; }\n .shop-config-panel .checkbox-wrapper.checked .checkbox-inner { background:#1966ff; border-color:#1966ff; }\n .shop-config-panel .checkbox-wrapper.checked .checkbox-inner:after { content:''; position:absolute; left:4px; top:1px; width:6px; height:9px; border:2px solid #fff; border-top:0; border-left:0; transform:rotate(45deg); }\n .shop-config-panel .table { width:100%; border-collapse:collapse; }\n .shop-config-panel .table th, .shop-config-panel .table td { padding:12px 16px; border-bottom:1px solid #f0f0f0; text-align:left; vertical-align:middle; }\n .shop-config-panel .table th { background:#fafafa; font-weight:500; color:#000000d9; }\n .shop-config-panel .product-card { display:flex; align-items:center; gap:12px; }\n .shop-config-panel .product-image { width:32px; height:32px; border-radius:2px; object-fit:cover; }\n .shop-config-panel .product-info { flex:1; min-width:0; }\n .shop-config-panel .product-title { font-size:13px; margin-bottom:4px; color:#252931; }\n .shop-config-panel .product-meta { color:#898b8f; font-size:12px; }\n .shop-config-panel .switch { position:relative; display:inline-block; width:28px; height:16px; background:#ccc; border-radius:100px; cursor:pointer; vertical-align:middle; }\n .shop-config-panel .switch.checked { background:#1966ff; }\n .shop-config-panel .switch-handle { position:absolute; top:2px; left:2px; width:12px; height:12px; background:white; border-radius:50%; transition:left 0.2s; }\n .shop-config-panel .switch.checked .switch-handle { left:14px; }\n .shop-config-panel .btn { padding:4px 15px; border-radius:2px; border:1px solid #d9d9d9; background:white; cursor:pointer; font-size:14px; }\n .shop-config-panel .btn-primary { background:#1966ff; border-color:#1966ff; color:white; }\n .shop-config-panel .btn-link { border:none; padding:0; color:#1966ff; }\n .shop-config-panel .set-end-time { min-width:80px; text-align:left; }\n ",
document.head.appendChild(c);
const r = document.createElement("div");
r.className = "header", r.innerHTML = '\n
\u9080\u8bf7\u914d\u7f6e
\n \n ';
const a = document.createElement("div");
a.className = "content";
const s = document.createElement("div");
s.style.flex = "1";
const l = document.createElement("div");
l.className = "form-block", l.innerHTML = '\n \u9080\u7ea6\u4fe1\u606f
\n \n \n ';
const p = document.createElement("div");
p.className = "form-block", p.innerHTML = '\n \u8054\u7cfb\u65b9\u5f0f
\n \n \n ';
const f = document.createElement("div");
f.className = "form-block", f.innerHTML = '\n \u5546\u54c1\u914d\u7f6e
\n \n \n
\n \n \n \n | \u5546\u54c1\u4fe1\u606f | \n \u4e13\u5c5e\u4f63\u91d1 | \n \u514d\u5ba1\u7533\u6837 | \n \u7b56\u7565\u7ed3\u675f\u65f6\u95f4 | \n \u64cd\u4f5c | \n
\n \n \n
\n ',
s.appendChild(l), s.appendChild(p), s.appendChild(f), a.appendChild(s);
const h = document.createElement("div");
h.style.cssText = "width:286px;flex-shrink:0;", h.innerHTML = '\n \u6548\u679c\u9884\u89c8
\n
\n ',
a.appendChild(h);
const u = document.createElement("div");
u.className = "footer", u.innerHTML = '';
const x = document.createElement("button");
x.textContent = "\u9884\u89c8\u914d\u7f6e", x.className = "btn", x.style.marginRight = "8px",
x.onclick = () => (function() {
const n = d("preview_account_id"), t = JSON.stringify(n, null, 2), o = document.createElement("div");
o.style.cssText = "position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:white;padding:24px;border-radius:2px;box-shadow:0 3px 6px -4px rgba(0,0,0,.12),0 6px 16px 0 rgba(0,0,0,.08);z-index:1002;width:800px;max-height:90vh;display:flex;flex-direction:column;",
o.innerHTML = `\n \n
\u914d\u7f6e\u9884\u89c8
\n \n \n ${t}\n `,
o.querySelector("button").onclick = () => document.body.removeChild(o), document.body.appendChild(o);
})(), u.insertBefore(x, u.firstChild), t.appendChild(r), t.appendChild(a), t.appendChild(u),
n.appendChild(t), [ r.querySelector("button"), u.querySelector(".btn:last-child") ].forEach((o => {
o.onclick = () => {
n.style.display = "none", t.style.display = "none";
};
})), n.onclick = o => {
o.target === n && (n.style.display = "none", t.style.display = "none");
};
const g = o(), m = l.querySelector("textarea");
m.value = g.templates[0]?.content || "", m.onchange = i((n => {
const t = o(), i = n.target.value, c = "template_" + Date.now();
0 === t.templates.length ? (t.templates.push({
id: c,
name: "\u9080\u7ea6\u6a21\u677f",
content: i,
rights: [ {
right: 1
}, {
right: 2
} ]
}), t.activeTemplateId = c) : t.templates[0].content = i, e(t);
}), 300), l.querySelectorAll(".checkbox-wrapper").forEach(((n, t) => {
const i = [ 1, 2, 4, 3 ][t];
(g.templates[0]?.rights || [ {
right: 1
}, {
right: 2
} ]).some((n => n.right === i)) && n.classList.add("checked"), n.onclick = () => {
const t = o();
n.classList.contains("checked") ? (n.classList.remove("checked"), t.templates[0].rights = t.templates[0].rights.filter((n => n.right !== i))) : (n.classList.add("checked"),
t.templates[0].rights.push({
right: i
})), e(t);
};
}));
const [b, v] = p.querySelectorAll("input");
b.value = g.contactInfo.phone, v.value = g.contactInfo.wechat, b.onchange = i((n => {
const t = n.target.value;
if (!/^1[3-9]\d{9}$/.test(t)) return void window.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801");
const i = o();
i.contactInfo.phone = t, e(i);
}), 300), v.onchange = i((n => {
const t = n.target.value;
if (!/^[a-zA-Z0-9_-]{6,20}$/.test(t)) return void window.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5fae\u4fe1\u53f7\uff086-20\u4f4d\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\uff09");
const i = o();
i.contactInfo.wechat = t, e(i);
}), 300);
const w = f.querySelector("tbody");
function y() {
const n = o();
w.innerHTML = n.productIds.map((t => {
const o = n.productSettings[t], e = o?.validTime && "end" === o.timeRadio ? o.validTime.split(" ")[0] : "\u957f\u671f";
return `\n \n \n \n  \n \n \u5546\u54c1ID: ${t} \n \n \u4f63\u91d1\uff1a${o?.cosRatio || 0}%\n \n \n \n | \n \n \n | \n \n \n | \n \n \n | \n \n \n | \n
\n `;
})).join(""), w.querySelectorAll("[data-id]").forEach((n => {
const t = n.getAttribute("data-id");
n.classList.contains("set-ratio") ? n.onclick = () => {
const n = o(), i = prompt("\u8bf7\u8f93\u5165\u4e13\u5c5e\u4f63\u91d1\u6bd4\u4f8b\uff08%\uff09", "" + (n.productSettings[t]?.cosRatio || 40));
if (null !== i) {
const o = parseInt(i);
isNaN(o) || 0 > o || o > 100 ? window.alert("\u8bf7\u8f93\u51650-100\u4e4b\u95f4\u7684\u6709\u6548\u6570\u5b57") : (n.productSettings[t].cosRatio = o,
e(n), y());
}
} : n.classList.contains("switch") ? n.onclick = () => {
const n = o();
n.productSettings[t].sampleStatus = 3 === n.productSettings[t].sampleStatus ? 1 : 3,
e(n), y();
} : n.classList.contains("set-end-time") ? n.onclick = () => {
const n = o(), i = n.productSettings[t];
if ("long" === i.timeRadio) {
if (confirm("\u662f\u5426\u8bbe\u7f6e\u7b56\u7565\u675f\u65f6\u95f4\uff1f")) {
const t = new Date, o = new Date(t.getTime() + 6048e5), c = document.createElement("input");
c.type = "date", c.value = o.toISOString().split("T")[0], c.min = t.toISOString().split("T")[0],
c.style.cssText = "\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 8px;\n border: 1px solid #d9d9d9;\n border-radius: 2px;\n font-size: 14px;\n z-index: 1003;\n ",
document.body.appendChild(c);
const r = document.createElement("div");
r.style.cssText = "\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(0,0,0,0.5);\n z-index: 1002;\n ",
document.body.appendChild(r), r.onclick = () => {
document.body.removeChild(c), document.body.removeChild(r);
}, c.onchange = t => {
const o = t.target.value;
i.timeRadio = "end", i.validTime = o + " 23:59:59", e(n), y(), document.body.removeChild(c),
document.body.removeChild(r);
}, setTimeout((() => {
c.focus();
}), 100);
}
} else confirm("\u662f\u5426\u6539\u4e3a\u957f\u671f\uff1f") && (i.timeRadio = "long",
i.validTime = "3000-01-01 00:00:00", e(n), y());
} : n.classList.contains("delete-product") && (n.onclick = () => {
if (confirm("\u786e\u5b9a\u5220\u9664\u8be5\u5546\u54c1\u5417\uff1f")) {
const n = o();
n.productIds = n.productIds.filter((n => n !== t)), delete n.productSettings[t],
e(n), y();
}
});
}));
}
return f.querySelector(".btn-primary").onclick = () => {
const n = prompt("\u8bf7\u8f93\u5165\u5546\u54c1ID");
if (!n) return;
if (!(function(n) {
return /^\d{6,20}$/.test(n);
})(n)) return void window.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5546\u54c1ID\uff086-20\u4f4d\u6570\u5b57\uff09");
const t = o();
t.productIds.includes(n) ? window.alert("\u8be5\u5546\u54c1\u5df2\u6dfb\u52a0") : (t.productIds.push(n),
t.productSettings[n] = {
sampleStatus: 1,
cosRatio: 40,
timeRadio: "long",
validTime: "3000-01-01 00:00:00"
}, e(t), y());
}, y(), n;
})();
document.body.appendChild(n), n.style.display = "block", n.querySelector(".shop-config-panel").style.display = "flex";
}
}
const r = {}, a = {}, s = {
name: "",
avatar: "",
shopId: ""
};
function d(n) {
const t = o(), e = t.templates.find((n => n.id === t.activeTemplateId));
if (!e) throw Error("Template not found");
return {
account_id: n,
account_type: 1,
invite_card: {
content: e.content,
rights: e.rights,
product_ids: t.productIds,
product_setting: t.productIds.filter((n => t.productSettings[n])).map((n => {
const o = t.productSettings[n];
return {
product_id: n,
author_sample_status: o.sampleStatus,
orient_cos_ratio_detail: {
orient_kol_cos_ratio: o.cosRatio,
time_radio: o.timeRadio,
valid_time: o.validTime || "3000-01-01 00:00:00",
suggest_orient_kol_cos_ratio: 53,
...o.cosRatio ? {} : {
cos_ratio_range: {
low: 0,
high: 80
}
}
}
};
}))
},
contact_info: t.contactInfo
};
}
function l(n) {
const t = (function(n) {
const t = a[n];
if (!t) return null;
const o = r[t];
return o?.data?.author_list ? o.data.author_list.find((t => t.avatar === n)) : null;
})(n);
return t || null;
}
function p(n) {
const t = n.querySelector(".card-info__avatar img");
return t?.getAttribute("src") || null;
}
function f(n) {
const t = p(n);
return t ? l(t) : null;
}
async function h(n) {
return new Promise(((t, o) => {
"undefined" != typeof GM_xmlhttpRequest ? GM_xmlhttpRequest({
method: "POST",
url: "https://shop_api.uinstall.eu.org:888/shop/api/v1/douyin/contact",
headers: {
"Content-Type": "application/json",
"User-Agent": window.navigator.userAgent,
Accept: "application/json",
Origin: "https://buyin.jinritemai.com",
Referer: "https://buyin.jinritemai.com/",
Cookie: document.cookie
},
data: JSON.stringify(n),
onload(n) {
try {
const e = JSON.parse(n.responseText);
200 === n.status && 200 === e.code ? t(e) : o(Error(e.message || "\u8bf7\u6c42\u5931\u8d25"));
} catch (n) {
o(n);
}
},
onerror(n) {
o(Error("\u7f51\u7edc\u8bf7\u6c42\u5931\u8d25"));
}
}) : o(Error("GM_xmlhttpRequest \u4e0d\u53ef\u7528"));
}));
}
async function u(n) {
try {
const t = await fetch("https://buyin.jinritemai.com/connection/pc/im/invite/card/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": window.navigator.userAgent,
Accept: "application/json",
Origin: "https://buyin.jinritemai.com",
Referer: "https://buyin.jinritemai.com/"
},
body: JSON.stringify(n),
credentials: "include"
});
if (!t.ok) throw Error("HTTP error! status: " + t.status);
const o = await t.json();
if (0 === o.code) return o;
throw Error(o.msg || "\u8bf7\u6c42\u5931\u8d25");
} catch (n) {
throw n;
}
}
function x(n) {
try {
return new Date(n).toLocaleString("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: !1
});
} catch (t) {
return n;
}
}
let g = null, m = null;
const b = new Map;
function v() {
const n = document.createElement("div");
n.className = "shop-log-panel", n.style.cssText = "\n position: fixed;\n left: 0;\n bottom: 0;\n width: 360px;\n background: white;\n border-radius: 8px 8px 0 0;\n box-shadow: 0 2px 8px rgba(0,0,0,0.15);\n z-index: 1000;\n font-size: 12px;\n display: flex;\n flex-direction: column;\n max-height: 400px;\n transition: transform 0.3s ease;\n ";
const t = document.createElement("div");
t.style.cssText = "\n padding: 12px 16px;\n border-bottom: 1px solid #f0f0f0;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-radius: 8px 8px 0 0;\n background: linear-gradient(to right, var(--progress-color, #e6f7ff) 0%, var(--progress-color, #e6f7ff) var(--progress, 0%), transparent var(--progress, 0%));\n cursor: move;\n ";
const o = document.createElement("div");
o.style.cssText = "\n display: flex;\n align-items: center;\n gap: 8px;\n ";
const e = document.createElement("span");
e.textContent = "\u64cd\u4f5c\u65e5\u5fd7", e.style.cssText = "\n font-weight: 500;\n color: #333;\n font-size: 13px;\n ";
const i = document.createElement("div");
i.style.cssText = "\n display: flex;\n gap: 8px;\n ";
const c = document.createElement("button");
c.innerHTML = '',
c.style.cssText = "\n padding: 0 8px;\n height: 24px;\n background: none;\n border: 1px solid #d9d9d9;\n border-radius: 4px;\n cursor: pointer;\n color: #666;\n display: inline-flex;\n align-items: center;\n transition: all 0.3s;\n &:hover {\n color: #40a9ff;\n border-color: #40a9ff;\n }\n ";
const r = document.createElement("button");
r.innerHTML = '\u6e05\u7a7a',
r.style.cssText = "\n padding: 0 8px;\n height: 24px;\n background: none;\n border: 1px solid #d9d9d9;\n border-radius: 4px;\n cursor: pointer;\n color: #666;\n display: inline-flex;\n align-items: center;\n transition: all 0.3s;\n &:hover {\n color: #40a9ff;\n border-color: #40a9ff;\n }\n ";
let a = !1;
c.onclick = () => {
a = !a, n.style.transform = a ? `translateY(${n.offsetHeight - t.offsetHeight}px)` : "translateY(0)";
}, r.onclick = k, o.appendChild(e), i.appendChild(c), i.appendChild(r), t.appendChild(o),
t.appendChild(i);
const s = document.createElement("div");
s.style.cssText = "\n flex: 1;\n overflow-y: auto;\n padding: 8px 0;\n max-height: 320px;\n ",
n.appendChild(t), n.appendChild(s), g = n, m = s;
let d, l, p, f, h = !1;
return t.addEventListener("mousedown", (t => {
h = !0, p = t.clientX - n.offsetLeft, f = t.clientY - n.offsetTop;
})), document.addEventListener("mousemove", (t => {
if (h) {
t.preventDefault(), d = t.clientX - p, l = t.clientY - f;
const o = window.innerWidth - n.offsetWidth, e = window.innerHeight - n.offsetHeight;
d = Math.max(0, Math.min(d, o)), l = Math.max(0, Math.min(l, e)), n.style.left = d + "px",
n.style.bottom = window.innerHeight - l - n.offsetHeight + "px";
}
})), document.addEventListener("mouseup", (() => {
h = !1;
})), n;
}
function w(n) {
if (!g) return;
const t = g.querySelector("div");
t && (t.style.setProperty("--progress", n + "%"), t.style.setProperty("--progress-color", 100 === n ? "#f6ffed" : "#e6f7ff"));
}
function y(n, t, o) {
if (!m) return;
const e = document.createElement("div");
e.style.cssText = "\n padding: 4px 16px;\n display: flex;\n align-items: flex-start;\n gap: 8px;\n line-height: 1.6;\n &:hover {\n background: #f5f5f5;\n }\n ";
const i = document.createElement("span");
i.style.cssText = `\n margin-top: 2px;\n flex-shrink: 0;\n color: ${"info" === t.type ? "#1890ff" : "success" === t.type ? "#52c41a" : "#ff4d4f"};\n `,
i.innerHTML = "info" === t.type ? '' : '';
const c = document.createElement("span");
c.style.cssText = "\n color: #999;\n font-size: 11px;\n flex-shrink: 0;\n min-width: 50px;\n ",
c.textContent = (new Date).toLocaleTimeString("zh-CN", {
hour12: !1
});
const r = document.createElement("span");
if (r.className = "log-message", r.style.cssText = "\n flex: 1;\n word-break: break-all;\n white-space: pre-wrap;\n ",
r.textContent = n, t.details) {
const n = document.createElement("span");
n.style.cssText = "\n color: #999;\n font-size: 11px;\n flex-shrink: 0;\n margin-left: 8px;\n ";
const o = [];
"db" === t.details.source && t.details.savedAt && o.push("DB:" + x(t.details.savedAt)),
"api" === t.details.source && void 0 !== t.details.remaining && o.push("API:" + t.details.remaining),
t.details.errorMessage && o.push(t.details.errorMessage), n.textContent = o.join(" | "),
e.appendChild(n);
}
e.appendChild(i), e.appendChild(c), e.appendChild(r), m.appendChild(e), m.scrollTop = m.scrollHeight;
}
function k() {
m && (m.innerHTML = "", b.clear());
}
function z(n, t) {
g || document.body.appendChild(v()), y(n, {
type: "info"
});
}
function _(n, t) {
g || document.body.appendChild(v()), y(n, {
type: "success",
details: t
});
}
function $(n, t) {
g || document.body.appendChild(v()), y(n, {
type: "error",
details: t
});
}
function M(n) {
return 1e8 > n ? 1e4 > n ? "" + n : (n / 1e4).toFixed(0) + "W" : (n / 1e8).toFixed(0) + "E";
}
const C = [ {
key: "name",
title: "\u8fbe\u4eba\u540d\u79f0"
}, {
key: "level",
title: "\u7b49\u7ea7"
}, {
key: "fans_num",
title: "\u7c89\u4e1d\u6570",
format(n) {
if (null == n) return "";
const t = 100 * Math.floor(n / 100);
return 1e4 > t ? 1e3 > t ? "" + t : (t / 1e3).toFixed(1) + "K" : (t / 1e4).toFixed(1) + "W";
}
}, {
key: "sale_range",
title: "\u5e97\u94fa\u63a8\u5e7f\u9500\u552e\u989d",
getValue(n) {
return n;
},
format(n) {
const t = n.sale?.low, o = n.sale?.high;
return null == t || null == o ? "" : 0 === t && 0 === o ? "0" : t === o ? M(t) : `${M(t)}-${M(o)}`;
}
}, {
key: "live_num",
title: "\u5173\u8054\u76f4\u64ad\u573a\u6b21"
}, {
key: "video_num",
title: "\u5173\u8054\u77ed\u89c6\u9891\u6570"
}, {
key: "promotion_num",
title: "\u63a8\u5e7f\u5546\u54c1\u6570"
}, {
key: "wechat_id",
title: "Wechat"
} ];
async function H() {
const n = Array.from(document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]:checked')).map((n => n.closest(".shop-card"))).filter((n => null !== n));
if (0 === n.length) return void alert("\u8bf7\u5148\u9009\u62e9\u8981\u5bfc\u51fa\u7684\u8fbe\u4eba");
const t = confirm(`\u5df2\u9009\u4e2d ${n.length} \u4e2a\u8fbe\u4eba\uff0c\u662f\u5426\u8981\u53d1\u9001\u9080\u7ea6\uff1f`);
if (t) {
const n = o();
if (!n.templates.length || !n.activeTemplateId) return void alert("\u8bf7\u5148\u914d\u7f6e\u9080\u7ea6\u6a21\u677f");
if (!n.productIds.length) return void alert("\u8bf7\u5148\u914d\u7f6e\u5546\u54c1");
if (!n.contactInfo.phone || !n.contactInfo.wechat) return void alert("\u8bf7\u5148\u914d\u7f6e\u8054\u7cfb\u65b9\u5f0f");
}
k();
const e = n.length;
z(`\u5f00\u59cb\u5904\u7406 | \u5171\u9009\u4e2d ${e} \u4e2a\u8fbe\u4eba`);
const i = n.map(p).filter((n => null !== n)).map((n => l(n))).filter((n => null !== n));
if (0 === i.length) return void $("\u672a\u627e\u5230\u8fbe\u4eba\u6570\u636e");
let c = 0, r = 0, a = 0;
z("------------------------");
const f = [];
for (const n of i) {
a++;
try {
const o = n.name || n.nickname || "\u672a\u77e5\u8fbe\u4eba";
let i = "";
const s = await h(n);
let l = `[${a}/${e}] ${o}`, p = [];
if (200 !== s.code && 0 !== s.code || !s.data?.wechat_id ? (l += " | \u274c \u67e5\u8be2\u5931\u8d25: " + (s.message || "\u672a\u627e\u5230\u8054\u7cfb\u65b9\u5f0f"),
"api" === s.source && void 0 !== s.remaining && p.push("API:" + s.remaining)) : (c++,
i = s.data.wechat_id, l += " | \u2705 \u67e5\u8be2\u6210\u529f: " + i, "db" === s.source && s.saved_at && p.push("DB:" + x(s.saved_at)),
"api" === s.source && void 0 !== s.remaining && p.push("API:" + s.remaining)), t) try {
const t = d(n.sec_author_id), o = await u(t);
0 === o.code ? (r++, l += " | \u2705 \u9080\u7ea6\u6210\u529f") : l += " | \u274c \u9080\u7ea6\u5931\u8d25: " + o.msg;
} catch (n) {
l += " | \u274c \u9080\u7ea6\u5931\u8d25: " + n.message;
}
p.length > 0 && (l += " | " + p.join(" | ")), l.includes("\u274c") ? $(l) : _(l),
f.push({
...n,
wechat_id: i
});
} catch (o) {
let i = `[${a}/${e}] ${n.name || n.nickname || "\u672a\u77e5\u8fbe\u4eba"} | \u274c \u67e5\u8be2\u5931\u8d25: ${o.message}`;
if (t) try {
const t = d(n.sec_author_id), o = await u(t);
0 === o.code ? (r++, i += " | \u2705 \u9080\u7ea6\u6210\u529f") : i += " | \u274c \u9080\u7ea6\u5931\u8d25: " + o.msg;
} catch (n) {
i += " | \u274c \u9080\u7ea6\u5931\u8d25: " + n.message;
}
$(i), f.push({
...n,
wechat_id: ""
});
}
w(Math.round(a / e * 100));
}
if (z("------------------------"), z(t ? `\u2728 \u5904\u7406\u5b8c\u6210 | \u67e5\u8be2\u6210\u529f\u7387: ${c}/${e} (${Math.round(c / e * 100)}%) | \u9080\u7ea6\u6210\u529f\u7387: ${r}/${e} (${Math.round(r / e * 100)}%)` : `\u2728 \u5904\u7406\u5b8c\u6210 | \u67e5\u8be2\u6210\u529f\u7387: ${c}/${e} (${Math.round(c / e * 100)}%)`),
c > 0) {
const n = (g = f, [ C.map((n => n.title)).join(","), ...g.map((n => C.map((t => {
let o;
if (t.getValue) o = t.getValue(n); else if (t.key.startsWith("sale_")) {
const e = t.key.replace("sale_", "");
o = n.sale?.[e];
} else o = n[t.key];
return (function(n) {
return null == n ? "" : "boolean" == typeof n ? n ? "\u662f" : "\u5426" : "number" == typeof n ? "" + n : ("object" != typeof n || Array.isArray(n) || (n = JSON.stringify(n)),
"string" == typeof n && (n.includes(",") || n.includes("\n") || n.includes('"')) ? `"${n.replace(/"/g, '""')}"` : n + "");
})(t.format ? t.format(o) : o);
})).join(","))) ].join("\n")), t = new Blob([ "\ufeff" + n ], {
type: "text/csv;charset=utf-8;"
}), o = URL.createObjectURL(t), e = document.createElement("a");
e.href = o;
const {name: i} = {
...s
}, c = (new Date).toISOString().split("T")[0];
e.download = i ? `${i}_\u8fbe\u4eba\u6570\u636e_${c}.csv` : `\u8fbe\u4eba\u6570\u636e_${c}.csv`,
document.body.appendChild(e), e.click(), document.body.removeChild(e), URL.revokeObjectURL(o),
_("\u6587\u4ef6\u5bfc\u51fa\u5b8c\u6210");
}
var g;
}
const j = '', I = '';
function A(n) {
const t = document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]:checked').length;
n.innerHTML = `${I}\u5bfc\u51fa\u9009\u4e2d(${t})`;
}
const T = '', V = '';
((function(n, t) {
document.querySelector(".shop-control-panel") || document.body.appendChild((function() {
const n = document.createElement("div");
n.className = "shop-control-panel", n.style.cssText = "\n position: fixed;\n bottom: 0;\n right: 60px;\n background: white;\n padding: 16px;\n border-radius: 8px 8px 0 0;\n box-shadow: 0 2px 8px rgba(0,0,0,0.15);\n z-index: 1000;\n display: flex;\n flex-direction: column;\n gap: 12px;\n font-size: 12px;\n ";
const t = document.createElement("div");
t.style.cssText = "\n padding: 4px 8px;\n margin: -16px -16px 8px -16px;\n background: #fafafa;\n border-radius: 8px 8px 0 0;\n border-bottom: 1px solid #f0f0f0;\n font-weight: 500;\n color: #333;\n font-size: 13px;\n ",
t.textContent = "\u6279\u91cf\u64cd\u4f5c";
const o = document.createElement("button");
o.innerHTML = j + '\u5168\u9009', o.style.cssText = "\n padding: 0 12px;\n height: 28px;\n background-color: #fff;\n color: #1890ff;\n border: 1px solid #1890ff;\n border-radius: 4px;\n cursor: pointer;\n font-size: 12px;\n transition: all 0.3s;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n &:hover {\n background-color: #1890ff;\n color: #fff;\n }\n ";
const e = document.createElement("button");
e.innerHTML = I + '\u5bfc\u51fa\u9009\u4e2d(0)',
e.style.cssText = "\n padding: 0 12px;\n height: 28px;\n background-color: #52c41a;\n color: white;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n font-size: 12px;\n transition: all 0.3s;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n &:hover {\n background-color: #73d13d;\n }\n ";
const i = document.createElement("button");
i.innerHTML = '\u9080\u8bf7\u914d\u7f6e',
i.style.cssText = "\n padding: 0 12px;\n height: 28px;\n background-color: #f7f7f7;\n color: #666;\n border: 1px solid #d9d9d9;\n border-radius: 4px;\n cursor: pointer;\n font-size: 12px;\n transition: all 0.3s;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n &:hover {\n color: #40a9ff;\n border-color: #40a9ff;\n svg {\n fill: #40a9ff;\n }\n }\n ";
const r = document.createElement("div");
r.style.cssText = "\n display: flex;\n flex-direction: column;\n gap: 8px;\n ";
let a = !1;
return o.addEventListener("click", (() => {
a = !a, o.innerHTML = `${j}${a ? "\u53d6\u6d88\u5168\u9009" : "\u5168\u9009"}`,
document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]').forEach((n => {
n.checked = a;
})), A(e);
})), e.addEventListener("click", H), i.addEventListener("click", c), document.addEventListener("checkbox-change", (() => {
A(e);
})), r.appendChild(o), r.appendChild(e), r.appendChild(i), n.appendChild(t), n.appendChild(r),
n;
})()), document.querySelector(".shop-log-panel") || document.body.appendChild(v());
const o = document.body;
new MutationObserver((() => {
document.querySelectorAll(n).forEach((n => {
n.querySelector(".shop-card-checkbox") || t(n);
}));
})).observe(o, {
childList: !0,
subtree: !0
}), document.querySelectorAll(n).forEach((n => {
n.querySelector(".shop-card-checkbox") || t(n);
}));
}))(".shop-card", (function(n) {
const t = (function() {
const n = document.createElement("div");
n.className = "shop-card-checkbox", n.style.cssText = "\n display: flex;\n align-items: center;\n padding: 0 10px;\n margin-right: 10px;\n ";
const t = document.createElement("input");
return t.type = "checkbox", t.style.cssText = "\n width: 16px;\n height: 16px;\n cursor: pointer;\n ",
t.addEventListener("change", (n => {
n.stopPropagation(), document.dispatchEvent(new CustomEvent("checkbox-change"));
})), t.addEventListener("click", (n => {
n.stopPropagation();
})), n.appendChild(t), n;
})(), e = (function(n) {
const t = document.createElement("div");
t.style.cssText = "\n display: flex;\n gap: 8px;\n margin-left: 10px;\n ";
const e = document.createElement("button");
e.innerHTML = T + '\u67e5\u8be2';
const i = T + '\u67e5\u8be2', c = T + '\u67e5\u8be2\u4e2d...';
e.style.cssText = "\n padding: 0 12px;\n font-size: 12px;\n border-radius: 4px;\n cursor: pointer;\n border: 1px solid #1890ff;\n background-color: #fff;\n color: #1890ff;\n transition: all 0.3s;\n outline: none;\n font-weight: normal;\n height: 24px;\n line-height: 22px;\n box-shadow: 0 2px 0 rgba(0,0,0,0.015);\n white-space: nowrap;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 48px;\n ";
const r = document.createElement("button");
r.innerHTML = V + '\u9080\u7ea6';
const a = V + '\u9080\u7ea6', s = V + '\u53d1\u9001\u4e2d...';
r.style.cssText = "\n padding: 0 12px;\n font-size: 12px;\n border-radius: 4px;\n cursor: pointer;\n border: 1px solid #52c41a;\n background-color: #52c41a;\n color: #fff;\n transition: all 0.3s;\n outline: none;\n font-weight: normal;\n height: 24px;\n line-height: 22px;\n box-shadow: 0 2px 0 rgba(0,0,0,0.015);\n white-space: nowrap;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 64px;\n ";
const l = (n, t) => {
t ? (n.style.opacity = "0.65", n.style.cursor = "not-allowed", n.disabled = !0) : (n.style.opacity = "1",
n.style.cursor = "pointer", n.disabled = !1);
};
return e.addEventListener("mouseover", (() => {
e.disabled || (e.style.backgroundColor = "#40a9ff", e.style.borderColor = "#40a9ff",
e.style.color = "#fff");
})), e.addEventListener("mouseout", (() => {
e.disabled || (e.style.backgroundColor = "#fff", e.style.borderColor = "#1890ff",
e.style.color = "#1890ff");
})), r.addEventListener("mouseover", (() => {
r.disabled || (r.style.backgroundColor = "#73d13d", r.style.borderColor = "#73d13d");
})), r.addEventListener("mouseout", (() => {
r.disabled || (r.style.backgroundColor = "#52c41a", r.style.borderColor = "#52c41a");
})), e.addEventListener("mousedown", (() => {
e.disabled || (e.style.backgroundColor = "#096dd9", e.style.borderColor = "#096dd9");
})), e.addEventListener("mouseup", (() => {
e.disabled || (e.style.backgroundColor = "#40a9ff", e.style.borderColor = "#40a9ff");
})), r.addEventListener("mousedown", (() => {
r.disabled || (r.style.backgroundColor = "#389e0d", r.style.borderColor = "#389e0d");
})), r.addEventListener("mouseup", (() => {
r.disabled || (r.style.backgroundColor = "#73d13d", r.style.borderColor = "#73d13d");
})), e.addEventListener("click", (async t => {
if (!e.disabled) {
t.stopPropagation(), t.preventDefault();
try {
l(e, !0), e.innerHTML = c;
const t = f(n);
if (!t) return void alert("\u672a\u627e\u5230\u8fbe\u4eba\u8d44\u6599");
const o = await h(t);
if (200 !== o.code && 0 !== o.code || !o.data?.wechat_id) alert("\u67e5\u8be2\u5931\u8d25: " + (o.message || "\u672a\u627e\u5230\u8054\u7cfb\u65b9\u5f0f")); else {
const n = [ "\u8fbe\u4eba\u540d\u79f0: " + (t.name || t.nickname || "\u672a\u77e5"), "\u8054\u7cfb\u65b9\u5f0f: " + o.data.wechat_id, "\u6570\u636e\u6765\u6e90: " + ("db" === o.source ? "\u6570\u636e\u5e93" : "API\u67e5\u8be2"), o.remaining ? "API\u5269\u4f59\u6b21\u6570: " + o.remaining : "", "db" === o.source && o.saved_at ? "\u6570\u636e\u5e93\u66f4\u65b0\u65f6\u95f4: " + x(o.saved_at) : "" ].filter(Boolean).join("\n");
alert(n);
}
} catch (n) {
alert("\u67e5\u8be2\u8054\u7cfb\u65b9\u5f0f\u5931\u8d25: " + n.message);
} finally {
l(e, !1), e.innerHTML = i;
}
}
})), r.addEventListener("click", (async t => {
if (!r.disabled) {
t.stopPropagation(), t.preventDefault();
try {
l(r, !0), r.innerHTML = s;
const t = f(n);
if (!t) return void alert("\u672a\u627e\u5230\u8fbe\u4eba\u8d44\u6599");
const e = o();
if (!e.templates.length || !e.activeTemplateId) return void alert("\u8bf7\u5148\u914d\u7f6e\u9080\u7ea6\u6a21\u677f");
if (!e.productIds.length) return void alert("\u8bf7\u5148\u914d\u7f6e\u5546\u54c1");
if (!e.contactInfo.phone || !e.contactInfo.wechat) return void alert("\u8bf7\u5148\u914d\u7f6e\u8054\u7cfb\u65b9\u5f0f");
const i = d(t.sec_author_id), c = await u(i);
0 === c.code ? alert("\u9080\u7ea6\u53d1\u9001\u6210\u529f\uff01") : alert("\u9080\u7ea6\u53d1\u9001\u5931\u8d25: " + c.msg);
} catch (n) {
alert("\u53d1\u9001\u9080\u7ea6\u5931\u8d25: " + n.message);
} finally {
l(r, !1), r.innerHTML = a;
}
}
})), t.appendChild(e), t.appendChild(r), t;
})(n);
n.insertBefore(t, n.firstChild), n.appendChild(e);
})), window.addEventListener("load", (function() {
const n = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(t, o, e, i, c) {
return "string" == typeof o && (o.includes("/square_pc_api/shop/shopProfileAuthorList") ? this.addEventListener("load", (function() {
try {
const n = JSON.parse(this.response), t = this.responseURL;
r[t] = n, n.data?.author_list?.forEach((n => {
n.avatar && (a[n.avatar] = t);
}));
} catch (n) {}
})) : o.includes("/square_pc_api/shop/shopProfile") && this.addEventListener("load", (function() {
try {
const n = JSON.parse(this.response);
if (0 === n.code && n.data?.basic_info) {
const {basic_info: t} = n.data;
s.name = t.name || "", s.avatar = t.avatar || "", s.shopId = t.shop_id?.toString() || "";
}
} catch (n) {}
}))), n.call(this, t, o, e ?? !0, i, c);
};
}));
})();