// ==UserScript== // @name U校园挂机喵 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.2.0 // @description save your time // @author 初雪小白 // @match https://u.unipus.cn/user/student/mycourse/* // @match https://ucontent.unipus.cn/_pc_default/*/*/courseware/*/*/*/* // @match https://ucontent.unipus.cn/_pc_default/*/*/courseware/*/*/*/*/* // @require https://cdn.staticfile.org/jquery/3.1.1/jquery.min.js // @resource customCSS https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css // @require https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js // @grant GM_addStyle // @grant GM_getResourceText // @grant unsafeWindow // ==/UserScript== let interval=10000; let autosolve=false; let review=true; let unit=1; let loop=true; let autosubmit=false; let waiting=5000; let time_control=120; let configContent=` `; let newCSS = GM_getResourceText ("customCSS"); let myCSS=document.createElement("style"); myCSS.innerHTML= ` #config {position: fixed;left: 0;top: 100px;z-index: 999;} .portion { height: auto; margin: 10px 0; } .h3 { display: inline-block; font-size: 16px; margin: 0!important; } .portion ul,ol { list-style: none; line-height: 20px!important; margin-bottom: 0!important; padding-left: 0; } .portion ul,ol li { margin: 10px 10px; height: 20px; } .portion ul li { float: left; } .clearfix:before,.clearfix:after { content:""; display:table; } .clearfix:after { clear:both; overflow:hidden; } .clearfix { zoom:1; /* for ie6 & ie7 */ } .clear { clear:both; display:block; font-size:0; height:0; line-height:0; overflow:hidden; } ` //---------------------------- $(function(){//dom加载完毕 GM_addStyle (newCSS); $("head").append(myCSS); AddHtml(configContent); $("window").ready(function(){ if(localStorage.getItem('configContent')){ configs=JSON.parse(localStorage.getItem('configContent')); autosolve=configs[0]; review=configs[1]; autosubmit=configs[2]; loop=configs[3]; interval=configs[4]; waiting=configs[5]; unit=configs[6]; time_control=configs[7]; } time_control+=interval/60000; $('.save').click(function(){ let map=[]; $('.modal').find('.modal-body').find('ul').find('input').each(function(i,e){ switch(i){ case 3:if($(e).prop('checked')) map[1]=true; default:map.push($(e).prop('checked')); } }) $('.modal').find('.modal-body').find('ol').find('input').each(function(i,e){ switch(i){ case 0:if($(e).val()==null){ map.push(5*60*1000); }else{ let val=Math.floor($(e).val()); if(val<=1) map.push(5*60*1000); else map.push(val*60*1000); } break; case 1:if($(e).val()==null){ map.push(15*1000); }else{ let val=Math.floor($(e).val()); if(val<=3) map.push(5*1000); else map.push(val*1000); } break; case 2:if($(e).val()==null){ map.push(0); }else{ let val=Math.floor($(e).val()); if(val<=0) map.push(0); else map.push(val-1); } break; case 3:if($(e).val()==null){ map.push(5); }else{ let val=Math.floor($(e).val()); if(val<=0) map.push(5); else map.push(val); } break; } }) localStorage.setItem('configContent',JSON.stringify(map)); console.log(localStorage.getItem('configContent')); location.reload(); }) let href=location.href; if(href.match('courseCatalog')!==null){//总目录页 setTimeout(function(){ let uls=[]; $('ul').each(function(i,e){ if(e.className===''){ uls.push(e); } }) if(review){ $(uls[unit]).children('.group').eq(1).click();//setting the scene页面有点小问题 } else{ } },15000) } else{ let right_lis=[]; let active_index=0; let top_lis=null; let active_one=null; setTimeout(function(){ console.log('out begin!'); top_lis=$('.headerbar').children('.TabsBox').children(); $('#layoutTheme').children('#sidemenuContainer').find('.menuRightTabContent').find('li').each(function(i,e){ if(!e.classList.contains('disabled')&&e.classList.contains('group')){ right_lis.push(e); } }) active_index=getIndexOf(right_lis,'active'); active_one=getIndexOf(top_lis,'active'); console.log(active_one); console.log(right_lis); console.log(top_lis); },waiting); let timer = setInterval(function(){ console.log('interval begin!'); if(localStorage.getItem(time_controls)){ let time_controls=JSON.parse(localStorage.getItem("time_controls")); time_controls[time_controls.length-1]+=interval/60000; localStorage.setItem("time_controls",JSON.stringify(time_controls)); let latest=time_controls[time_controls.length-1]; if(latest>=time_control){ location.href="https://u.unipus.cn/index.html/"; location.reload(); } } else{ let time_controls=[]; time_controls.push(interval/60000); localStorage.setItem("time_controls",JSON.stringify(time_controls)); } if($('.headerbar').children('.TabsBox').children().length===1){ right_lis[active_index+1].click(); } else{ if(active_one===top_lis.length-1){ if(active_index===right_lis.length-1){ if(loop){ console.log(11); $('#header').find('.layoutHeaderStyle--breadCrumbBox-rFgzd').children('ul').children().eq(0).children('a')[0].click(); } else clearInterval(timer); } else right_lis[active_index+1].click(); } else{ top_lis[active_one+1].click(); } } setTimeout(function(){ top_lis=$('.headerbar').children('.TabsBox').children(); active_index=getIndexOf(right_lis,'active'); active_one=getIndexOf(top_lis,'active'); },waiting); },interval); } }) }) function AddHtml(html) { document.body.insertAdjacentHTML('afterBegin', html); } function getIndexOf(list,classname){ let index=-1; $.each(list,function(i,e){ if(e.classList.contains(classname)) index=i; }) return index; } //-------------------------------------