v1.10.1: 支付成功即显示卡密 + 已支付未发卡的明确状态

- 订单状态区新增「你的卡密」展示区,拿到 card_key 立刻显示(不等激活结果)
- 自动激活失败时给出手动激活路径(卡密+侧边栏步骤+订单号)
- paid 但无卡密时显示发卡进度,90s 后提示权益不丢失可凭订单号补发
- 卡密一键复制(clipboard API → execCommand 降级)
This commit is contained in:
jinghui committed 2026-10-20 22:01:47 +08:00
1 parent ec8bfda853
commit 32f48613c4
5 files changed
+149 -4

No files matched your search

+56 -3
View File
@@ -99,20 +99,36 @@ function startPolling() {
try {
const res = await chrome.runtime.sendMessage({ action: 'authQueryOrder', orderNo });
if (!res || !res.ok) return;
// 只要拿到卡密就先展示出来,不等激活结果——自动激活失败时用户手里必须有码
if (res.cardKey) showCardBox(res.cardKey, !!res.activated);
if (res.activated) {
clearInterval(pollTimer);
pollTimer = null;
showActivated(res);
} else if (res.cardKey && !res.activated) {
} else if (res.cardKey) {
clearInterval(pollTimer);
pollTimer = null;
const status = $('order-status');
status.className = 'order-status error';
status.textContent = '✗ 已支付但激活失败:' + (res.message || '请联系客服,提供订单号补发');
status.innerHTML = '✗ <b>已支付并已发卡</b>,但自动激活未成功(' +
esc(res.message || '本机绑定可能被占用') + ')。请用上方卡密手动激活:回到插件侧边栏 → 卡密输入框粘贴 → 点「粘贴卡密并激活」。<br>' +
'订单号:<b>' + esc(orderNo || '') + '</b>';
} else if (res.paid) {
// 已付款但服务端还没把卡发出来(最常见原因是卡池库存不足)
const waited = attempts * 5;
const status = $('order-status');
status.className = 'order-status pending';
status.textContent = '⏳ 已支付,正在为你发卡…(订单 ' + orderNo + ',已等待 ' + waited + ' 秒)';
if (waited >= 90) {
status.className = 'order-status error';
status.innerHTML = '⏳ <b>已支付</b>,但发卡耗时较长(已 ' + waited + ' 秒)。订单 <b>' + esc(orderNo) +
'</b> 付款状态为已支付,<b>权益不会丢失</b>:继续等会自动发放,或凭此订单号联系客服补发。';
}
} else {
const status = $('order-status');
status.className = 'order-status pending';
status.textContent = `⏳ 等待支付中…(订单 ${orderNo},已等待 ${attempts * 5} 秒)`;
status.textContent = '⏳ 等待支付中…(订单 ' + orderNo + ',已等待 ' + attempts * 5 + ' 秒)';
}
} catch (e) {
/* 单次查询失败不中断轮询 */
@@ -120,6 +136,17 @@ function startPolling() {
}, 5000);
}
/** 支付成功后立刻把卡密展示给用户(含自动激活失败的场景) */
function showCardBox(key, activated) {
const box = $('card-box');
if (!box || !key) return;
if (!box.hidden && $('cb-key-text').textContent === key) return;
$('cb-key-text').textContent = key;
box.hidden = false;
$('cb-copy-tip').textContent = activated ? '已自动激活本机,这是你的卡密,建议留存' : '';
box.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
function showActivated(res) {
const status = $('order-status');
status.className = 'order-status success';
@@ -134,4 +161,30 @@ document.querySelectorAll('.pay-btn').forEach((btn) => {
btn.addEventListener('click', () => createOrder(btn.dataset.pay));
});
// 复制卡密:优先 clipboard API,无权限时降级 execCommand
$('cb-copy') && $('cb-copy').addEventListener('click', async () => {
const key = ($('cb-key-text').textContent || '').trim();
if (!key) return;
let ok = false;
try {
await navigator.clipboard.writeText(key);
ok = true;
} catch (e) { /* 降级 */ }
if (!ok) {
try {
const ta = document.createElement('textarea');
ta.value = key;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
ok = document.execCommand('copy');
document.body.removeChild(ta);
} catch (e2) {
ok = false;
}
}
$('cb-copy-tip').textContent = ok ? '已复制,可直接粘贴到侧边栏激活' : '复制失败,请手动长按选择卡密';
});
loadPackages();