v1.9.0: 试用策略改为 3 天/30 条(任一先到即止)+ 价值时刻提示 + 到期 24h 内 8 折 + 过期只锁评论

This commit is contained in:
personal82555 committed 2026-10-14 21:29:55 +08:00
1 parent 557f75fc54
commit 6a697a2663
6 files changed
+97 -18

No files matched your search

+42 -9
View File
@@ -69,7 +69,8 @@ reportInstall(false); // SW 启动即登记一次(同一浏览器只记一条
const AUTH_BASE = "https://auth.88531.cn/api";
const PROJECT_NAME = "B站评论插件";
const PROJECT_ID = 4;
const TRIAL_MS = 24 * 3600 * 1000; // 未授权试用1天
const TRIAL_MS = 72 * 3600 * 1000; // 未授权试用3天
const TRIAL_COMMENT_LIMIT = 30; // 试用期内最多30条评论,用完或到期任一先到即止
const CARD_API_KEY = "ak_ab99ed40b2296d6d2db06a4b5692b987";
async function getMachineId() {
@@ -124,14 +125,21 @@ async function checkLicense() {
offline = true; // 网络/超时 → 放行
}
const st = await chrome.storage.local.get("trialStart");
const st = await chrome.storage.local.get(["trialStart", "trialComments"]);
let trialStart = Number(st.trialStart) || 0;
if (!trialStart) {
trialStart = Date.now();
await chrome.storage.local.set({ trialStart: trialStart });
}
const trialEnd = trialStart + TRIAL_MS;
const leftMs = Math.max(0, trialEnd - Date.now());
const now = Date.now();
const leftMs = Math.max(0, trialEnd - now);
const usedComments = Number(st.trialComments) || 0;
const leftComments = Math.max(0, TRIAL_COMMENT_LIMIT - usedComments);
// 到期后24小时内购买享8折(折扣窗口从试用到期时刻起算)
const discountEnd = trialEnd + 24 * 3600 * 1000;
const inDiscount = leftMs <= 0 && now < discountEnd;
const discountLeftMs = inDiscount ? discountEnd - now : 0;
return {
authorized: authorized || offline, // offline 时视为放行
@@ -141,7 +149,12 @@ async function checkLicense() {
machine: machine,
trialStart: trialStart,
trialEnd: trialEnd,
trialLeftMs: leftMs
trialLeftMs: leftMs,
trialCommentsUsed: usedComments,
trialCommentsLimit: TRIAL_COMMENT_LIMIT,
trialCommentsLeft: leftComments,
inDiscount: inDiscount,
discountLeftMs: discountLeftMs
};
}
@@ -450,11 +463,23 @@ async function sendWithRetry(tabId, msg, tries) {
async function handleStartRun(p, sendResponse) {
try {
// 授权闸门:未授权且试用到期 → 拦截自动评论(下载视频不走这里,不受影响)
// 授权闸门:未授权时同时检查试用时长与试用条数(下载视频不走这里,不受影响)
const lic = await checkLicense();
if (!lic.authorized && lic.trialLeftMs <= 0) {
sendResponse({ ok: false, error: "免费试用已到期,自动评论已锁定。购买卡密激活后即可继续使用(下载视频不受影响)" });
return;
if (!lic.authorized) {
if (lic.trialLeftMs <= 0) {
sendResponse({ ok: false, error: "免费试用已到期,自动评论已锁定。购买卡密激活后即可继续使用(下载视频不受影响)" });
return;
}
if (lic.trialCommentsLeft <= 0) {
sendResponse({ ok: false, error: "试用期 " + lic.trialCommentsLimit + " 条评论已用完,购买卡密激活后不限量(下载视频不受影响)" });
return;
}
// 试用中:把剩余额度写进任务配置,内容脚本发到额度会自动停
p.config = p.config || {};
p.config.trialQuota = lic.trialCommentsLeft;
if (Number(p.config.maxN) > lic.trialCommentsLeft) {
p.config.maxN = lic.trialCommentsLeft;
}
}
ACTIVE_TASK = null; // 本次点「开始」= 全新任务,作废残留的旧任务(旧任务会带着预生成的旧文案继续跑)
let tab = await findBiliTab();
@@ -604,7 +629,15 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
(async () => {
const h = await addRecord({ bvid: msg.bvid, title: msg.title, text: msg.text, keyword: msg.keyword, ts: msg.ts });
const s = statsOf(h);
sendResponse({ ok: true, stats: { total: s.total, today: s.today, week: s.week } });
// 试用计数:每成功发一条评论消耗一次额度(仅未授权时计数)
let trialCommentsLeft = null;
const lic = await checkLicense();
if (!lic.realAuthorized && !lic.offline) {
const used = lic.trialCommentsUsed + 1;
await chrome.storage.local.set({ trialComments: used });
trialCommentsLeft = Math.max(0, lic.trialCommentsLimit - used);
}
sendResponse({ ok: true, stats: { total: s.total, today: s.today, week: s.week }, trialCommentsLeft: trialCommentsLeft });
})();
return true;
}