愛課程刷課腳本
// ==UserScript==
// @name 愛課程刷課腳本
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://service.icourses.cn/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=chinaedu.net
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @run-at document-start
// ==/UserScript==
const config={
pdf_time:20*60*1000//30分鐘
}
let ChapterList=[]
function GetRessList(id){
return new Promise((resolve,reject)=>{
GM_xmlhttpRequest({
url:"https://service.icourses.cn/hep-company//sword/company/getRess",
method :"POST",
data:"sectionId="+id,
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
onload:function(xhr){
try {
resolve(JSON.parse(xhr.responseText).model.listRes)
}
catch(err) {
resolve([])
}
}
});
})
}
function OpenOriginDialog(Content){
return new Promise((resolve,reject)=>{
unsafeWindow.require(["Play"],function(Play){
let courseId=unsafeWindow._courseId;
let userId=unsafeWindow._userId;
let companyCode=unsafeWindow._companyCode;
const ListenMessage= (e)=> {
if(e.data==='lhd_close'){
unsafeWindow.removeEventListener('message', ListenMessage)
document.querySelector('[id^=dialog-myModal]')?.remove()
resolve()
}
}
unsafeWindow.addEventListener('message', ListenMessage);
Play.dialog({
//唯一ID
id:"videoBox-link",
data:{
url:Content.fullResUrl,
companyCode:companyCode,//三方公司id
resId:Content.id,
type:Content.mediaType,
userId:userId,
courseId:courseId,
title:Content.title+'-李恒道破解'
},
//弹出框宽度
width:"auto",
//弹出框高度
height:(screen.availHeight-200) + "px",
//是否开启打点功能
isTicker:true
});
})
})
}
async function ExecteContentMission(Contet){
return new Promise(async (resolve,reject)=>{
await OpenOriginDialog(Contet)
//执行相关内容
resolve()
})
}
async function AutoExecteChaprterMission(ChapterList){
for(let index=0;index<ChapterList.length;index++){
let CurrentChapert=ChapterList[index]//获取每个章
let ContentList=await GetRessList(CurrentChapert)//获取该章数据
for(let ContentIndex=0;ContentIndex<ContentList.length;ContentIndex++){
let CurrentContent=ContentList[ContentIndex]//遍历内容数据列表
await ExecteContentMission(CurrentContent)//执行内容
}
}
}
function InjectButtonToBody(){
let btn=document.createElement("div");
btn.innerHTML='<button style="position: fixed;bottom: 80vw;right: 0;z-index: 9999;height: 50px;">开始刷课</button>';
btn.onclick=function(){
ChapterList=[]
ChapterList=ChapterList.concat(...document.querySelectorAll(".shareResources > .panel-group > li"))
let ParentChapert= document.querySelectorAll(".shareResources > .panel-group > li:not(.noContent)")
ParentChapert.forEach((item) => {
ChapterList=ChapterList.concat(...item.querySelectorAll(".chapter-content [data-secid]"))
});
ChapterList= ChapterList.map((item)=>item.getAttribute("data-id")??item.getAttribute("data-secid"))
AutoExecteChaprterMission(ChapterList)
}
document.body.append(btn);
}
function InjectVideoPage(){
unsafeWindow.savevideojs=undefined
Object.defineProperty(unsafeWindow,'videojs',{
get(){
let result=unsafeWindow.savevideojs;
return result
},
set(vdobj){
vdobj.hook('beforesetup', function(videoEl, options) {
options.muted=true;
options.autoplay=true;
return options;
});
vdobj.hook('setup', function(player) {
player.on("ended", function() {
});
});
unsafeWindow.savevideojs=vdobj;
}
})
}
function InjectPdfPage(){
setTimeout(()=>{
},config.pdf_time)
}
function MainBranch(){
if(location.href.indexOf('/sword/rp/play/toPlay')!==-1){
InjectVideoPage()
}else if(location.href.indexOf('/icourse/lib/pdfjs/web/')!==-1){
InjectPdfPage()
}else{
InjectButtonToBody()
}
}
MainBranch()