feat: 评论间隔随机化 v1.7.6
- 每条评论之间在设定范围内随机等待(默认1~2分钟,可自定义,支持小数) - 进度条实时倒计时显示剩余秒数,可随时停止 - 填0则不等待
This commit is contained in:
1 parent
8193e6c0c5
commit
2e97e62210
7 files changed
+179
-8
No files matched your search
+48
-2
@@ -896,8 +896,8 @@ class XHSNoteSaver {
|
||||
|
||||
console.log(`已点击第 ${totalClicked} 个笔记`);
|
||||
|
||||
// 等待内容展开,增加等待时间
|
||||
await this.sleep(2000);
|
||||
// 评论间隔:在设定范围内随机等待(如1~2分钟),模拟真人节奏
|
||||
await this.randomCommentDelay();
|
||||
|
||||
} catch (error) {
|
||||
console.error('点击笔记失败:', error);
|
||||
@@ -1501,6 +1501,52 @@ class XHSNoteSaver {
|
||||
});
|
||||
}
|
||||
|
||||
// 评论间隔:最小~最大分钟之间随机等待,进度条实时倒计时
|
||||
async randomCommentDelay() {
|
||||
let min = 1;
|
||||
let max = 2;
|
||||
try {
|
||||
const result = await chrome.storage.local.get(['commentDelayMin', 'commentDelayMax']);
|
||||
const parsedMin = Number(result.commentDelayMin);
|
||||
const parsedMax = Number(result.commentDelayMax);
|
||||
if (Number.isFinite(parsedMin) && parsedMin >= 0) min = parsedMin;
|
||||
if (Number.isFinite(parsedMax) && parsedMax >= 0) max = parsedMax;
|
||||
} catch (error) {
|
||||
console.log('读取评论间隔失败,使用默认 1~2 分钟:', error);
|
||||
}
|
||||
|
||||
if (max < min) [min, max] = [max, min];
|
||||
|
||||
// 都是0则不等待
|
||||
if (min === 0 && max === 0) return;
|
||||
|
||||
const totalSec = Math.round((min + Math.random() * (max - min)) * 60);
|
||||
console.log(`评论间隔:随机等待 ${totalSec} 秒(范围 ${min}~${max} 分钟)`);
|
||||
|
||||
// 进度条提示实时倒计时
|
||||
const tip = document.querySelector('.xhs-progress-tip');
|
||||
let remain = totalSec;
|
||||
const renderTip = () => {
|
||||
if (tip) {
|
||||
tip.textContent = remain > 0
|
||||
? `⏳ 评论间隔:随机等待 ${remain} 秒后继续下一篇…`
|
||||
: '💡 长按评论模式按钮可管理自定义评论';
|
||||
}
|
||||
};
|
||||
renderTip();
|
||||
const countdownTimer = setInterval(() => {
|
||||
remain--;
|
||||
renderTip();
|
||||
}, 1000);
|
||||
this.cleanupTimers.add(countdownTimer);
|
||||
|
||||
await this.sleep(totalSec * 1000);
|
||||
|
||||
clearInterval(countdownTimer);
|
||||
this.cleanupTimers.delete(countdownTimer);
|
||||
renderTip();
|
||||
}
|
||||
|
||||
// 阻止笔记元素内的所有链接跳转
|
||||
preventLinkNavigation(noteElement) {
|
||||
const links = noteElement.querySelectorAll('a');
|
||||
|
||||
Reference in new issue
Block a user