超星挂机小助手(仅支持脚本猫,请勿使用油猴)
// ==UserScript==
// @name 超星挂机小助手(仅支持脚本猫,请勿使用油猴)
// @namespace unrival
// @version 2.2
// @description 浏览器后台挂视频脚本,请配合超星网课小助手使用
// @author unrival
// @storageName unrivalxxt
// @background
// @icon http://pan-yz.chaoxing.com/favicon.ico
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @connect mooc1-1.chaoxing.com
// @connect mooc1.chaoxing.com
// @connect mooc1-2.chaoxing.com
// @connect proxy-unrival-agent-api1.xn--6cs.top
// @connect 14.29.190.187
// @license GPL-3.0-or-later
// @original-script https://scriptcat.org/script-show-page/379
// @original-author unrival
// @original-license GPL-3.0-or-later
// ==/UserScript==
return new Promise((resolve, reject) => {
var sendLog = (log)=>{
GM_setValue('unrivalxxtbackgroundinfo',log);
console.log(log);
}
GM_setValue('unrivalBackgroundVideo','1');
GM_setValue('unrivalBackgroundList',[]);
var host = 'http://proxy-unrival-agent-api1.xn--6cs.top/',
missionList = [],
value = GM_getValue('unrivalBackgroundVideo','1');
GM_setValue('unrivalBackgroundVideoEnable',String(Math.round(new Date() / 1000)));
function dealMission(videoInfo) {
try{
for(let i=0,l=missionList.length;i<l;i++){
if(missionList[i]['jobid']==videoInfo['jobid']&&missionList[i]['userid']==videoInfo['userid']){
sendLog('提交了两个相同任务');
return;
}
if(missionList[i]['userid']!=videoInfo['userid']){
sendLog('禁止多用户同刷');
return;
}
}
}catch(e){
console.log(e);
return;
}
videoInfo['done']=false;
videoInfo['playTime'] = '-60';
videoInfo['rt'] = videoInfo['rt'];
videoInfo['isdrag'] = '3';
videoInfo['videojs_id'] = String(parseInt(Math.random() * 9999999));
sendLog('添加新任务');
missionList.push(videoInfo);
GM_setValue('unrivalBackgroundList',missionList);
}
setInterval(function(){
if(value!=GM_getValue('unrivalBackgroundVideo','1')){
value = GM_getValue('unrivalBackgroundVideo','1');
dealMission(value);
}
},1000);
setInterval(function(){
GM_setValue('unrivalBackgroundVideoEnable',String(Math.round(new Date() / 1000)));
GM_setValue('unrivalBackgroundList',missionList);
},1000);
var jobLoop = setInterval(function(){
for(let i=0,l=missionList.length;i<l;i++){
if(missionList[i]['done']){
continue;
}
let video = missionList[i];
missionList[i]['playTime'] = parseInt(missionList[i]['playTime'])+60;
if(parseInt(missionList[i]['playTime'])>=parseInt(missionList[i]['duration'])){
missionList[i]['playTime'] = missionList[i]['duration'];
missionList[i]['isdrag'] = '4';
}else if(parseInt(missionList[i]['playTime'])>0){
missionList[i]['isdrag'] = '0';
}
let encUrl = host+'chaoXing/v3/getEnc.php?classid='+video['classId']+'&playtime='+missionList[i]['playTime']+'&duration='+video['duration']+'&objectid='+video['objectId']+'&jobid='+video['jobid']+'&uid='+video['userid'];
GM_xmlhttpRequest({
method: "get",
url: encUrl,
onload: function(res) {
let enc = res.responseText;
if(enc.includes('--#')){
let warnInfo = enc.match(new RegExp('--#(.*?)--#',"ig"))[0].replace(/--#/ig,'');
sendLog(warnInfo);
enc = enc.replace(/--#(.*?)--#/ig,'');
if(enc.indexOf('.stop')>=0){
clearInterval(jobLoop);
setInterval(function(){
sendLog(warnInfo);
},20000);
return;
}
}
if(enc.length!=32){
if(enc.indexOf('.stop')>=0){
clearInterval(jobLoop);
return;
}
sendLog('获取视频enc错误,六十秒后重试');
sendLog('如果反复失败,请尝试在脚本代码内更改服务器线路');
sendLog(enc.replace('.stop',''));
if(enc.indexOf('.stop')>=0){
clearInterval(jobLoop);
}
missionList[i]['playTime']=String(parseInt(missionList[i]['playTime'])-60);
return;
}
let reportsUrl = video['reportUrl']+'/'+video['dtoken']+'?clazzId='+video['classId']+'&playingTime='+missionList[i]['playTime']+'&duration='+video['duration']+'&clipTime=0_'+video['duration']+'&objectId='+video['objectId']+'&otherInfo='+video['otherInfo']+'&jobid='+video['jobid']+'&userid='+video['userid']+'&isdrag='+missionList[i]['isdrag']+'&view=pc&enc='+enc+'&rt='+missionList[i]['rt']+'&dtype=Video&_t='+String(Math.round(new Date())),
vrefer = GM_getValue('vrefer','https://mooc1.chaoxing.com/ananas/modules/video/index.html?v=2022-1118-1729'),
h = GM_getValue('host','mooc1.chaoxing.com');
GM_xmlhttpRequest({
method: "get",
headers: {
'Host': h,
'Referer': vrefer
},
url: reportsUrl,
cookie: 'videojs_id='+video['videojs_id'],
onload: function(res) {
try{
let today = new Date(),
todayStr = today.getFullYear()+'d'+today.getMonth()+'d'+today.getDate(),
timelong = GM_getValue('unrivaltimelong',{});
if(timelong[video['userid']]==undefined||timelong[video['userid']]['today']!=todayStr){
timelong[video['userid']] = {
'time':0,
'today':todayStr
};
}else{
timelong[video['userid']]['time']++;
}
GM_setValue('unrivaltimelong',timelong);
if(timelong[video['userid']]['time']/60>22&&!video['review']){
sendLog(video['name']+':今日学习时间过长,继续学习会导致清空进度,请明天再来');
clearInterval(jobLoop);
return;
}
let ispass = JSON.parse(res.responseText);
if(ispass['isPassed']&&!video['review']){
sendLog(video['name']+':视频任务已完成');
missionList[i]['done']=true;
}else if(missionList[i]['isdrag']== '4'||parseInt(missionList[i]['playTime'])>=parseInt(missionList[i]['duration'])){
if(video['review']){
sendLog(video['name']+':视频已观看完毕');
}else{
sendLog(video['name']+':视频已观看完毕,但视频任务未完成');
}
missionList[i]['done']=true;
}else{
sendLog(video['name']+'已观看'+missionList[i]['playTime']+'秒,剩余大约'+String(parseInt(video['duration'])-parseInt(missionList[i]['playTime']))+'秒');
}
}catch(e){
console.log(e);
if(res.responseText.indexOf('验证码')>=0){
sendLog('已被超星风控,请点击下方链接处理:');
sendLog('<a href="'+reportsUrl+'" target="view_window">'+reportsUrl+'</a>');
missionList[i]['playTime']='10';
return;
}
sendLog('超星返回错误信息,六十秒后重试','red');
missionList[i]['playTime']=String(parseInt(missionList[i]['playTime'])-60);
return;
}
},
onerror:function(err){
console.log(err);
sendLog(video['name']+':观看视频失败');
missionList[i]['done']=true;
}
});
},
onerror:function(err){
console.log(err);
sendLog('获取视频enc失败,请检查脚本插件是否有完整的访问权限,具体请见脚本下载页','red');
}
});
break;
}
},60000);
});