|
发表于 2021-4-26 02:05:01
// ==UserScript==
// @name 学习强国答题辅助 带辅助模式切换 (脚本仅供学习)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 本学习资料脚本 适用于激发学习兴趣
// @author little child
// @match https://pc.xuexi.cn/points/exam-weekly-detail.html*
// @match https://pc.xuexi.cn/points/exam-practice.html*
// @match https://pc.xuexi.cn/points/exam-paper-detail.html*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
var Yijkt=10, ksdfyo=null,jkqz='auto',tressv=false,ertet,yuiyi;
function asdaa(){
var nmlsuo=0,sdswxfg=[],match_w={}, max=0,yc_t=0;
tressv=false;
if(document.querySelector(".q-header")==null)
{
if(document.querySelector(".ant-btn.action.ant-btn-primary")!=null) return;
else{ksdfyo=setTimeout(asdaa,1000);return;}}
var tixing=document.querySelector(".q-header").innerText.substr(0,3);
if(document.querySelector(".q-footer .tips")!=null){document.querySelector(".q-footer .tips").click();}else{ ghjgr(1); return;}
document.querySelectorAll('.line-feed ').forEach(function(a,b,c){ let i=a.innerText; if(i!="") sdswxfg.push(i);});
switch(tixing){
case "单选题": yc_t=1;
case "多选题":
nmlsuo=document.querySelectorAll('.q-answers .chosen').length;
if(nmlsuo<=0){
document.querySelectorAll('.q-answer').forEach(function(a,b,c){
var yttyutut=a.innerHTML.split('. ').slice(-1)[0];
var poyuyui=false;
var dz_c=0;
var ootrddfg=false;
var qazswr=sdswxfg.join('');
ootrddfg=Boolean(a.className.indexOf("chosen")!=-1);
poyuyui=(yttyutut.indexOf(qazswr)!=-1||qazswr.indexOf(yttyutut)!=-1)&&qazswr!="";
if(poyuyui&&!ootrddfg){a.click();nmlsuo++;}
if(!poyuyui){dz_c+=qweqeqd(qazswr,a.innerHTML); match_w[dz_c]=a}
})
if(nmlsuo==0)
{for(let i in match_w){ max=Number(max)>=Number(i)? Number(max):Number(i); }
match_w[max].click();nmlsuo++;
tressv=true;}
jkjkl();yc_t=yc_t==0?2500:1500;}
break;
case "填空题":
var inpus=document.querySelectorAll('.q-body input');
var inputs_e=document.querySelectorAll('.q-body input[value=""]');
nmlsuo=inpus.length-inputs_e.length;
if(inputs_e.length>0)
{
var ev=new Event('input',{bubbles:true});
inpus.forEach(function(a,b,c){
if(sdswxfg[0]==undefined){tressv=true;let a=document.querySelector(".q-body").innerText;let n=parseInt(Math.random()*2+2);let i=parseInt(Math.random()*(a.length-n-1));sdswxfg[0]=a.substr(i,n);}
var value="";
if(c.length==1)
value=sdswxfg.join('');
else
value=b<sdswxfg.length?sdswxfg:sdswxfg[0];
if(a.value==""){
a.setAttribute("value",value);
a.dispatchEvent(ev);
nmlsuo++;
}
})
jkjkl();
yc_t=3500;
}
break;
}
ksdfyo=setTimeout(function(){ghjgr(nmlsuo)},parseInt(Math.random()*1500+yc_t));
}
function ghjgr(nmlsuo=0)
{
if(nmlsuo>0&&jkqz=='auto')
{
!document.querySelector(".next-btn").disabled?document.querySelector(".next-btn").click():document.querySelector(".submit-btn").click();
ksdfyo=setTimeout(asdaa,parseInt(Math.random()*1000+2000));
}
}
function qweqeqd(a='',b=''){
let c=0;
for(let i=0;i<b.length;i++)
{
if(a.indexOf(b.substr(i,1))!=-1)
{c++;}
}
return c;
}
function jkjkl(){
if(document.querySelector("#my_ms")!=null||!tressv) return ;
let ds_c=0;
let ds_t=null;
jkqz="wait";
let e=document.createElement("div");
e.id="my_ms";
e.innerHTML="此题无完全匹配答案,已填写(选择)一个相对最匹配的答案(可能是错误的)。你可以点击下面按钮切换到手动做题并修正答案后再次点击按钮切换到自动做题。<br><span id='my_ds'>若 <span id='my_ds_c'>"+Yijkt+"</span> 秒无操作则继续自动做题</span><br>";
e.style.color='red';
e.style.fontSize='20px';
e.style.textAlign='center';
document.querySelector(".header-row").appendChild(e);
let b=document.createElement("button");
b.style.color='green';
b.style.fontSize='24px';
b.style.textAlign='center';
b.style.marginTop='10px';
b.value='auto';
b.innerText='切换到手动做题';
b.onclick=function(){
document.querySelector("#my_ds").innerHTML='';
if(ds_t!=null){clearInterval(ds_t); ds_t=null;}
if(this.value=='auto')
{
this.value='manual';
jkqz="manual";
b.innerText='切换到自动做题';
this.style.color='red';
}
else
{
this.value='auto';
jkqz='auto';
b.innerText='切换到手动做题';
this.style.color='green';
document.querySelector("#my_ms").remove();
asdaa();
}
}
e.appendChild(b);
ds_t=setInterval(function(){
ds_c++;
document.querySelector("#my_ds_c").innerText=Yijkt-ds_c;
if(ds_c>=Yijkt)
{
document.querySelector("#my_ms").remove();
clearInterval(ds_t);
ds_t=null;
jkqz='auto';
ghjgr(1);
}
},1000);
}
ksdfyo=setTimeout(asdaa,parseInt(Math.random()*1000+2000));
})(); |
|