菜单

Administrator
发布于 2025-06-03 / 14 阅读
0
0

一个自动刷阅读量的控制台小代码

1、效果和场景

rt,通常对于某些论坛,可能会有一些阅读要求,比如需要阅读量大于多少。

这个代码的作用就是会自动向下滑动页面,模拟鼠标向下滚动。

并且会自动触发翻页动作

2、代码

// 带有定时暂停功能的智能滚动
function smartScrollWithPauses() {
  const viewportHeight = window.innerHeight;
  let documentHeight = Math.max(
    document.body.scrollHeight,
    document.documentElement.scrollHeight
  );
  let currentPosition = window.pageYOffset || document.documentElement.scrollTop;
  const smallStep = 10;
  const smallStepInterval = 10000 / (viewportHeight / smallStep);
  let bottomDetectionCount = 0;
  const maxBottomDetections = 3;
  let lastDocumentHeight = documentHeight;
  let noNewContentCount = 0;
  const maxNoNewContent = 5;
  let isTabActive = !document.hidden;
  let isPaused = false;
  
  // 滚动计时器
  let scrollTimer = 0;
  // 3-5分钟后暂停(转为毫秒)
  const scrollDuration = (3 * 60 + Math.floor(Math.random() * 2 * 60)) * 1000;
  // 暂停1分钟(毫秒)
  const pauseDuration = 60 * 1000;
  
  console.log(`开始智能滚动,视窗高度: ${viewportHeight}px, 文档总高度: ${documentHeight}px`);
  console.log(`将在 ${Math.round(scrollDuration/1000/60)} 分钟后暂停 ${pauseDuration/1000/60} 分钟`);
  
  // 监听页面可见性变化
  document.addEventListener('visibilitychange', () => {
    isTabActive = !document.hidden;
    console.log(`页面可见性变化: ${isTabActive ? '前台' : '后台'}`);
  });
  
  // 定时暂停和恢复功能
  function managePauses() {
    scrollTimer += 1000;
    
    // 检查是否需要暂停
    if (scrollTimer >= scrollDuration && !isPaused) {
      isPaused = true;
      console.log(`已滚动 ${Math.round(scrollTimer/1000/60)} 分钟,开始暂停 ${pauseDuration/1000/60} 分钟`);
      
      // 设置定时器,暂停后恢复
      setTimeout(() => {
        isPaused = false;
        scrollTimer = 0;
        console.log('暂停结束,继续滚动');
        
        // 计算新的滚动持续时间(3-5分钟)
        const newScrollDuration = (3 * 60 + Math.floor(Math.random() * 2 * 60)) * 1000;
        console.log(`将在 ${Math.round(newScrollDuration/1000/60)} 分钟后再次暂停`);
      }, pauseDuration);
    }
    
    // 每秒检查一次
    setTimeout(managePauses, 1000);
  }
  
  function scrollStep() {
    // 如果页面在后台或处于暂停状态,等待条件恢复再继续
    if (!isTabActive || isPaused) {
      const reason = !isTabActive ? '页面在后台' : '处于计划暂停';
      console.log(`暂停滚动: ${reason}`);
      setTimeout(scrollStep, 1000);
      return;
    }
    
    documentHeight = Math.max(
      document.body.scrollHeight,
      document.documentElement.scrollHeight
    );
    
    if (currentPosition + viewportHeight >= documentHeight - 50) {
      bottomDetectionCount++;
      console.log(`到达底部 ${bottomDetectionCount}/${maxBottomDetections}`);
      
      if (bottomDetectionCount >= maxBottomDetections) {
        console.log('尝试触发加载更多内容...');
        
        // 多次滚动到底部,增加触发加载的几率
        for (let i = 0; i < 3; i++) {
          setTimeout(() => {
            window.scrollTo(0, documentHeight + 100);
          }, i * 300);
        }
        
        setTimeout(() => {
          const newDocumentHeight = Math.max(
            document.body.scrollHeight,
            document.documentElement.scrollHeight
          );
          
          if (newDocumentHeight > documentHeight) {
            console.log(`检测到新内容加载,高度从 ${documentHeight}px 增加到 ${newDocumentHeight}px`);
            bottomDetectionCount = 0;
            noNewContentCount = 0;
            lastDocumentHeight = newDocumentHeight;
            scrollStep();
          } else {
            noNewContentCount++;
            console.log(`没有检测到新内容 ${noNewContentCount}/${maxNoNewContent}`);
            
            if (noNewContentCount >= maxNoNewContent) {
              console.log('已确认没有更多内容可加载,停止滚动');
              return;
            }
            
            bottomDetectionCount = 0;
            scrollStep();
          }
        }, 2000);
        
        return;
      }
    } else {
      bottomDetectionCount = 0;
    }
    
    currentPosition += smallStep;
    window.scrollTo(0, currentPosition);
    
    const randomDelay = smallStepInterval * (0.8 + Math.random() * 0.4);
    setTimeout(scrollStep, randomDelay);
  }
  
  // 启动暂停管理
  managePauses();
  // 启动滚动
  scrollStep();
}

// 启动带有定时暂停功能的智能滚动
smartScrollWithPauses();

3、用法

复制代码,到控制台。即可运行

ps:不建议后台运行,建议放在前台。然后去吃饭吧

由于某些论坛会有限速策略,可以自行修改一些速度控制

比如上述的10000 是指下滑速度。


评论