Greasy Fork is available in English.

国家中小学智慧教育平台刷课脚本(16倍速,自动答题,自动切换列表中的视频,后台播放,学时不更新的解决方法看下面)

16倍速,自动答题,自动切换列表中的视频,后台播放,学时不更新的解决方法看下面

ของเมื่อวันที่ 15-01-2023 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name         国家中小学智慧教育平台刷课脚本(16倍速,自动答题,自动切换列表中的视频,后台播放,学时不更新的解决方法看下面)
// @namespace    http://tampermonkey.net/
// @version      2.2
// @license      CC BY-NC-SA
// @description  16倍速,自动答题,自动切换列表中的视频,后台播放,学时不更新的解决方法看下面
// @author       HGGshiwo
// @match        https://*.zxx.edu.cn/teacherTraining/courseDetail*
// @match        https://basic.smartedu.cn/teacherTraining/courseDetail*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
  ("use strict");
  const xljkUrlList = [
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=52437a43-1e09-43cf-b7af-2beb4f96baca&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=9ca7b73a-9386-4b58-9cf9-4e452b86b47f&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=ea4a8bdb-6819-47af-bfc2-233933bb5049&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=1238d399-6ea6-4d5c-b010-4d469b3f9d2c&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=2f22d9c1-2510-4db1-81e2-152e94f45b00&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=f97c5ef3-4163-4551-bbe6-c2282de8002e&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=03ce293f-ce99-4905-8088-62d3efd1415f&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=9c50d48e-b997-4371-bfde-c9ef9da36006&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=b13aa14e-29e0-48fd-be51-aa32f343095a&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=98b8ea15-c39c-4ab0-9c90-89cc16ea345e&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=0b8c7836-3b5a-47f9-b6f2-6a57d9208148&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=c0234602-7ba1-4c9f-b409-39d15732a1d2&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=25928aa1-3029-4442-814a-2e73123e409c&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
    "https://www.zxx.edu.cn/teacherTraining/courseDetail?courseId=64f2dcad-6020-4be6-a150-eb3bfa9d0de8&tag=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD&channelId=&libraryId=bb042e69-9a11-49a1-af22-0c3fab2e92b9&breadcrumb=%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD",
  ];
  const xljkUrlTag =
    "%E5%BF%83%E7%90%86%E5%81%A5%E5%BA%B7%E6%95%99%E8%82%B2%E6%95%99%E5%B8%88%E5%9F%B9%E8%AE%AD";
  // function
  const sleep = async (time) => {
    var p = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve();
      }, time);
    });
    return p;
  };

  const waitLoading = async () => {
    var resItems = document.getElementsByClassName("resource-item");
    var video = document.getElementsByTagName("video");
    if (resItems.length === 0 || video.length === 0) {
      console.log(666, "视频没有加载完成,等待1s");
      await sleep(1000);
      return waitLoading();
    } else {
      return sleep(1000);
    }
  };

  const getActiveVideoAndPlay = async () => {
    //获取当前的页面活跃的视频并且播放
    await waitLoading();
    //获取当前视频位置
    var groups = document.getElementsByClassName("fish-collapse-item");
    var groupNo = [...groups].findIndex((item) => {
      return item.className.includes("active");
    });
    var base = groupNo === -1 ? document : groups[groupNo];
    var resItems = base.getElementsByClassName("resource-item");
    var resNo = [...resItems].findIndex((item) => {
      return item.className.includes("active");
    });

    //计算下一个视频的位置
    const toNextVideo = async () => {
      if (resNo + 1 == resItems.length) {
        //看完了当前组
        if (groupNo + 1 == groups.length) {
          var urlList = [];
          //是心理健康教育培训
          if (location.href.includes(xljkUrlTag)) {
            urlList = [...xljkUrlList];
          }
          var curUrl = urlList.indexOf(location.href);
          if (curUrl + 1 == urlList.length) {
            console.log(666, "看完了所有学习页面,退出");
          } else if (curUrl != -1) {
            console.log(666, "进入下一个学习页面");
            window.open(urlList[curUrl + 1], "_self");
          }
        } else {
          //观看下一组
          console.log(666, `点击下一组的第一个视频`);
          document
            .getElementsByClassName("fish-collapse-header")
            [groupNo + 1].click();
          await sleep(1000);
          resItems =
            groups[groupNo + 1].getElementsByClassName("resource-item");
          resItems[0].click();
          getActiveVideoAndPlay();
        }
      } else {
        //观看当前组的下一个视频
        resItems[resNo + 1].click();
        console.log(666, `点击当前组的下一个视频`);
        getActiveVideoAndPlay();
      }
    };

    //保证看完的不再看
    const iconClassName = "iconfont icon_checkbox_linear";
    let title = resItems[resNo].getElementsByClassName(iconClassName).title;
    if (title !== "未开始") {
      console.log(666, "该视频已经观看")
      await toNextVideo();
      return;
    }

    console.log(666, `开始观看: 第${resNo + 1}个视频,第${groupNo + 1}组`);
    try {
      var video = document.getElementsByTagName("video")[0];
      video.muted = true;
      video.play().catch((err) => {
        console.log(666, err);
        location.reload(); //视频播放出错,刷新页面
      });
      video.playbackRate = 16;
      video.addEventListener(
        "ended",
        async () => {
          await sleep(1000);
          //计算下一个视频的位置
          toNextVideo();
        },
        false
      );
      video.addEventListener("pause", async () => {
        //因为页面隐藏而暂停,则直接播放
        if (document.hidden) {
          video.play().catch((err) => {
            console.log(666, err); //视频播放出错,刷新页面
            location.reload();
          });
          return;
        }
      });
    } catch (e) {
      console.log(666, e);
      getActiveVideoAndPlay(); //获取不到视频,再次调用
    }
  };

  const setPageHandler = () => {
    //点击页面的题目和弹窗
    setInterval(() => {
      var options = document.getElementsByClassName("nqti-option");
      if (options.length) {
        options[0].click();
      }
      var btnWapper = document.getElementsByClassName(
        "index-module_markerExercise_KM5bU"
      );
      if (btnWapper.length) {
        var btns = btnWapper[0].getElementsByClassName("fish-btn");
        if (btns.length) {
          btns[0].click();
        }
      }
      var confirmBtns = document.getElementsByClassName(
        "fish-modal-confirm-btns"
      );
      if (confirmBtns.length) {
        confirmBtns[0].getElementsByClassName("fish-btn")[0].click();
      }
    }, 1000);
  };

  //下面开始运行脚本
  setPageHandler();
  getActiveVideoAndPlay();
})();