宁波干部党员学习网

自动学习

当前为 2021-06-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         宁波干部党员学习网
// @namespace    http://nb.nbstudy.gov.cn/vm/login.jsp
// @version      1.3
// @description  自动学习
// @author       dahuilang
// @match        http://nb.nbstudy.gov.cn/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...

    var pageList=['http://nb.nbstudy.gov.cn/vm/class/show','http://nb.nbstudy.gov.cn/vm/course'] //启用脚本的页面
    var isStart = false;
    var videoLenth = 3600*10;//最长10个小时
    for(var pIndex=0;pIndex<pageList.length;pIndex++){
        
        if(location.href.indexOf(pageList[pIndex])>=0){
            
            isStart = true;
        }
    }

    if(isStart){


   var idList=[];

    //获取当前页所有视频的ID
    var interval = setInterval(function(){
         
       if(idList.length==0){
          var divList = $(".box2.class_box");
           for(var i=0;i<divList.length;i++){
               var c = divList[i];
               var link = $(c).attr("onclick");
               var gid= link.split(",")[0].split("(")[1].replace(/'/g,'');
               idList.push(gid);
           }

       }else{
             clearInterval(interval);
            playCurrentPage();
       }


    },1000);

    //播放当前页面未完成的视频
    function playCurrentPage(){
         query(idList,function(notCompleteId){

                 if(notCompleteId){
                    play(notCompleteId)
                 }else{
                     var url = location.href;
                     var pageNoIndex = url.indexOf("pageNo=")
                     var pageNo = 1;
                     if(pageNoIndex>=0){
                         pageNo = url.substring(pageNoIndex+"pageNo=".length)
                     }

                   location.href="http://nb.nbstudy.gov.cn/vm/course/?sid=0&pageNo="+(new Number(pageNo)+1) //翻页到下一页

                 }
             })

    }


    //获取cardid
    function getCardId(){
         var html =  document.documentElement.innerHTML
             var cardidIndex = html.indexOf("cardid=");
             if(cardidIndex>=0){
                html = html.substring(cardidIndex+"cardid=".length)
             }
             var cardid = html.split("&")[0];
        return cardid

    }


    //获取到未播放完成的视频
    function query(list,callback){

       var cardid = getCardId();

        $.ajax({
				   type: "GET",
				    url: "/in/GET-STUDY-SUM.phtml?cardid="+cardid+"&oid="+Math.random(),
				    dataType: 'json',
				   success: function(data){


                       var notCompleteId = null;

                       for(var i=0;i<list.length;i++){
                           var id = list[i];

                           var isComplete = false;
                           for(var j=0;j<data.length;j++){
                              var c = data[j];
                              if(id == c.videoId && c.ccc=="100"){ //已经完成观看
                                 isComplete = true;
                                  break;
                              }
                           }//end for

                          if(!isComplete){
                              notCompleteId = id;
                              break;
                          }
                       }//end for

                        callback(notCompleteId)


				   }
				});

    }

    //模拟播放
    function play(videoId){

        var cardid = getCardId();

        getVideoLength(videoId)

        var p2 = 60;

        var playInterval = setInterval(function(){
               console.log(new Date(),"play:"+videoId+",p2:"+p2)
             
             $.ajax({
				   type: "GET",
				    url: "/in/CAL.jsp?rid=0&cardid="+cardid+"&videoId="+videoId+"&p1=0&p2="+p2,
				    dataType: 'json',
				     success: function(data){


                       //查询该视频的播放进度是否100%,如果是则刷新页面
                      query([videoId],function(notCompleteId){

                            if(notCompleteId){ //视频没有播放完成,继续循环

                                if(p2 > videoLenth){ //花费的时间超过了视频的总时长,则播放当前页面除了本视频之外的下一个视频

                                    for(var i=0;i<idList.length;i++){
                                       var c = idList[i]
                                        if(c == videoId){
                                            idList.splice(i, 1);
                                            break;
                                        }

                                    }

                                     playCurrentPage();
                                }

                            }else{//视频已经播放完成,则刷新页面
                                 location.reload()

                            }



                      })


				   }
				});

            p2 = p2+60;

        },60000);
    }//end play

        //获取视频时长
       function getVideoLength(cid){
           if(!cid){
              return
           }
           $.ajax({
				   type: "GET",
				    url: "/vm/course/play.jsp?cid="+cid,
				    dataType: 'html',
				     success: function(data){

                         var index = data.indexOf("file:")
                         data = data.substring(index+"file:".length)
                         var url = data.split("}")[0].replace(/"/g,"")

                         var video = document.createElement('video');
                         video.setAttribute("src",url);
                         video.onloadedmetadata = function() {

                             videoLenth = video.duration;
                             console.log(url,"second:"+videoLenth)
                         };

				   }
				});

       }

 }





    
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址