minerva-online下载报告附件

在问卷管理页面生效,点击↓加载附件列表,点击√可一键下载全部附件,点击附件名下载单个附件,如弹出窗口被拦截请允许后再进行操作

当前为 2021-09-02 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         minerva-online下载报告附件
// @namespace    https://greasyfork.org/scripts/431414-minerva-online%E4%B8%8B%E8%BD%BD%E6%8A%A5%E5%91%8A%E9%99%84%E4%BB%B6
// @version      0.9
// @description  在问卷管理页面生效,点击↓加载附件列表,点击√可一键下载全部附件,点击附件名下载单个附件,如弹出窗口被拦截请允许后再进行操作
// @author       inoki
// @match        https://www.minerva-online.com/document.asp?alias=smngr.surveyexplorer
// @resource     /lib/jquery/jquery-1.11.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';


    $("tr.persist-header").each(function(){
        $(this).children().first().after( $(this).children().first().clone(true));
    });
    $("div.sticky-wrap").find(":checkbox").each(function(){//checkbox后添加下载按钮
        var surveyid=$(this).val();
        $(this).parent().after('<td><button type=button id='+surveyid+' class=download><b>↓</td>');
        $("#"+surveyid+".download").on("click",download_button);
    });


    //获取附件列表
    function download_button(){
        var surveyid=$(this).attr("id");
        $("#"+surveyid+".download").after('<p id='+surveyid+' class=loading><b>......');
        $.get("/document.asp?alias=survey.view&InstanceID="+surveyid,function(data,status){//获取当前survey内容
            if (status=="success"){
                var fileno=$(data).find("td.attachLeftCell").size();
                $("p#"+surveyid+".loading").after('<ol id='+surveyid+' class=filelist>\n#='+fileno+'');
                if (fileno>0){
                    $(data).find("td.attachLeftCell").each(function(){
                        $('<li><a id='+surveyid+' class=file href='+file_attr(this)[1]+'>'+file_attr(this)[0]+'</li>').appendTo("ol#"+surveyid+".filelist");
                    });
                    $("ol#"+surveyid+".filelist").prepend('<button type=button id='+surveyid+' class=yes><b>√');
                    $("button#"+surveyid+".yes").on("click",download_yes);
                    download_button0(surveyid);
                }
                else {
                    download_button0(surveyid);
                }
            }
            else {
                download_button0(surveyid);
            }
        });
    }

    //判断附件类型并获取名称和地址
    function file_attr(file){
        if ($(file).children().first().is("img")){
            var fileurl=$(file).find("img.attachedImg").attr("src");
            if (fileurl.indexOf("Visual.asp?")>=0){
                fileurl=$(file).next().find("a.downloadLinkBtn").attr("href");
            }
        }
        else {
            fileurl=$(file).children().first().attr("data-source");
        }
        var filename=$(file).next().find("div.propValueContent.propValueFileName").text();
        if (fileurl.indexOf("getImage")>=0){
            fileurl=fileurl.replace("Image.asp?","Attachment.asp?Attachment");
        }
        return [filename,fileurl];
    }

    //按钮变为关闭
    function download_button0(surveyid){
        $("p#"+surveyid+".loading").remove();
        $("button#"+surveyid+".download").unbind();
        $("button#"+surveyid+".download").on("click",download_button1);
        $("button#"+surveyid+".download").text("×");
    }

    //按钮重置为初始
    function download_button1(){
        var surveyid=$(this).attr("id");
        $("ol").remove("#"+surveyid);
        $("button#"+surveyid+".download").unbind();
        $("button#"+surveyid+".download").on("click",download_button);
        $("button#"+surveyid+".download").text("↓");
    }

    //确认下载
    function download_yes(){
        var surveyid=$(this).attr("id");
        var url=$("a#"+surveyid+".file");
        for(var i=0;i<url.length;i++){
            window.open($(url[i]).attr("href"));
        }
        $("button#"+surveyid+".yes").text("〇");
    }


})();