小脏i学习-全自动学习脚本

智慧通用里面的小通i学习,加载脚本将自动学习,进入视频列表开始任务。

// ==UserScript==
// @name 小脏i学习-全自动学习脚本
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 智慧通用里面的小通i学习,加载脚本将自动学习,进入视频列表开始任务。
// @author xiaozang
// @match https://education.gt.cn/*
// @grant none
// ==/UserScript==

(function() {
 'use strict';

 // 存储当前正在学习的视频元素,用于后续操作
 let currentLearningVideoItem = null;
 let logTextarea = null; // 用于存储编辑框的引用
 // 定义播放倍速
 const playbackRate = 3;

 // 自定义日志函数,将信息输出到编辑框
 function customLog(message) {
  if (logTextarea) {
   const now = new Date();
   const timeString = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`;
   logTextarea.value += `[${timeString}] ${message}\n`;
   // 自动滚动到底部
   logTextarea.scrollTop = logTextarea.scrollHeight;
  }
  console.log(message); // 同时保留控制台输出,方便调试
 }

 // 重写 alert 函数,将其内容也输出到编辑框
 window.alert = function(message) {
  customLog(`提示信息: ${message}`);
 };

 // 确保视频持续播放并设置倍速的函数
 function autoPlayVideo() {
  const videoElement = document.querySelector('video');
  if (videoElement) {
   // 检查并设置视频倍速
   if (videoElement.playbackRate !== playbackRate) {
    videoElement.playbackRate = playbackRate;
    customLog(`已将视频播放速度设置为 ${playbackRate} 倍。`);
   }

   // 确保视频持续播放
   if (videoElement.paused) {
    customLog('检测到视频已暂停,正在尝试恢复播放。');
    videoElement.play().catch(error => {
     customLog('自动播放失败,原因:' + error);
    });
   }
  }
 }

 // 每5秒检查一次视频状态,以确保它不会暂停或倍速被重置
 setInterval(autoPlayVideo, 5000);

 // 查找并点击下一个待学视频
 function clickNextVideo() {
  const videoItems = document.querySelectorAll('.el-col-video-play.el-col.el-col-8');
  let targetVideo = null;

  for (const item of videoItems) {
   const statusLabel = item.querySelector('.videoStudyingProgressLabel');
   if (statusLabel && statusLabel.textContent.includes('%')) {
    targetVideo = item;
    customLog('找到一个已经有进度的视频,准备学习。');
    break;
   }
  }

  if (!targetVideo) {
   for (const item of videoItems) {
    const statusLabel = item.querySelector('.videoProgressLabel');
    if (statusLabel && statusLabel.textContent.includes('待学')) {
     targetVideo = item;
     customLog('未找到有进度的视频,找到一个待学视频。');
     break;
    }
   }
  }

  if (targetVideo) {
   const videoCard = targetVideo.querySelector('.el-card');
   if (videoCard) {
    videoCard.click();
    customLog('已学习一个待学或有进度的视频。');
    currentLearningVideoItem = targetVideo;
    waitForVideoCompletion(currentLearningVideoItem);
   }
  } else {
   customLog('所有视频均已完成,或没有找到待学视频。');
   window.alert('所有视频均已完成,脚本已停止。'); // 调用重写过的alert
  }
 }

 // 使用 MutationObserver 等待视频状态更新为“已学”
 function waitForVideoCompletion(videoItem) {
  if (window.observer) {
   window.observer.disconnect();
  }

  const observer = new MutationObserver((mutations) => {
   mutations.forEach(() => {
    const newStatusLabel = videoItem.querySelector('.videoStudyedProgressLabel');
    if (newStatusLabel && newStatusLabel.textContent.includes('已学')) {
     customLog('视频状态已变更为“已学”。');
     observer.disconnect();

     setTimeout(() => {
      customLog('延迟3秒,正在暂停当前视频并寻找下一个。');

      const videoElement = document.querySelector('video');
      if (videoElement) {
       videoElement.pause();
       customLog('当前视频已暂停。');
      }
      customLog('正在重新寻找下一个视频...');
      clickNextVideo();
     }, 3000);
    }
   });
  });

  const config = { subtree: true, childList: true, attributes: true };
  observer.observe(document.body, config);
  window.observer = observer;
 }

 // 底部添加只读编辑框并初始化日志功能
 function addEditorBox() {
  const targetElement = document.querySelector('div[data-v-5a36d7d2].video-box-content');

  if (targetElement) {
   const editorContainer = document.createElement('div');
   editorContainer.style.marginTop = '10px';
   editorContainer.style.paddingLeft = '5px';
   editorContainer.style.paddingRight = '5px';

   const textarea = document.createElement('textarea');
   textarea.style.width = '100%';
   textarea.style.height = '200px'; // 适当增加高度以容纳更多日志
   textarea.style.boxSizing = 'border-box';
   textarea.style.border = '1px solid #ccc';
   textarea.style.padding = '5px';
   textarea.placeholder = '日志信息将显示在这里...';
   textarea.readOnly = true; // 设置为只读编辑框

   editorContainer.appendChild(textarea);
   targetElement.parentNode.insertBefore(editorContainer, targetElement.nextSibling);

   // 将引用存储在全局变量中
   logTextarea = textarea;
   customLog('欢迎使用由xiaozang开发的小脏i学习脚本。');
   customLog('Hook页面成功,脚本日志功能已启动。');
   customLog('正在等待视频列表加载...');
  }
 }

 // 使用 MutationObserver 监听 DOM 变化,确保在页面动态加载时也能执行
 const mainObserver = new MutationObserver((mutationsList, observer) => {
  // 判断页面是否已经加载了视频列表
  if (document.querySelector('.el-col-video-play')) {
   addEditorBox(); // 先添加编辑框
   setTimeout(clickNextVideo, 3000); // 然后开始自动学习
   observer.disconnect(); // 找到并添加后停止观察
  }
 });

 mainObserver.observe(document.body, { childList: true, subtree: true });

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址