Elearning Downloader

download all files on the page on elearning with one click

目前為 2022-09-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Elearning Downloader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  download all files on the page on elearning with one click
// @author       Char不多得了
// @match        https://elearning.fudan.edu.cn/courses/*/files
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fudan.edu.cn
// @grant        GM_registerMenuCommand
// @grant        GM.registerMenuCommand
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var course_id = null
    var file_elem = null
    course_id = /\d+/.exec(window.location.href)[0];
    file_elem = document.getElementsByClassName("ef-name-col__link");

    console.log("debug")
    // 适配不同版本的GM函数
    var _GM_registerMenuCommand;
    if(typeof GM_registerMenuCommand!='undefined'){
        _GM_registerMenuCommand=GM_registerMenuCommand;
    }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
        _GM_registerMenuCommand=GM.registerMenuCommand;
    }
    if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};


    function download_all(){
        if(file_elem==null||file_elem.length===0){
            console.log("当前页面未找到文件")
            return;
        }
        let file_url_list = []

        for(let i=0;i<file_elem.length;i++){
            file_url_list.push("https://elearning.fudan.edu.cn/courses/"+course_id+"/files/"+ /\d+/.exec(file_elem.item(i).href)[0]+ "/download?download_frd=1")
        }
        console.log(file_url_list)

        for(let url in file_url_list){
            // 根据链接下载
            const a = document.createElement('a');
            a.setAttribute('href', file_url_list[url]);
            a.setAttribute('download', "");
            a.click();
        }

    }


    _GM_registerMenuCommand("download all",download_all);
})();

QingJ © 2025

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