说明
复制到油猴里使用,然后打开课程列表界面即可,自动选课,自动下一集,课程学完自动换下一课
// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url] 安徽干部教育在线刷课脚本2.0
// [url=home.php?mod=space&uid=467642]@namespace[/url] [url=http://tampermonkey.net/]http://tampermonkey.net/[/url]
// [url=home.php?mod=space&uid=1248337]@version[/url] 2025-05-27
// @description 自动浏览和选择课程章节,自动播放视频,通过页面显示的课程时间,来延迟执行完成函数
// [url=home.php?mod=space&uid=686208]@AuThor[/url] You
// [url=home.php?mod=space&uid=195849]@match[/url] [url=https://www.ahgbjy.gov.cn/]https://www.ahgbjy.gov.cn/[/url]*
// [url=home.php?mod=space&uid=593100]@Icon[/url] [url=https://www.ahgbjy.gov.cn//commons/img/index/favicon.ico]https://www.ahgbjy.gov.cn//commons/img/index/favicon.ico[/url]
// [url=home.php?mod=space&uid=609072]@grant[/url] GM_setValue
// @grant GM_getValue
// @run-at document-start
// @downloadURL [url=https://update.greasyfork.cc/scripts/490300/%E5%AE%89%E5%BE%BD%E5%B9%B2%E9%83%A8%E6%95%99%E8%82%B2%E5%9C%A8%E7%BA%BF%E5%88%B7%E8%AF%BE%E8%84%9A%E6%9C%AC10.user.js]https://update.greasyfork.cc/scr ... %E6%9C%AC10.user.js[/url]
// @updateURL [url=https://update.greasyfork.cc/scripts/490300/%E5%AE%89%E5%BE%BD%E5%B9%B2%E9%83%A8%E6%95%99%E8%82%B2%E5%9C%A8%E7%BA%BF%E5%88%B7%E8%AF%BE%E8%84%9A%E6%9C%AC10.meta.js]https://update.greasyfork.cc/scr ... %E6%9C%AC10.meta.js[/url]
// ==/UserScript==
//屏蔽弹窗
(function () {
'use strict';
// 重写 window.alert 方法以阻止警告窗口显示
unsafeWindow.alert = function() {
console.log('警告窗口被屏蔽了!原始消息: ' );
};
// 重写 window.confirm 方法以阻止确认对话框显示
unsafeWindow.confirm = function() {
console.log('确认对话框被屏蔽了!原始消息: ' );
// 默认情况下,confirm返回false
return false;
};
// 重写 window.prompt 方法以阻止提示输入框显示
unsafeWindow.prompt = function() {
console.log('提示输入框被屏蔽了!原始消息: ' );
// 默认情况下,prompt返回空字符串
return '';
};
var currentURL = window.location.href;
// 选课页面
function xuanke() {
//判断当前页课程是否全部学完,如果学完点击下页,否则进入未学习的课程
var xxstat = document.getElementsByClassName("coursespan")
//如果最后一个节点也学完了,则全部完成,跳转下页
if (xxstat[xxstat.length-1].lastChild.innerHTML == "已完成"){
var NextPage= "https://www.ahgbjy.gov.cn/"+document.getElementsByClassName("pagination")[0].lastChild.previousSibling.previousSibling.firstChild.getAttribute("href");
window.location.href = NextPage;
//否则,找到第一个未学完的页面,点击开始学习
}else{
for(var n=0;n<xxstat.length;n++){
if (xxstat[n].lastChild.innerHTML!="已完成"){
xxstat[n].click();
break;
}
}
}
}
// 课程详情页
function xiangqing() {
var j = GM_getValue('jj');
var kewc = document.getElementsByClassName("col-md-2")
//判断课程是否全部完成,如果完成跳转至首页,否则点击开始学习
if (kewc[kewc.length-1].getElementsByTagName("span")[0].innerHTML == 100)
{
window.open("https://www.ahgbjy.gov.cn/pc/course/courselist.do?categoryid=&year=&coutype=0&mostNInput=0&mostHInput=0&mostTJInput=&keyword=", "_blank");
}else{
//点击开始学习
var xx = document.getElementsByClassName("btn btn-default startlearn");
xx[0].click();
}
}
// 视频课程
function StarAndExit() {
//视频课程
var a = document.getElementsByClassName("jp-duration");
//获取课程的时间+1分钟
var TimeN = parseInt(a[0].innerHTML.substring(1,3),10)+1;
var b= document.getElementById("coursenametitle");
var c = TimeN;
b.innerHTML=" 脚本已执行,将在"+c+"分钟后自动点击完成";
function updateTime(){
b.innerHTML=" 脚本将在"+c+"分钟后自动点击完成";
c=c-1;
}
setInterval(updateTime, 1000*60);
console.log("延迟"+TimeN+"分钟,点击完成")
//延迟执行,时间到点击完成播放
setTimeout(function() {
var wcbtn = document.getElementsByClassName("btn btn-default")
wcbtn[1].click();
}, 1000*TimeN*60);
}
//ppt课程
function playscorm(){
//点击开始学习
const iframe = document.querySelector('iframe');
iframe.contentDocument.querySelector('.user_choise').click();
//需要延迟5秒,等视频加载出来,若网卡,5秒加载不出来,会出现闪退
setTimeout(function() {console.log("延迟五秒");
const iframe2 = document.querySelector('iframe');
var video = iframe2.contentDocument.getElementById('course_player');
var TimeM=video.duration;
var c= TimeM;
//在控制台输出倒计时
function updateTime(){
document.querySelector("a[data-toggle='collapse']").innerHTML=Math.floor(c)+"秒,约合"+Math.floor(c/60+1)+"分钟后,脚本将自动点击完成";
console.log(Math.floor(c)+"秒,约合"+Math.floor(c/60+1)+"分钟后,脚本将自动点击完成");
c=c-1;
}
//设置定时器,到时间自动点击完成播放
setInterval(updateTime, 1000);
setTimeout(function() {
// var wcbtn = document.getElementsByClassName("btn btn-default")
// wcbtn[1].click();
document.querySelector("button[class=' btn btn-default']").click();
}, 1000*TimeM);
}, 1000*5);
}
function StartFunc() {
// 根据当前页面执行相应操作
if (currentURL.includes('https://www.ahgbjy.gov.cn/pc/course/courselist.do')) {
xuanke(); // 开始选课
} else if (currentURL.includes('https://www.ahgbjy.gov.cn/pc/course/coursedetail.do')) {
xiangqing();
} else if (currentURL.includes('https://www.ahgbjy.gov.cn/pc/course/playvideo.do' )){
StarAndExit();
}else if (currentURL.includes('https://www.ahgbjy.gov.cn/pc/course/playscorm.do' )){
playscorm();
}
}
window.onload = function () {
// 调用需要在页面加载完成后执行的函数
StartFunc();
}
})();