Elearning Downloader

download all files on the page on elearning with one click

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
})();