Greasy Fork is available in English.
抖店达人拓展好帮手
当前为
// ==UserScript==
// @name 抖店达人助手
// @namespace https://github.com/yourusername
// @version 2.3.0
// @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
// ==/UserScript==
(function () {
'use strict';
const e = {
templates: [],
productSettings: {},
productIds: [],
contactInfo: {
phone: "",
wechat: ""
},
activeTemplateId: ""
}, t = "INVITE_CARD_CONFIG";
function getConfig() {
const n = GM_getValue(t, e);
return {
templates: n.templates || e.templates,
productSettings: n.productSettings || {},
productIds: n.productIds || [],
contactInfo: {
phone: n.contactInfo?.phone || "",
wechat: n.contactInfo?.wechat || ""
},
activeTemplateId: n.activeTemplateId || e.activeTemplateId
};
}
function saveConfig(e) {
GM_setValue(t, e);
}
function debounce(e, t) {
let n;
return (...o) => {
clearTimeout(n), n = window.setTimeout((() => e(...o)), t);
};
}
function createConfigPanel() {
const e = document.createElement("div");
e.className = "shop-config-overlay", e.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 n = document.createElement("style");
n.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(n);
const o = document.createElement("div");
o.className = "header", o.innerHTML = '\n <h3>\u9080\u8bf7\u914d\u7f6e</h3>\n <button style="font-size:20px;line-height:1;padding:0 8px;border:none;background:none;">\xd7</button>\n ';
const i = document.createElement("div");
i.className = "content";
const a = document.createElement("div");
a.style.flex = "1";
const c = document.createElement("div");
c.className = "form-block", c.innerHTML = '\n <div class="highlight-text">\u9080\u7ea6\u4fe1\u606f</div>\n <div class="form-row">\n <div class="form-label">\u9080\u7ea6\u5185\u5bb9</div>\n <div class="form-content">\n <textarea class="large" placeholder="\u8bf7\u8f93\u5165\u9080\u7ea6\u5185\u5bb9"></textarea>\n </div>\n </div>\n <div class="form-row">\n <div class="form-label">\u4e13\u5c5e\u6743\u76ca</div>\n <div class="form-content">\n <div class="checkbox-group">\n <label class="checkbox-wrapper checked">\n <span class="checkbox-inner"></span>\n <span>\u4e13\u5c5e\u9ad8\u4f63</span>\n </label>\n <label class="checkbox-wrapper checked">\n <span class="checkbox-inner"></span>\n <span>\u514d\u8d39\u7533\u6837</span>\n </label>\n <label class="checkbox-wrapper">\n <span class="checkbox-inner"></span>\n <span>\u89c6\u9891\u7d20\u6750\u652f\u6301</span>\n </label>\n <label class="checkbox-wrapper">\n <span class="checkbox-inner"></span>\n <span>\u4f18\u8d28\u89c6\u9891\u6295\u6d41</span>\n </label>\n </div>\n </div>\n </div>\n ';
const r = document.createElement("div");
r.className = "form-block", r.innerHTML = '\n <div class="highlight-text">\u8054\u7cfb\u65b9\u5f0f</div>\n <div class="form-row">\n <div class="form-label">\u624b\u673a\u53f7</div>\n <div class="form-content">\n <input type="text" placeholder="\u8bf7\u8f93\u5165\u624b\u673a\u53f7" maxlength="11">\n </div>\n </div>\n <div class="form-row">\n <div class="form-label">\u5fae\u4fe1\u53f7</div>\n <div class="form-content">\n <input type="text" placeholder="\u8bf7\u8f93\u5165\u5fae\u4fe1\u53f7" maxlength="20">\n </div>\n </div>\n ';
const s = document.createElement("div");
s.className = "form-block", s.innerHTML = '\n <div class="highlight-text">\u5546\u54c1\u914d\u7f6e</div>\n <div style="margin-bottom:16px">\n <button type="button" class="btn btn-primary">\u6dfb\u52a0\u5546\u54c1</button>\n </div>\n <table class="table">\n <thead>\n <tr>\n <th>\u5546\u54c1\u4fe1\u606f</th>\n <th style="width:120px">\u4e13\u5c5e\u4f63\u91d1</th>\n <th style="width:100px">\u514d\u5ba1\u7533\u6837</th>\n <th style="width:160px">\u7b56\u7565\u7ed3\u675f\u65f6\u95f4</th>\n <th style="width:80px">\u64cd\u4f5c</th>\n </tr>\n </thead>\n <tbody></tbody>\n </table>\n ',
a.appendChild(c), a.appendChild(r), a.appendChild(s), i.appendChild(a);
const l = document.createElement("div");
l.style.cssText = "width:286px;flex-shrink:0;", l.innerHTML = '\n <div class="highlight-text" style="margin:4px 0 8px 4px">\u6548\u679c\u9884\u89c8</div>\n <img width="286" src="https://p3-infra.elabpic.com/tos-cn-i-ax5x5hote5/3343d634a25844368fe5ec79df459dc0~tplv-ax5x5hote5-image.image">\n ',
i.appendChild(l);
const d = document.createElement("div");
d.className = "footer", d.innerHTML = '<button type="button" class="btn">\u53d6\u6d88</button>';
const p = document.createElement("button");
p.textContent = "\u9884\u89c8\u914d\u7f6e", p.className = "btn", p.style.marginRight = "8px",
p.onclick = () => (function showPreviewDialog() {
const e = convertConfigToRequestBody("preview_account_id"), t = JSON.stringify(e, null, 2), n = document.createElement("div");
n.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;",
n.innerHTML = `\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;">\n <h3 style="margin:0">\u914d\u7f6e\u9884\u89c8</h3>\n <button style="font-size:20px;line-height:1;padding:0 8px;border:none;background:none;cursor:pointer;">\xd7</button>\n </div>\n <pre style="flex:1;overflow:auto;background:#f5f5f5;padding:16px;border-radius:2px;margin:0;font-family:monospace;font-size:12px;">${t}</pre>\n `,
n.querySelector("button").onclick = () => document.body.removeChild(n), document.body.appendChild(n);
})(), d.insertBefore(p, d.firstChild), t.appendChild(o), t.appendChild(i), t.appendChild(d),
e.appendChild(t);
[ o.querySelector("button"), d.querySelector(".btn:last-child") ].forEach((n => {
n.onclick = () => {
e.style.display = "none", t.style.display = "none";
};
})), e.onclick = n => {
n.target === e && (e.style.display = "none", t.style.display = "none");
};
const h = getConfig(), f = c.querySelector("textarea");
f.value = h.templates[0]?.content || "", f.onchange = debounce((e => {
const t = getConfig(), n = e.target.value, o = "template_" + Date.now();
0 === t.templates.length ? (t.templates.push({
id: o,
name: "\u9080\u7ea6\u6a21\u677f",
content: n,
rights: [ {
right: 1
}, {
right: 2
} ]
}), t.activeTemplateId = o) : t.templates[0].content = n, saveConfig(t);
}), 300);
c.querySelectorAll(".checkbox-wrapper").forEach(((e, t) => {
const n = h.templates[0]?.rights || [ {
right: 1
}, {
right: 2
} ], o = [ 1, 2, 4, 3 ][t];
n.some((e => e.right === o)) && e.classList.add("checked"), e.onclick = () => {
const t = getConfig();
e.classList.contains("checked") ? (e.classList.remove("checked"), t.templates[0].rights = t.templates[0].rights.filter((e => e.right !== o))) : (e.classList.add("checked"),
t.templates[0].rights.push({
right: o
})), saveConfig(t);
};
}));
const [u, g] = r.querySelectorAll("input");
u.value = h.contactInfo.phone, g.value = h.contactInfo.wechat, u.onchange = debounce((e => {
const t = e.target.value;
if (!(function validatePhoneNumber(e) {
return /^1[3-9]\d{9}$/.test(e);
})(t)) return void window.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801");
const n = getConfig();
n.contactInfo.phone = t, saveConfig(n);
}), 300), g.onchange = debounce((e => {
const t = e.target.value;
if (!(function validateWechat(e) {
return /^[a-zA-Z0-9_-]{6,20}$/.test(e);
})(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 n = getConfig();
n.contactInfo.wechat = t, saveConfig(n);
}), 300);
const m = s.querySelector("tbody");
function renderProductList() {
const e = getConfig();
m.innerHTML = e.productIds.map((t => {
const n = e.productSettings[t], o = n?.validTime && "end" === n.timeRadio ? n.validTime.split(" ")[0] : "\u957f\u671f";
return `\n <tr>\n <td>\n <div class="product-card">\n <img class="product-image" src="https://placeholder.com/32x32" alt="">\n <div class="product-info">\n <div class="product-title">\u5546\u54c1ID: ${t}</div>\n <div class="product-meta">\n <span>\u4f63\u91d1\uff1a${n?.cosRatio || 0}%</span>\n </div>\n </div>\n </div>\n </td>\n <td>\n <button type="button" class="btn btn-link set-ratio" data-id="${t}">\n ${n?.cosRatio ? `${n.cosRatio}%` : "\u8bbe\u7f6e"}\n </button>\n </td>\n <td>\n <div class="switch ${3 === n?.sampleStatus ? "checked" : ""}" data-id="${t}">\n <div class="switch-handle"></div>\n </div>\n </td>\n <td>\n <button type="button" class="btn btn-link set-end-time" data-id="${t}">\n ${o}\n </button>\n </td>\n <td>\n <button type="button" class="btn btn-link delete-product" data-id="${t}">\u5220\u9664</button>\n </td>\n </tr>\n `;
})).join(""), m.querySelectorAll("[data-id]").forEach((e => {
const t = e.getAttribute("data-id");
e.classList.contains("set-ratio") ? e.onclick = () => {
const e = getConfig(), n = e.productSettings[t]?.cosRatio || 40, o = prompt("\u8bf7\u8f93\u5165\u4e13\u5c5e\u4f63\u91d1\u6bd4\u4f8b\uff08%\uff09", n.toString());
if (null !== o) {
const n = parseInt(o);
!isNaN(n) && n >= 0 && n <= 100 ? (e.productSettings[t].cosRatio = n, saveConfig(e),
renderProductList()) : window.alert("\u8bf7\u8f93\u51650-100\u4e4b\u95f4\u7684\u6709\u6548\u6570\u5b57");
}
} : e.classList.contains("switch") ? e.onclick = () => {
const e = getConfig(), n = e.productSettings[t].sampleStatus;
e.productSettings[t].sampleStatus = 3 === n ? 1 : 3, saveConfig(e), renderProductList();
} : e.classList.contains("set-end-time") ? e.onclick = () => {
const e = getConfig(), n = e.productSettings[t];
if ("long" === n.timeRadio) {
if (confirm("\u662f\u5426\u8bbe\u7f6e\u7b56\u7565\u675f\u65f6\u95f4\uff1f")) {
const t = new Date, o = new Date(t.getTime() + 6048e5), i = document.createElement("input");
i.type = "date", i.value = o.toISOString().split("T")[0], i.min = t.toISOString().split("T")[0],
i.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(i);
const a = document.createElement("div");
a.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(a), a.onclick = () => {
document.body.removeChild(i), document.body.removeChild(a);
}, i.onchange = t => {
const o = t.target.value;
n.timeRadio = "end", n.validTime = `${o} 23:59:59`, saveConfig(e), renderProductList(),
document.body.removeChild(i), document.body.removeChild(a);
}, setTimeout((() => {
i.focus();
}), 100);
}
} else confirm("\u662f\u5426\u6539\u4e3a\u957f\u671f\uff1f") && (n.timeRadio = "long",
n.validTime = "3000-01-01 00:00:00", saveConfig(e), renderProductList());
} : e.classList.contains("delete-product") && (e.onclick = () => {
if (confirm("\u786e\u5b9a\u5220\u9664\u8be5\u5546\u54c1\u5417\uff1f")) {
const e = getConfig();
e.productIds = e.productIds.filter((e => e !== t)), delete e.productSettings[t],
saveConfig(e), renderProductList();
}
});
}));
}
return s.querySelector(".btn-primary").onclick = () => {
const e = prompt("\u8bf7\u8f93\u5165\u5546\u54c1ID");
if (!e) return;
if (!(function validateProductId(e) {
return /^\d{6,20}$/.test(e);
})(e)) return void window.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5546\u54c1ID\uff086-20\u4f4d\u6570\u5b57\uff09");
const t = getConfig();
t.productIds.includes(e) ? window.alert("\u8be5\u5546\u54c1\u5df2\u6dfb\u52a0") : (t.productIds.push(e),
t.productSettings[e] = {
sampleStatus: 1,
cosRatio: 40,
timeRadio: "long",
validTime: "3000-01-01 00:00:00"
}, saveConfig(t), renderProductList());
}, renderProductList(), e;
}
function showConfigPanel() {
const e = document.querySelector(".shop-config-overlay");
if (e) e.style.display = "block", e.querySelector(".shop-config-panel").style.display = "flex"; else {
const e = createConfigPanel();
document.body.appendChild(e), e.style.display = "block", e.querySelector(".shop-config-panel").style.display = "flex";
}
}
const n = {}, o = {}, i = {
name: "",
avatar: "",
shopId: ""
};
function convertConfigToRequestBody(e) {
const t = getConfig(), n = t.templates.find((e => e.id === t.activeTemplateId));
if (!n) throw new Error("Template not found");
return {
account_id: e,
account_type: 1,
invite_card: {
content: n.content,
rights: n.rights,
product_ids: t.productIds,
product_setting: t.productIds.filter((e => t.productSettings[e])).map((e => {
const n = t.productSettings[e];
return {
product_id: e,
author_sample_status: n.sampleStatus,
orient_cos_ratio_detail: {
orient_kol_cos_ratio: n.cosRatio,
time_radio: n.timeRadio,
valid_time: n.validTime || "3000-01-01 00:00:00",
suggest_orient_kol_cos_ratio: 53,
...n.cosRatio ? {} : {
cos_ratio_range: {
low: 0,
high: 80
}
}
}
};
}))
},
contact_info: t.contactInfo
};
}
function getShopProfile(e) {
const t = (function findAuthorByAvatar(e) {
const t = o[e];
if (!t) return null;
const i = n[t];
return i?.data?.author_list ? i.data.author_list.find((t => t.avatar === e)) : null;
})(e);
return t || null;
}
function extractAvatarUrl(e) {
const t = e.querySelector(".card-info__avatar img"), n = t?.getAttribute("src") || null;
return n || null;
}
function getShopProfileFromElement(e) {
const t = extractAvatarUrl(e);
return t ? getShopProfile(t) : null;
}
function getShopProfilesFromElements(e) {
return (function getShopProfiles(e) {
return e.map((e => getShopProfile(e))).filter((e => null !== e));
})(e.map(extractAvatarUrl).filter((e => null !== e)));
}
async function queryContact(e) {
return new Promise(((t, n) => {
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,
Cookie: document.cookie
},
data: JSON.stringify(e),
onload: function(e) {
try {
const o = JSON.parse(e.responseText);
200 === e.status && 200 === o.code ? t(o) : n(new Error(o.message || "\u8bf7\u6c42\u5931\u8d25"));
} catch (o) {
n(o);
}
},
onerror: function(e) {
n(new Error("\u7f51\u7edc\u8bf7\u6c42\u5931\u8d25"));
}
});
}));
}
async function sendInvite(e) {
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(e),
credentials: "include"
});
if (!t.ok) throw new Error(`HTTP error! status: ${t.status}`);
const n = await t.json();
if (0 === n.code) return n;
throw new Error(n.msg || "\u8bf7\u6c42\u5931\u8d25");
} catch (t) {
throw t;
}
}
function formatDateTime(e) {
try {
return new Date(e).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 e;
}
}
const a = {
info: '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"/><path d="M464 336a48 48 0 1096 0 48 48 0 10-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z"/></svg>',
success: '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"/></svg>',
error: '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"/></svg>',
clear: '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M899.1 869.6l-53-305.6H864c14.4 0 26-11.6 26-26V346c0-14.4-11.6-26-26-26H618V138c0-14.4-11.6-26-26-26H432c-14.4 0-26 11.6-26 26v182H160c-14.4 0-26 11.6-26 26v192c0 14.4 11.6 26 26 26h17.9l-53 305.6c-.3 1.5-.4 3-.4 4.4 0 14.4 11.6 26 26 26h723c1.5 0 3-.1 4.4-.4 14.2-2.4 23.7-15.9 21.2-30zM204 390h272V182h72v208h272v104H204V390zm468 440V674c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v156H416V674c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v156H202.8l45.1-260H776l45.1 260H672z"/></svg>',
minimize: '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M872 474H152c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h720c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z"/></svg>'
};
let c = null, r = null;
function createLogPanel() {
const e = document.createElement("div");
e.className = "shop-log-panel", e.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: #fafafa;\n cursor: move;\n ";
const n = document.createElement("div");
n.style.cssText = "\n display: flex;\n align-items: center;\n gap: 8px;\n ";
const o = document.createElement("span");
o.textContent = "\u64cd\u4f5c\u65e5\u5fd7", o.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 s = document.createElement("button");
s.innerHTML = `${a.minimize}`, s.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 l = document.createElement("button");
l.innerHTML = `${a.clear}<span style="margin-left:4px">\u6e05\u7a7a</span>`, l.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 d = !1;
s.onclick = () => {
d = !d, e.style.transform = d ? `translateY(${e.offsetHeight - t.offsetHeight}px)` : "translateY(0)";
}, l.onclick = clearLog, n.appendChild(o), i.appendChild(s), i.appendChild(l), t.appendChild(n),
t.appendChild(i);
const p = document.createElement("div");
p.style.cssText = "\n flex: 1;\n overflow-y: auto;\n padding: 8px 0;\n max-height: 320px;\n ",
e.appendChild(t), e.appendChild(p), c = e, r = p;
let h, f, u, g, m = !1;
return t.addEventListener("mousedown", (t => {
m = !0, u = t.clientX - e.offsetLeft, g = t.clientY - e.offsetTop;
})), document.addEventListener("mousemove", (t => {
if (m) {
t.preventDefault(), h = t.clientX - u, f = t.clientY - g;
const n = window.innerWidth - e.offsetWidth, o = window.innerHeight - e.offsetHeight;
h = Math.max(0, Math.min(h, n)), f = Math.max(0, Math.min(f, o)), e.style.left = `${h}px`,
e.style.bottom = window.innerHeight - f - e.offsetHeight + "px";
}
})), document.addEventListener("mouseup", (() => {
m = !1;
})), e;
}
function addLogEntry(e, t) {
if (!r) return;
const n = document.createElement("div");
n.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 o = document.createElement("span");
o.style.cssText = `\n margin-top: 2px;\n flex-shrink: 0;\n color: ${"info" === t.type ? "#1890ff" : "success" === t.type ? "#52c41a" : "#ff4d4f"};\n `,
o.innerHTML = "info" === t.type ? a.info : "success" === t.type ? a.success : a.error;
const i = document.createElement("span");
i.style.cssText = "\n color: #999;\n font-size: 11px;\n flex-shrink: 0;\n min-width: 50px;\n ",
i.textContent = (new Date).toLocaleTimeString("zh-CN", {
hour12: !1
});
const c = document.createElement("span");
if (c.style.cssText = "\n flex: 1;\n word-break: break-all;\n ",
c.textContent = e, t.details) {
const e = document.createElement("span");
e.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:${formatDateTime(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), e.textContent = o.join(" | "),
n.appendChild(e);
}
n.appendChild(o), n.appendChild(i), n.appendChild(c), r.appendChild(n), r.scrollTop = r.scrollHeight;
}
function clearLog() {
r && (r.innerHTML = "");
}
function addInfoLog(e) {
c || document.body.appendChild(createLogPanel()), addLogEntry(e, {
type: "info"
});
}
function addSuccessLog(e, t) {
c || document.body.appendChild(createLogPanel()), addLogEntry(e, {
type: "success",
details: t
});
}
function addErrorLog(e, t) {
c || document.body.appendChild(createLogPanel()), addLogEntry(e, {
type: "error",
details: t
});
}
function formatNumberWithUnit(e) {
return e >= 1e8 ? (e / 1e8).toFixed(0) + "E" : e >= 1e4 ? (e / 1e4).toFixed(0) + "W" : e.toString();
}
const s = [ {
key: "name",
title: "\u8fbe\u4eba\u540d\u79f0"
}, {
key: "level",
title: "\u7b49\u7ea7"
}, {
key: "fans_num",
title: "\u7c89\u4e1d\u6570",
format: function formatFansCount(e) {
if (null == e) return "";
const t = 100 * Math.floor(e / 100);
return t >= 1e4 ? (t / 1e4).toFixed(1) + "W" : t >= 1e3 ? (t / 1e3).toFixed(1) + "K" : t.toString();
}
}, {
key: "sale_range",
title: "\u5e97\u94fa\u63a8\u5e7f\u9500\u552e\u989d",
getValue: e => e,
format: function formatSaleRange(e) {
const t = e.sale?.low, n = e.sale?.high;
return null == t || null == n ? "" : 0 === t && 0 === n ? "0" : t === n ? formatNumberWithUnit(t) : `${formatNumberWithUnit(t)}-${formatNumberWithUnit(n)}`;
}
}, {
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 exportSelectedShops() {
const e = Array.from(document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]:checked')).map((e => e.closest(".shop-card"))).filter((e => null !== e));
if (0 === e.length) return void alert("\u8bf7\u5148\u9009\u62e9\u8981\u5bfc\u51fa\u7684\u8fbe\u4eba");
const t = confirm(`\u5df2\u9009\u4e2d ${e.length} \u4e2a\u8fbe\u4eba\uff0c\u662f\u5426\u8981\u53d1\u9001\u9080\u7ea6\uff1f`);
if (t) {
const e = getConfig();
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");
}
clearLog(), addInfoLog(`\u5f00\u59cb\u5904\u7406 | \u5df2\u9009\u4e2d ${e.length} \u4e2a\u8fbe\u4eba`);
const n = getShopProfilesFromElements(e);
if (0 === n.length) return void addErrorLog("\u672a\u627e\u5230\u8fbe\u4eba\u6570\u636e");
let o = 0, a = 0;
const c = [];
for (const i of n) try {
const e = i.name || i.nickname || "\u672a\u77e5\u8fbe\u4eba";
let n = "";
const s = await queryContact(i);
let l = e, d = [];
if (200 !== s.code && 0 !== s.code || !s.data?.wechat_id) {
0;
l += ` | \u67e5\u8be2\u5931\u8d25: ${s.message || "\u672a\u627e\u5230\u8054\u7cfb\u65b9\u5f0f"}`,
"api" === s.source && void 0 !== s.remaining && d.push(`API:${s.remaining}`);
} else o++, n = s.data.wechat_id, l += ` | \u67e5\u8be2\u6210\u529f: ${n}`, "db" === s.source && s.saved_at && d.push(`DB:${formatDateTime(s.saved_at)}`),
"api" === s.source && void 0 !== s.remaining && d.push(`API:${s.remaining}`);
if (t) try {
const e = convertConfigToRequestBody(i.sec_author_id), t = await sendInvite(e);
0 === t.code ? (a++, l += " | \u9080\u7ea6\u6210\u529f") : l += ` | \u9080\u7ea6\u5931\u8d25: ${t.msg}`;
} catch (r) {
0;
l += ` | \u9080\u7ea6\u5931\u8d25: ${r.message}`;
}
d.length > 0 && (l += ` | ${d.join(" | ")}`), l.includes("\u5931\u8d25") ? addErrorLog(l) : addSuccessLog(l),
c.push({
...i,
wechat_id: n
});
} catch (l) {
const e = l.message;
let n = `${i.name || i.nickname || "\u672a\u77e5\u8fbe\u4eba"} | \u67e5\u8be2\u5931\u8d25: ${e}`;
if (t) try {
const e = convertConfigToRequestBody(i.sec_author_id), t = await sendInvite(e);
0 === t.code ? (a++, n += " | \u9080\u7ea6\u6210\u529f") : n += ` | \u9080\u7ea6\u5931\u8d25: ${t.msg}`;
} catch (r) {
n += ` | \u9080\u7ea6\u5931\u8d25: ${r.message}`;
}
addErrorLog(n), c.push({
...i,
wechat_id: ""
});
}
if (addInfoLog("------------------------"), addInfoLog(t ? `\u5904\u7406\u5b8c\u6210 | \u67e5\u8be2\u6210\u529f\u7387: ${o}/${n.length} | \u9080\u7ea6\u6210\u529f\u7387: ${a}/${n.length}` : `\u5904\u7406\u5b8c\u6210 | \u67e5\u8be2\u6210\u529f\u7387: ${o}/${n.length}`),
o > 0) {
const e = (function convertToCSV(e) {
const t = s.map((e => e.title)).join(","), n = e.map((e => s.map((t => {
let n;
if (t.getValue) n = t.getValue(e); else if (t.key.startsWith("sale_")) {
const o = t.key.replace("sale_", "");
n = e.sale?.[o];
} else n = e[t.key];
return t.format ? formatValue(t.format(n)) : formatValue(n);
})).join(",")));
return [ t, ...n ].join("\n");
})(c), t = new Blob([ "\ufeff" + e ], {
type: "text/csv;charset=utf-8;"
}), n = URL.createObjectURL(t), o = document.createElement("a");
o.href = n;
const {name: a} = (function getShopInfo() {
return {
...i
};
})(), r = (new Date).toISOString().split("T")[0], l = a ? `${a}_\u8fbe\u4eba\u6570\u636e_${r}.csv` : `\u8fbe\u4eba\u6570\u636e_${r}.csv`;
o.download = l, document.body.appendChild(o), o.click(), document.body.removeChild(o),
URL.revokeObjectURL(n), addSuccessLog("\u6587\u4ef6\u5bfc\u51fa\u5b8c\u6210");
}
}
function formatValue(e) {
return null == e ? "" : "boolean" == typeof e ? e ? "\u662f" : "\u5426" : "number" == typeof e ? e.toString() : ("object" != typeof e || Array.isArray(e) || (e = JSON.stringify(e)),
"string" == typeof e && (e.includes(",") || e.includes("\n") || e.includes('"')) ? `"${e.replace(/"/g, '""')}"` : String(e));
}
const l = '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32zm-40 728H184V184h656v656zM492 400h184c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H492c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8zm0 144h184c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H492c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8zm0 144h184c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8H492c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8zM288 368c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v48zm0 144c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v48zm0 144c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v48z"/></svg>', d = '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M880 112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V144c0-17.7-14.3-32-32-32zm-40 464H528V448h312v128zm0 264H184V184h656v200H496c-17.7 0-32 14.3-32 32v192c0 17.7 14.3 32 32 32h344v200zM580 512h-48c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z"/></svg>', p = '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M924.8 625.7l-65.5-56c3.1-19 4.7-38.4 4.7-57.8s-1.6-38.8-4.7-57.8l65.5-56a32.03 32.03 0 0 0 9.3-35.2l-.9-2.6a443.74 443.74 0 0 0-79.7-137.9l-1.8-2.1a32.12 32.12 0 0 0-35.1-9.5l-81.3 28.9c-30-24.6-63.5-44-99.7-57.6l-15.7-85a32.05 32.05 0 0 0-25.8-25.7l-2.7-.5c-52.1-9.4-106.9-9.4-159 0l-2.7.5a32.05 32.05 0 0 0-25.8 25.7l-15.8 85.4a351.86 351.86 0 0 0-99 57.4l-81.9-29.1a32 32 0 0 0-35.1 9.5l-1.8 2.1a446.02 446.02 0 0 0-79.7 137.9l-.9 2.6c-4.5 12.5-.8 26.5 9.3 35.2l66.3 56.6c-3.1 18.8-4.6 38-4.6 57.1 0 19.2 1.5 38.4 4.6 57.1L99 625.5a32.03 32.03 0 0 0-9.3 35.2l.9 2.6c18.1 50.4 44.9 96.9 79.7 137.9l1.8 2.1a32.12 32.12 0 0 0 35.1 9.5l81.9-29.1c29.8 24.5 63.1 43.9 99 57.4l15.8 85.4a32.05 32.05 0 0 0 25.8 25.7l2.7.5a449.4 449.4 0 0 0 159 0l2.7-.5a32.05 32.05 0 0 0 25.8-25.7l15.7-85a350 350 0 0 0 99.7-57.6l81.3 28.9a32 32 0 0 0 35.1-9.5l1.8-2.1c34.8-41.1 61.6-87.5 79.7-137.9l.9-2.6c4.5-12.3.8-26.3-9.3-35zM788.3 465.9c2.5 15.1 3.8 30.6 3.8 46.1s-1.3 31-3.8 46.1l-6.6 40.1 74.7 63.9a370.03 370.03 0 0 1-42.6 73.6L721 702.8l-31.4 25.8c-23.9 19.6-50.5 35-79.3 45.8l-38.1 14.3-17.9 97a377.5 377.5 0 0 1-85 0l-17.9-97.2-37.8-14.5c-28.5-10.8-55-26.2-78.7-45.7l-31.4-25.9-93.4 33.2c-17-22.9-31.2-47.6-42.6-73.6l75.5-64.5-6.5-40c-2.4-14.9-3.7-30.3-3.7-45.5 0-15.3 1.2-30.6 3.7-45.5l6.5-40-75.5-64.5c11.3-26.1 25.6-50.7 42.6-73.6l93.4 33.2 31.4-25.9c23.7-19.5 50.2-34.9 78.7-45.7l37.9-14.3 17.9-97.2c28.1-3.2 56.8-3.2 85 0l17.9 97 38.1 14.3c28.7 10.8 55.4 26.2 79.3 45.8l31.4 25.8 92.8-32.9c17 22.9 31.2 47.6 42.6 73.6L781.8 426l6.5 39.9zM512 326c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176zm79.2 255.2A111.6 111.6 0 0 1 512 614c-29.9 0-58-11.7-79.2-32.8A111.6 111.6 0 0 1 400 502c0-29.9 11.7-58 32.8-79.2C454 401.6 482.1 390 512 390c29.9 0 58 11.6 79.2 32.8A111.6 111.6 0 0 1 624 502c0 29.9-11.7 58-32.8 79.2z"/></svg>';
function updateExportButtonText(e) {
const t = document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]:checked').length;
e.innerHTML = `${d}<span style="margin-left:4px">\u5bfc\u51fa\u9009\u4e2d(${t})</span>`;
}
const h = '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0011.6 0l43.6-43.5a8.2 8.2 0 000-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"/></svg>', f = '<svg viewBox="64 64 896 896" width="14" height="14" fill="currentColor"><path d="M892 772h-80v-80c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v80h-80c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h80v80c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-80h80c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8zM373.5 498.4c-.9-8.7-1.4-17.5-1.4-26.4 0-15.9 1.5-31.4 4.3-46.5.7-3.6-1.2-7.3-4.5-8.8-13.6-6.1-26.1-14.5-36.9-25.1a127.54 127.54 0 01-38.7-95.4c.9-32.1 13.8-62.6 36.3-85.6 24.7-25.3 57.9-39.1 93.2-38.7 31.9.3 62.7 12.6 86 34.4 7.9 7.4 14.7 15.6 20.4 24.4 2 3.1 5.9 4.4 9.3 3.2 17.6-6.1 36.2-10.4 55.3-12.4 5.6-.6 8.8-6.6 6.3-11.6-32.5-64.3-98.9-108.7-175.7-109.9-110.8-1.7-203.2 89.2-203.2 200 0 62.8 28.9 118.8 74.2 155.5-31.8 14.7-61.1 35-86.5 60.4-54.8 54.7-85.8 126.9-87.8 204a8 8 0 008 8.2h56.1c4.3 0 7.9-3.4 8-7.7 1.9-58 25.4-112.3 66.7-153.5 29.4-29.4 65.4-49.8 104.7-59.7 3.8-1.1 6.4-4.8 5.9-8.8z"/><path d="M824 472c0-109.4-87.9-198.3-196.9-200C516.3 270.3 424 361.2 424 472c0 62.8 29 118.8 74.2 155.5a300.95 300.95 0 00-86.4 60.4C357 742.6 326 814.8 324 891.8a8 8 0 008 8.2h56c4.3 0 7.9-3.4 8-7.7 1.9-58 25.4-112.3 66.7-153.5C505.8 695.7 563 672 624 672c110.4 0 200-89.5 200-200zm-109.5 90.5C690.3 586.7 658.2 600 624 600s-66.3-13.3-90.5-37.5a127.26 127.26 0 01-37.5-90.5c0-34.2 13.3-66.3 37.5-90.5 24.2-24.2 56.3-37.5 90.5-37.5s66.3 13.3 90.5 37.5c24.2 24.2 37.5 56.3 37.5 90.5s-13.3 66.3-37.5 90.5z"/></svg>';
function watchForElement(e, t) {
document.querySelector(".shop-control-panel") || document.body.appendChild((function createControlPanel() {
const e = document.createElement("div");
e.className = "shop-control-panel", e.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 n = document.createElement("button");
n.innerHTML = `${l}<span style="margin-left:4px">\u5168\u9009</span>`, n.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 o = document.createElement("button");
o.innerHTML = `${d}<span style="margin-left:4px">\u5bfc\u51fa\u9009\u4e2d(0)</span>`,
o.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 = `${p}<span style="margin-left:4px">\u9080\u8bf7\u914d\u7f6e</span>`,
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 a = document.createElement("div");
a.style.cssText = "\n display: flex;\n flex-direction: column;\n gap: 8px;\n ";
let c = !1;
return n.addEventListener("click", (() => {
c = !c, n.innerHTML = `${l}<span style="margin-left:4px">${c ? "\u53d6\u6d88\u5168\u9009" : "\u5168\u9009"}</span>`,
document.querySelectorAll('.shop-card-checkbox input[type="checkbox"]').forEach((e => {
e.checked = c;
})), updateExportButtonText(o);
})), o.addEventListener("click", exportSelectedShops), i.addEventListener("click", showConfigPanel),
document.addEventListener("checkbox-change", (() => {
updateExportButtonText(o);
})), a.appendChild(n), a.appendChild(o), a.appendChild(i), e.appendChild(t), e.appendChild(a),
e;
})()), document.querySelector(".shop-log-panel") || document.body.appendChild(createLogPanel());
const n = document.body;
new MutationObserver((() => {
document.querySelectorAll(e).forEach((e => {
e.querySelector(".shop-card-checkbox") || t(e);
}));
})).observe(n, {
childList: !0,
subtree: !0
});
document.querySelectorAll(e).forEach((e => {
e.querySelector(".shop-card-checkbox") || t(e);
}));
}
function handleShopCard(e) {
const t = (function createCheckboxDiv() {
const e = document.createElement("div");
e.className = "shop-card-checkbox", e.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", (e => {
e.stopPropagation(), e.target.checked, document.dispatchEvent(new CustomEvent("checkbox-change"));
})), t.addEventListener("click", (e => {
e.stopPropagation();
})), e.appendChild(t), e;
})(), n = (function createActionButton(e) {
const t = document.createElement("div");
t.style.cssText = "\n display: flex;\n gap: 8px;\n margin-left: 10px;\n ";
const n = document.createElement("button");
n.innerHTML = `${h}<span style="margin-left:4px">\u67e5\u8be2</span>`;
const o = `${h}<span style="margin-left:4px">\u67e5\u8be2</span>`, i = `${h}<span style="margin-left:4px">\u67e5\u8be2\u4e2d...</span>`;
n.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 a = document.createElement("button");
a.innerHTML = `${f}<span style="margin-left:4px">\u9080\u7ea6</span>`;
const c = `${f}<span style="margin-left:4px">\u9080\u7ea6</span>`, r = `${f}<span style="margin-left:4px">\u53d1\u9001\u4e2d...</span>`;
a.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 setButtonDisabled = (e, t) => {
t ? (e.style.opacity = "0.65", e.style.cursor = "not-allowed", e.disabled = !0) : (e.style.opacity = "1",
e.style.cursor = "pointer", e.disabled = !1);
};
return n.addEventListener("mouseover", (() => {
n.disabled || (n.style.backgroundColor = "#40a9ff", n.style.borderColor = "#40a9ff",
n.style.color = "#fff");
})), n.addEventListener("mouseout", (() => {
n.disabled || (n.style.backgroundColor = "#fff", n.style.borderColor = "#1890ff",
n.style.color = "#1890ff");
})), a.addEventListener("mouseover", (() => {
a.disabled || (a.style.backgroundColor = "#73d13d", a.style.borderColor = "#73d13d");
})), a.addEventListener("mouseout", (() => {
a.disabled || (a.style.backgroundColor = "#52c41a", a.style.borderColor = "#52c41a");
})), n.addEventListener("mousedown", (() => {
n.disabled || (n.style.backgroundColor = "#096dd9", n.style.borderColor = "#096dd9");
})), n.addEventListener("mouseup", (() => {
n.disabled || (n.style.backgroundColor = "#40a9ff", n.style.borderColor = "#40a9ff");
})), a.addEventListener("mousedown", (() => {
a.disabled || (a.style.backgroundColor = "#389e0d", a.style.borderColor = "#389e0d");
})), a.addEventListener("mouseup", (() => {
a.disabled || (a.style.backgroundColor = "#73d13d", a.style.borderColor = "#73d13d");
})), n.addEventListener("click", (async t => {
if (!n.disabled) {
t.stopPropagation(), t.preventDefault();
try {
setButtonDisabled(n, !0), n.innerHTML = i;
const t = getShopProfileFromElement(e);
if (!t) return void alert("\u672a\u627e\u5230\u8fbe\u4eba\u8d44\u6599");
const o = await queryContact(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 e = [ `\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: ${formatDateTime(o.saved_at)}` : "" ].filter(Boolean).join("\n");
alert(e);
}
} catch (a) {
alert("\u67e5\u8be2\u8054\u7cfb\u65b9\u5f0f\u5931\u8d25: " + a.message);
} finally {
setButtonDisabled(n, !1), n.innerHTML = o;
}
}
})), a.addEventListener("click", (async t => {
if (!a.disabled) {
t.stopPropagation(), t.preventDefault();
try {
setButtonDisabled(a, !0), a.innerHTML = r;
const t = getShopProfileFromElement(e);
if (!t) return void alert("\u672a\u627e\u5230\u8fbe\u4eba\u8d44\u6599");
const n = getConfig();
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");
const o = convertConfigToRequestBody(t.sec_author_id), i = await sendInvite(o);
0 === i.code ? alert("\u9080\u7ea6\u53d1\u9001\u6210\u529f\uff01") : alert(`\u9080\u7ea6\u53d1\u9001\u5931\u8d25: ${i.msg}`);
} catch (n) {
alert("\u53d1\u9001\u9080\u7ea6\u5931\u8d25: " + n.message);
} finally {
setButtonDisabled(a, !1), a.innerHTML = c;
}
}
})), t.appendChild(n), t.appendChild(a), t;
})(e);
e.insertBefore(t, e.firstChild), e.appendChild(n);
}
watchForElement(".shop-card", handleShopCard), (function setupApiMonitor() {
window.addEventListener("load", (function() {
const e = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(t, a, c, r, s) {
return "string" == typeof a && (a.includes("/square_pc_api/shop/shopProfileAuthorList") ? this.addEventListener("load", (function() {
try {
const e = JSON.parse(this.response), t = this.responseURL;
n[t] = e, e.data?.author_list?.forEach((e => {
e.avatar && (o[e.avatar] = t);
}));
} catch (e) {}
})) : a.includes("/square_pc_api/shop/shopProfile") && this.addEventListener("load", (function() {
try {
const e = JSON.parse(this.response);
if (0 === e.code && e.data?.basic_info) {
const {basic_info: t} = e.data;
i.name = t.name || "", i.avatar = t.avatar || "", i.shopId = t.shop_id?.toString() || "";
}
} catch (e) {}
}))), e.apply(this, [ t, a, c ?? !0, r, s ]);
};
}));
})();
})();