diff --git a/content.js b/content.js index 04c92c6..07ce1a7 100644 --- a/content.js +++ b/content.js @@ -879,6 +879,29 @@ // 所以默认间隔 2~4 分钟、每视频最多 3 人、同一 mid 永不重复 const DM_GAP_MIN = 2 * 60 * 1000, DM_GAP_MAX = 4 * 60 * 1000; + // 私信内容:优先用面板「私信内容」框(每行一条随机取); + // 留空则复用本次评论内容(与界面「留空则复用上方评论内容」一致),再不行才用模板 + function pickDmText(cfg, video, commentText) { + const raw = String(cfg.dmText || "").split("\n").map(s => s.trim()).filter(Boolean); + if (raw.length) { + const valid = [], bad = []; + for (const line of raw) { + const v = verifyMessage(line); + if (v.ok) valid.push(v.text); else bad.push(line + "(" + v.reason + ")"); + } + if (bad.length) step("⚠ " + bad.length + " 行私信内容不合规不会使用:" + bad.join(";"), "fail"); + if (!valid.length) { + step("❌ 私信内容全部不合规(每行需3~200字、不含外链、不能全是重复字),已改用评论模板", "fail"); + } else { + return { text: valid[Math.floor(Math.random() * valid.length)], source: "私信自定义" }; + } + } + if (commentText && verifyMessage(commentText).ok) { + return { text: String(commentText).trim(), source: "复用评论" }; + } + return { text: pickTemplate(video.title, cfg.keyword), source: "模板" }; + } + async function runDmStep(task, video) { const cfg = task.config; const limit = Math.max(1, Math.min(5, Number(cfg.dmCount) || 1)); @@ -894,10 +917,11 @@ for (let i = 0; i < targets.length; i++) { if (stopRequested()) { step("已手动停止,私信中断", "fail"); return; } const t = targets[i]; - const text = video.dmText || pickTemplate(video.title, cfg.keyword); + const dm = pickDmText(cfg, video, text); + const text = dm.text; const v = verifyMessage(text); if (!v.ok) { step("❌ 私信内容不合规:" + v.reason, "fail"); return; } - step("私信 @" + t.name + "(" + (i + 1) + "/" + targets.length + "):" + text.slice(0, 24) + (text.length > 24 ? "…" : "")); + step("私信[" + dm.source + "] @" + t.name + "(" + (i + 1) + "/" + targets.length + "):" + text.slice(0, 24) + (text.length > 24 ? "…" : "")); const res = await sendDm(t.mid, text); if (res.code === 0) { task.dmSent = (task.dmSent || 0) + 1; diff --git a/manifest.json b/manifest.json index 6793cbe..6b94030 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "B站评论助手", - "version": "1.7.0", + "version": "1.7.1", "description": "B站网页版关键词评论助手:按搜索关键词找视频,默认模拟真人(打开视频页、滚到评论区、逐字输入、点发布),也可快速API直发;支持下载当前页视频;带防重复记录、可中断执行与页面实时进度浮层。", "permissions": ["storage", "tabs", "scripting", "sidePanel", "downloads", "declarativeNetRequest"], "host_permissions": [