智慧职教 | 职教云 —— 课件下载

专门用于对智慧职教旗下的职教云、MOOC学院和资源库的课件下载

目前為 2021-12-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name         智慧职教 | 职教云 —— 课件下载
// @namespace    https://gf.qytechs.cn/zh-CN/users/856720
// @version      0.4
// @description  专门用于对智慧职教旗下的职教云、MOOC学院和资源库的课件下载
// @license      GPL License
// @author       a我还是少年a
// @match        https://zjy2.icve.com.cn/common/directory/directory.html?*
// @match        http://zjy2.icve.com.cn/common/directory/directory.html?*
// @match        https://mooc.icve.com.cn/study/courseLearn/resourcesStudy.html?*
// @match        http://mooc.icve.com.cn/study/courseLearn/resourcesStudy.html?*
// @match        https://www.icve.com.cn/study/directory/dir_course.html?*
// @match        http://www.icve.com.cn/study/directory/dir_course.html?*
// @icon         https://zjy2.icve.com.cn/favicon.ico
// @grant        none
// ==/UserScript==

(function() {

    //获取课件网页URL信息
    function getQueryVariable(variable){
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
    }

    //获取具体参数
    var courseOpenId = getQueryVariable("courseOpenId");
    var openClassId = getQueryVariable("openClassId");
    var cellId = getQueryVariable("cellId");
    var flag = getQueryVariable("flag");
    var moduleId = getQueryVariable("moduleId");
    var courseId = getQueryVariable("courseId");
    var chapterId = getQueryVariable("chapterId");
    var sort = getQueryVariable("sort");

    //定义POST请求地址
    var posturl;
    //定义请求数据
    var post;
    //如果是职教云课程就请求第一个,如果不是就继续判断是哪个
    if(flag){
       posturl = "https://zjy2.icve.com.cn/api/common/Directory/viewDirectory";
       post = "courseOpenId="+ courseOpenId +"&openClassId="+ openClassId +"&cellId="+ cellId +"&flag="+ flag +"&moduleId="+moduleId;
    }else{
        //如果是资源库就会请求第一个,是MOOC学院就会请求第二个
        if(sort){
            //获取网站url地址
            var courseurl = window.location.href;
            //获取#号后内容,即资源库课程的课件id
            cellId = courseurl.split("#")[1];
            posturl = "https://www.icve.com.cn/study/directory/view";
            post = "cellId="+cellId+"&courseId="+courseId+"&enterType=study";
        }else{
            posturl = "https://mooc.icve.com.cn/study/learn/viewDirectory";
            post = 'courseOpenId='+ courseOpenId +'&openClassId='+ openClassId +'&cellId='+ cellId +'&flag='+ flag +'&moduleId='+moduleId;
        }
    }
    //创建ajax对象
    var xhr = new XMLHttpRequest();
    //初始化设置类型和url
    xhr.open('POST',posturl);
    //POST请求ajax,必须设置请求头
    xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded')
    //发送请求,POST参数
    xhr.send(post);
    //事件绑定
    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4){
            if(xhr.status >= 200 && xhr.status < 300){

                //将服务器返回结果以JSON方式呈现
                var txt = JSON.parse(xhr.response);
                //定义一个下载地址变量
                var url;
                //如果是资源库就会按照第一种执行,职教云和MOOC学院会按照第二种执行
                if(sort){
                    //在控制台输出课件下载地址,用于调试,可删除
                    console.log(txt.data.downloadurl);
                    console.log(txt);
                    //将获取到的下载地址赋值给url变量
                    url = txt.data.downloadurl;
                    //获取课件的名称
                    var title = txt.cell.Title;
                    //定位到class="header-draw"
                    var add_download = document.getElementsByClassName("header-draw")[0];
                    //添加a标签
                    var download = document.createElement("a");
                    add_download.appendChild(download);
                    //将创建的a标签替换为下载的代码
                    download.innerHTML = '<div style="float:right;margin-right:200px;"><span style="font-weight: bold;color:balck;font-size:20px;margin-right:40px;">友情提示:在本页面下切换课件后请刷新网页,否则下载的会是上一个课件</span><span>'+title+'</span><a id="download" href="'+url+'" style="font-size:20px;color:red;line-height:70px;margin:20px;">点此下载</a></div>';
                }else{
                    //在控制台输出课件下载地址,用于调试,可删除
                    console.log(txt.downLoadUrl);
                    //将获取到的下载地址赋值给url变量
                    url = txt.downLoadUrl;

                    //延迟一秒执行
                    setTimeout(function(){
                        //改变原本的class名称,使得图标显示
                        document.getElementById("download").className='admin';
                        //将原本的空链接改变为获取到的课件地址
                        document.getElementById("down_resource").setAttribute('href',url);
                    },1000);
                }

            }
        }
    }

    'use strict';

    // Your code here...
})();

QingJ © 2025

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