教师研修-yanxiu.com
// ==UserScript==
// @name 教师研修-yanxiu.com
// @namespace http://tampermonkey.net/
// @version 2024-07-24.3
// @description 教师研修网2024
// @author f_cat
// @match https://ipx.yanxiu.com/train2/workspace/*
// @match https://ipx.yanxiu.com/grain/course/*
// @icon https://srt-read-online.3ren.cn/basebusiness/headimg/20200711/1594463211851X00rZyPRV8-23.png
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
/* ==UserConfig==
设置:
config:
title: 静音挂课
description: 挂课时保持静音
type: checkbox
default: true
==/UserConfig== */
(function () {
'use strict';
// Your code here...
function wait(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Done waiting");
resolve(ms)
}, ms)
})
}
function getTraining() {
return new Promise((resolve) => {
let getT = setInterval(() => {
let trainings = document.querySelectorAll('.training-pack.web');
if (trainings.length > 0) {
clearInterval(getT);
resolve(trainings);
}
});
})
}
function getCourse(training) {
return new Promise((resolve) => {
let getC = setInterval(() => {
let courses = training.querySelectorAll('.course-item');
if (courses.length > 0) {
clearInterval(getC);
resolve(courses);
}
});
})
}
async function waitForEnd() {
return new Promise(async (resolve) => {
while (GM_getValue('studing')) {
await wait(3000);
}
resolve('done');
});
}
async function learnCourse(course) {
return new Promise(async (resolve) => {
if (course.querySelector('.learn-status') == undefined || course.querySelector('.learn-status > span').innerText != '已观看 100%') {
console.log('开始学习');
course.click();
await waitForEnd();
console.log('结束学习');
resolve('done');
}
else {
console.log('已学过');
resolve('done');
}
});
}
async function gotoTraining(item) {
if (item.querySelector('.pack-tool-content').style.display == 'none') {
item.querySelector('.pack-info').click();
await wait(300);
console.log('展开');
}
let courses = await getCourse(item);
console.log('共找到 ' + courses.length + '节课');
for (var i = 0; i < courses.length; i++) {
GM_setValue('studing', true)
await learnCourse(courses[i]);
}
}
async function contentsPage() {
console.log('课程学习页面');
let trainings = await getTraining();
console.log('共找到 ' + trainings.length + '个模块')
for (let i = 0; i < trainings.length; i++) {
var isLastPage = false;
while (!isLastPage) {
await gotoTraining(trainings[i]);
if (document.querySelector('.btn-next.is-last[aria-disabled="false"]') != undefined) {
document.querySelector('.btn-next.is-last[aria-disabled="false"]').click();
console.log('下一页');
await wait(3000);
trainings = await getTraining();
} else {
isLastPage = true;
console.log('最后一页');
}
}
}
}
async function getResourse() {
return new Promise((resolve) => {
let getR = setInterval(() => {
let resourses = document.querySelectorAll('.res-item');
if (resourses.length > 0) {
clearInterval(getR);
resolve(resourses);
}
});
})
}
function setMute() {
let mu = setInterval(() => {
if (document.querySelector("video") != undefined) {
document.querySelector("video").muted = true;
}
}, 100)
}
async function readResourse() {
console.log('开始阅读');
if (GM_getValue('设置.config')) {
document.querySelector("video").muted = true;
}
return new Promise((resolve) => {
let study = setInterval(function () {
if (document.querySelector('.action-timer').querySelector('span').innerText.substr(0, 4) == '您已完成') {
clearInterval(study);
console.log('结束阅读');
resolve('done');
return;
}
if (document.querySelector('.vcp-playtoggle').style.backgroundImage != undefined) {
if (document.querySelector('.scoring-wrapper').style.display != 'none') {
var event = new Event("mousemove");
document.querySelectorAll('.scoring-wrapper .rate-item')[4].dispatchEvent(event);
document.querySelectorAll('.scoring-wrapper .rate-item')[4].click();
document.querySelector('.ivu-btn.ivu-btn-primary').click();
console.log('完成评分,继续播放');
return;
}
if (document.querySelector('.ended-mask').style.display != 'none') {
clearInterval(study);
console.log('结束阅读');
resolve('done');
return;
}
if (document.querySelector('.alarmClock-wrapper').style.display != 'none') {
document.querySelector('.alarmClock-wrapper').click();
console.log('继续播放');
return;
}
if (document.querySelector('.vcp-player.vcp-playing') == undefined) {
const player = document.querySelector('video').click();
document.querySelector('.vcp-bigplay').click();
console.log('开始播放');
return;
}
}
}, 3000);
});
}
async function coursePage() {
console.log('课程学习页面');
if (GM_getValue('设置.config')) {
setMute();
}
let resourse = await getResourse();
console.log('共找到 ' + resourse.length + '个资源')
console.log('开始学习');
if (document.querySelector('.action-timer').querySelector('span').innerText.substr(0, 4) != '您已完成') {
for (let i = 0; i < resourse.length; i++) {
resourse[i].querySelector('p').click();
await wait(3000);
if (resourse[i].querySelector('.icon-media')) {
//媒体资源
console.log('媒体资源');
await readResourse();
} else {
//文档资源
console.log('文档资源');
await wait(3000);
}
if (document.querySelector('.action-timer').querySelector('span').innerText.substr(0, 4) == '您已完成') {
break;
}
}
console.log('结束学习');
GM_setValue('studing', false);
window.close();
}
}
if ('https://ipx.yanxiu.com/train2/' == window.location.href.substr(0, 30)) {
contentsPage();
} else if ('https://ipx.yanxiu.com/grain/' == window.location.href.substr(0, 29)) {
coursePage();
}
})();