LAW

LC AUTO WATCH

当前为 2022-10-09 提交的版本,查看 最新版本

// ==UserScript==
// @name         LAW
// @namespace    http://tampermonkey.net/
// @version      2.90
// @description  LC AUTO WATCH
// @author       You
// @match        https://edu.inspur.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=inspur.com
// @grant        none
// ==/UserScript==
let curTime = "";

function setCookie(cname,cvalue,exdays)
{
  var d = new Date();
  d.setTime(d.getTime()+(exdays*24*60*60*1000));
  var expires = "expires="+d.toGMTString();
  document.cookie = cname + "=" + cvalue + "; " + expires +";path=/";
}
function getCookie(cname)
{
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++)
  {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) return decodeURI(c.substring(name.length,c.length));
  }
  return "";
}
function back(){
    let urllist = [];
    const urlstr = getCookie('urllist');
    if(urlstr!==''){
        urllist=JSON.parse(urlstr);
    }
    if(urllist.length>0){
        window.location.href=urllist.pop();
    }else{
        window.history.back(-1);
    }
}
function go(url){
    let urllist=[];
    const urlstr=getCookie('urllist');
    if(urlstr!==''){
        urllist=JSON.parse(urlstr);
    }
    urllist.push(window.location.href);
    setCookie('urllist',JSON.stringify(urllist));
    window.location.href=url;
}
function refreshSchedule(){
    const divStartArea=document.getElementById('divStartArea');
    if(divStartArea!==null){
        const spanLeavTimes=document.getElementById('spanLeavTimes').innerText;
        if(divStartArea.style.display==="none"){
            back();
        }else{
            if(curTime===""||curTime===spanLeavTimes){
                myPlayer.play();
            }else{
                console.log(divStartArea.innerText);
            }
            curTime=spanLeavTimes;
        }
    }
}
(function() {
    'use strict';
    let i=1;
    while(1){
        let contentitem=document.getElementById('contentitem'+i);
        if(contentitem!==null){
            let url=$('#contentitem'+i).attr('onclick').match(/learningKnowledge\(\"(.*).html"/)[1]+".html",flag=false;
            console.log(url);
            let skipstr=getCookie('skip'),skip=[];
            if(skipstr!==''){
                skip=JSON.parse(skipstr);
            }
            for(let s of skip){
                if(s===url){
                    flag=true;
                    break;
                }
            }
            if(flag){
                i++;
                continue;
            }
            const progress=contentitem.getElementsByClassName('el-plan-progress-text')[0].innerText;
            if(progress==="100%"){
                i++;
                continue;
            }
            setCookie('tmp',url,1);
            go(url);
            break;
        }else{
            break;
        }
        i++;
    }

    const tbodyTrainInfo=document.getElementById('tbodyTrainInfo');
    if(tbodyTrainInfo!==null){
        let trs = tbodyTrainInfo.children,i;
        console.log(trs);
        for(i =1;i<trs.length;i++){
            if(trs[i].nodeName==='TR'){
                //console.log(trs[i]);
                let str=trs[i].lastElementChild.lastElementChild.lastElementChild.innerText;
                if(str==="100%"||str==="查看"){
                    continue;
                }
                if(str==="开始考试"){
                    let skipstr=getCookie('skip'),tmp=getCookie('tmp'),skip=[];
                    if(tmp!==''){
                        if(skipstr!==''){
                            skip=JSON.parse(skipstr);
                        }
                        skip.push(tmp);
                        setCookie('skip',JSON.stringify(skip),1);
                    }
                    back();
                    break;
                }
                //window.location.href=window.location.href;
                let url=trs[i].getAttribute('onclick');
                console.log(url);
                go(url.match(/return StudyRowClick\(\'(.*).html?/)[1]+".html");
                break;
                //window.history.pushState(null,"",url.match(/return StudyRowClick\(\'(.*).html?/)[1]+".html");
            }
        }
        if(i>0&&i==trs.length){
            back();
        }
    }

    const tableContainer=document.getElementById('tableContainer');
    if(tableContainer!==null){
        let trs = tableContainer.firstElementChild.firstElementChild.children;
        console.log(trs);
        if(trs.length>1&&trs[1].nodeName==='TR'&&trs[1].className!=="empty"){
            //console.log(trs[1]);
            //window.location.href=window.location.href;
            let check=trs[1].firstElementChild.firstElementChild.firstElementChild;
            if(check!==null){
                check.checked=true;
                ClickSelf(check);
                $('#hidDeleteType').val("BacthDelete");
                document.getElementById('btnDelete').click();
            }
            let url=trs[1].children[2].innerHTML;
            console.log(url);
            go(url.match(/isOpenFaceId\(&quot;&quot;,&quot;&quot;,&quot;(.*).html?/)[1]+".html");
            //window.location.replace(url.match(/isOpenFaceId\(&quot;&quot;,&quot;&quot;,&quot;(.*).html?/)[1]+".html");
        }
    }

    const normalrow=document.getElementsByClassName('normalrow clearfix');
    if(normalrow!==null){
        let i=0;
        for(;i<normalrow.length;i++){
            if(normalrow[i].nodeName==='DIV'){
                let str=normalrow[i].getElementsByClassName('fontnumber study-schedule')[0].innerHTML;
                if(str.match(/100.0%/)!==null){
                    continue;
                }
                //window.location.href=window.location.href;
                let url=normalrow[i].getElementsByClassName('text-color6')[0].getAttribute('href');
                console.log(url);
                go(url.match(/javascript:void\(StudyRowClick\(\'(.*).html?/)[1]+".html");
                break;
            }
        }
        if(i>0&&i==normalrow.length){
            back();
        }
    }
    let timer=null;
    clearInterval(timer);
    timer=setInterval(() => {
        refreshSchedule();
    }, 10000);
    if(typeof phaseTrackIntervalTime!=='undefined'){
        phaseTrackIntervalTime = 60000;
    }
    // Your code here...
})();