// ==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.8
// @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
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
$("tr.persist-header").children().first().after( $("tr.persist-header").children().first().clone(true));
$("div.sticky-wrap").find(":checkbox").each(function(){//checkbox后添加下载按钮
var surveyid=$(this).val();
$(this).parent().after('
↓ ');
$("#"+surveyid+".download").on("click",download_button);
});
//获取附件列表
function download_button(){
var surveyid=$(this).attr("id");
$("#"+surveyid+".download").after('......');
$.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('\n#='+fileno+'');
if (fileno>0){
$(data).find("td.attachLeftCell").each(function(){
$(''+file_attr(this)[0]+' ').appendTo("ol#"+surveyid+".filelist");
});
$("ol#"+surveyid+".filelist").prepend('√');
$("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