155 lines
4.8 KiB
JavaScript
155 lines
4.8 KiB
JavaScript
// ==UserScript==
|
||
// @name 平顶山学院(青书学堂)自动学习脚本
|
||
// @namespace http://tampermonkey.net/
|
||
// @version 2026-06-03
|
||
// @description try to take over the world!
|
||
// @author You
|
||
// @match https://degree.qingshuxuetang.com/pdsu/Student/Course/CourseStudy*
|
||
// @match https://degree.qingshuxuetang.com/pdsu/Student/Course/CourseShow*
|
||
// @icon https://www.google.com/s2/favicons?sz=64&domain=qingshuxuetang.com
|
||
// @grant none
|
||
// ==/UserScript==
|
||
|
||
(function () {
|
||
"use strict";
|
||
|
||
const url = window.location.href;
|
||
const MIN_STUDY_SECONDS = 5 * 60;
|
||
const COURSEWARE_DETECT_TIMEOUT_SECONDS = 60;
|
||
const TEXT_COURSEWARE_SELECTOR = "#easyXDM_default2872_provider";
|
||
console.log("插件加载完成,等待界面渲染");
|
||
|
||
const parseStudySeconds = (text) => {
|
||
const hourMatch = text.match(/(\d+)\s*小时/);
|
||
const minuteMatch = text.match(/(\d+)\s*分钟/);
|
||
const secondMatch = text.match(/(\d+)\s*秒/);
|
||
|
||
return (
|
||
(hourMatch ? Number(hourMatch[1]) * 3600 : 0) +
|
||
(minuteMatch ? Number(minuteMatch[1]) * 60 : 0) +
|
||
(secondMatch ? Number(secondMatch[1]) : 0)
|
||
);
|
||
};
|
||
|
||
const shouldEnterCourseware = (item) => {
|
||
const mark = item.querySelector(".study_being");
|
||
|
||
if (!mark) {
|
||
return true;
|
||
}
|
||
|
||
const studiedSeconds = parseStudySeconds(mark.innerText);
|
||
return studiedSeconds < MIN_STUDY_SECONDS;
|
||
};
|
||
|
||
const returnToStudyPage = () => {
|
||
const backLink = document.querySelector(".back-link");
|
||
|
||
if (backLink) {
|
||
backLink.click();
|
||
return;
|
||
}
|
||
|
||
history.back();
|
||
};
|
||
|
||
const onPageLoad = () => {
|
||
console.log("页面加载完成,开始执行脚本");
|
||
|
||
if (url.includes("CourseStudy")) {
|
||
console.log("进入准备阶段");
|
||
// 等待3秒后点击下一个未播放的视频
|
||
setTimeout(() => {
|
||
// 准备阶段
|
||
const list = document.querySelector("#list");
|
||
if (!list) {
|
||
console.error("课程列表未找到,结束脚本");
|
||
return;
|
||
}
|
||
const items = list.querySelectorAll("li > a.node");
|
||
console.log("获取到课程数量:", items.length);
|
||
|
||
if (items.length === 0) {
|
||
console.error("课程数量为空,结束脚本");
|
||
return;
|
||
}
|
||
for (const item of items) {
|
||
if (shouldEnterCourseware(item)) {
|
||
const mark = item.querySelector(".study_being");
|
||
const studiedSeconds = mark ? parseStudySeconds(mark.innerText) : 0;
|
||
console.log(
|
||
"点击未完成学习时长的视频:" +
|
||
item.querySelector(".title").innerText +
|
||
",已学习:" +
|
||
studiedSeconds +
|
||
"秒"
|
||
);
|
||
item.click();
|
||
return;
|
||
}
|
||
}
|
||
console.log("所有视频均已播放完毕,结束脚本");
|
||
}, 3000);
|
||
} else if (url.includes("CourseShow")) {
|
||
console.log("进入学习阶段");
|
||
// 学习阶段
|
||
const showPageStartedAt = Date.now();
|
||
const videoInterval = setInterval(() => {
|
||
const video = document.querySelector("#vjs_video_3_html5_api");
|
||
|
||
if (!video) {
|
||
const textCourseware = document.querySelector(TEXT_COURSEWARE_SELECTOR);
|
||
|
||
if (textCourseware) {
|
||
console.log("检测到文本课件,等待5分钟后返回准备页面");
|
||
clearInterval(videoInterval);
|
||
setTimeout(() => {
|
||
console.log("文本课件等待完成,返回准备页面");
|
||
returnToStudyPage();
|
||
}, MIN_STUDY_SECONDS * 1000);
|
||
return;
|
||
}
|
||
|
||
if (
|
||
Date.now() - showPageStartedAt >
|
||
COURSEWARE_DETECT_TIMEOUT_SECONDS * 1000
|
||
) {
|
||
console.error("视频和文本课件元素均未找到,结束脚本");
|
||
clearInterval(videoInterval);
|
||
return;
|
||
}
|
||
|
||
console.log("课件元素尚未渲染完成,继续等待");
|
||
return;
|
||
}
|
||
|
||
if (video.paused && video.currentTime === 0) {
|
||
video.play();
|
||
console.log("视频未播放,开始播放视频");
|
||
return;
|
||
}
|
||
|
||
if (video.currentTime >= video.duration - 1) {
|
||
console.log("视频播放结束,返回准备页面");
|
||
clearInterval(videoInterval);
|
||
returnToStudyPage();
|
||
}
|
||
|
||
if (video.playbackRate === 1) {
|
||
console.log("将视频倍速设置为2倍速");
|
||
video.playbackRate = 2;
|
||
}
|
||
|
||
console.log("视频正在播放,当前时间:" + video.currentTime);
|
||
}, 3000);
|
||
}
|
||
};
|
||
|
||
// 等待页面加载完成后执行
|
||
if (document.readyState === "complete") {
|
||
onPageLoad();
|
||
} else {
|
||
window.addEventListener("load", onPageLoad);
|
||
}
|
||
})();
|