Greasy Fork

来自缓存

Greasy Fork is available in English.

minerva-online assistant

此脚本能更方便使用minerva-online平台,可在代码开头处手动设置功能开关,请仔细阅读后根据需要启用/关闭功能

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

// ==UserScript==
// @name         minerva-online assistant
// @namespace    https://space.bilibili.com/17846288
// @version      1.9.2
// @description  此脚本能更方便使用minerva-online平台,可在代码开头处手动设置功能开关,请仔细阅读后根据需要启用/关闭功能
// @author       inoki
// @match        https://www.minerva-online.com/*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js
// @noframes
// ==/UserScript==

/*jshint esversion: 6 */

(()=>{
    'use strict';

    /*功能开关:开启设为1;关闭设为0*/
    /*请根据需要手动修改开关值,保存(Ctrl+S)后生效*/

    const 置顶置底=1;
    //置顶置底:在当前域名所有页面生效,右下角添加置顶置底按钮,滚动一次页面后显示,会根据页面滚动方向自动切换置顶和置底,按钮样式可修改

    const 下载附件=1;
    //下载附件:在问卷管理页面生效,在每份报告前添加↓按钮,点↓加载附件列表,点√一键下载全部附件,点附件名下载单个附件,鼠标悬停可预览图片,浏览器设为无须确认下载效果更佳

    const 扣分标记=1;
    //扣分标记:在单店报告页面生效,将题目选项中勾选n/a的标橙,扣分的标红,选项更改后需保存报告才会刷新标记项,方便快速检查扣分题评论


    var $=$||window.$;


    /*全局添加置顶置底功能*/
    if(置顶置底&&document.location.href.indexOf('alias=knowledgebase')===-1){//knowledgebase页面自带置底按钮,不启用
        if($(document).height()>(window.innerHeight+1||document.documentElement.clientHeight)){//如有滚动条
            var goTopBottomButton=document.createElement('div');
            var toggleButton=document.createElement('img');
            $(toggleButton).appendTo(goTopBottomButton);
            $(goTopBottomButton).appendTo('body');
            $(goTopBottomButton).css({'position':'fixed','zIndex':10000});
            $(toggleButton).css({'display':'block','cursor':'pointer'}).attr('src','/knowledgebase/images/arrow_back_to_top.svg');//按钮显示图片(向下箭头)

            //以下按钮参数可自定义修改
            goTopBottomButton.style.bottom='50px';//按钮距离网页底部50px
            goTopBottomButton.style.right='30px';//按钮距离网页右边30px
            toggleButton.style.width='25px';//按钮图片宽25px
            toggleButton.style.height='25px';//按钮图片高25px
            toggleButton.style.opacity=0.5;//按钮不透明度,0.0(完全透明)到1.0(完全不透明)
            toggleButton.style.backgroundColor='grey';//按钮背景颜色,也可使用在excel等软件的自定义颜色界面的16进制代码
            let clickScrollTime=500;//点击按钮时,网页滚动到顶部或底部需要的时间,单位是毫秒

            //点击按钮时网页滚动到顶部或底部
            var scrollDirection='down';
            toggleButton.addEventListener('click',()=>{
                if (scrollDirection==='up'){
                    $('html,body').animate({scrollTop:'0px'},clickScrollTime);
                }
                else{
                    let initialHeight=$(document).height();
                    $('html,body').animate({scrollTop:initialHeight},clickScrollTime);
                }
            });

            //页面滚动监听
            let scrollAction=window.pageYOffset;
            document.onscroll=()=>{
                let diffY=scrollAction-window.pageYOffset;
                scrollAction=window.pageYOffset;
                if(diffY<0){
                    changeDirection('down');
                }
                else if(diffY>0){
                    changeDirection('up');
                }
                if(getScrollTop()===0){
                    changeDirection('down');
                }
                if(getScrollTop()+window.innerHeight+20>=$(document).height()){
                    changeDirection('up');
                }
            };
        }
    }

    //改变按钮方向
    function changeDirection(direction){
        scrollDirection=direction;
        if(direction==='down'){
            toggleButton.style.transform='rotate(0deg)';
        }
        if(direction==='up'){
            toggleButton.style.transform='rotate(180deg)';
        }
    }

    //获取垂直方向滑动距离
    function getScrollTop(){
        let scrollTop=0;
        if(document.documentElement&&document.documentElement.scrollTop){
            scrollTop=document.documentElement.scrollTop;
        }
        else if(document.body){
            scrollTop=document.body.scrollTop;
        }
        return scrollTop;
    }
    /*全局添加置顶置底功能*/


    /*问卷管理界面添加附件下载功能*/
    if (下载附件&&document.location.href.indexOf('alias=smngr.surveyexplorer')>=0){
        $('tr.persist-header').each(function(){
            $(this).children().first().after( $(this).children().first().clone(true));
        });
        $('div.sticky-wrap').find(':checkbox').each(function(){//checkbox后添加下载按钮
            let surveyid=$(this).val();
            $(this).parent().after('<td><button type=button id='+surveyid+' class=download><b>↓</td>');
            $('#'+surveyid+'.download').one('click',()=>{
                DownloadButton(surveyid);
            });
        });
    }

    //获取附件列表
    function DownloadButton(surveyid){
        $('button#'+surveyid+'.download').hide();
        $('button#'+surveyid+'.download').after('<p id='+surveyid+' class=loading><b>......');
        $.get('/open/data.asp?post={"action":"exec","dataset":{"datasetname":"/Apps/SM/Survey/SurveyInstanceGetData"},"parameters":[{"name":"SurveyInstanceID","value":"'+surveyid+'"}]}',(data,status)=>{//调用API获取当前survey数据[SurveyInstanceGetData]
            if (status==='success'){
                let attachmentdata=data.dataset.data[3];
                let fileno=attachmentdata.length;
                $('p#'+surveyid+'.loading').after('<ol id='+surveyid+' class=filelist>\t#='+fileno+'');
                if (fileno>0){
                    for(let i in attachmentdata){
                        let filename=attachmentdata[i].FileName+'.'+attachmentdata[i].FileExtension;
                        let fileid=attachmentdata[i].AttachmentID;
                        let fileurl='/mystservices/Attachments/getAttachment.asp?Attachment='+fileid+'&Password='+attachmentdata[i].Password+'';
                        let filesize=Number(attachmentdata[i].FileSizeInBytes)/1024;
                        filesize= (filesize>1024)? (filesize/1024).toFixed(2)+' MB' : filesize.toFixed(2)+' KB';
                        $('<tr id='+fileid+'>').appendTo('ol#'+surveyid+'.filelist');
                        $(`<td><li><a id=${surveyid} class='${attachmentdata[i].AttachmentType} mailboxlink' href=${fileurl}>${filename}</a>`)
                            .appendTo('tr#'+fileid);
                        $('<td>'+filesize+'</td>').appendTo('tr#'+fileid);
                        $('<iframe id='+surveyid+'>').prependTo('tr#'+fileid).hide();
                    }
                    $('a#'+surveyid+'.I,a#'+surveyid+'.V').mouseenter(function(){
                        FilePreview(1,$(this).attr('href'),this);
                    });
                    $('a#'+surveyid+'.I,a#'+surveyid+'.V').mouseleave(function(){
                        FilePreview(0);
                    });
                    $('ol#'+surveyid+'.filelist').prepend('<button type=button id='+surveyid+' class=yes><b>√');
                    $('button#'+surveyid+'.yes').on('click',()=>{
                        DownloadAll(surveyid);
                    });
                    DownloadButton0(surveyid);
                }
                else {
                    DownloadButton0(surveyid);
                }
            }
            else {
                DownloadButton0(surveyid);
            }
        },"json");
    }

    //预览附件图片
    function FilePreview(show,src){
        if(show){
            let imgid=src.split('=')[2];
            if($('img#'+imgid+'.filepreview').length===0){
                $('<div><img id='+imgid+' class=filepreview>').appendTo('body');
                $('img#'+imgid+'.filepreview').attr('src',src+'&getThumbnail=1').css('height','200px')
                    .parent().css({'position':'fixed','zIndex':10000,'height':'200px','background':'url(/images/icons/filtersv2/loading06.gif)'});
            }
            $('img#'+imgid+'.filepreview').parent().css({'top':event.clientY-200+'px','left':event.clientX+100+'px'});
            $('img#'+imgid+'.filepreview').show();
        }
        else{
            $('img.filepreview').hide();
        }
    }

    //按钮变为关闭
    function DownloadButton0(surveyid){
        $('p#'+surveyid+'.loading').remove();
        $('button#'+surveyid+'.download').one('click',()=>{
            DownloadButton1(surveyid);
        });
        $('button#'+surveyid+'.download').text('×');
        $('button#'+surveyid+'.download').show();
    }

    //按钮重置为初始
    function DownloadButton1(surveyid){
        $('ol').remove('#'+surveyid);
        $('button#'+surveyid+'.download').one('click',()=>{
            DownloadButton(surveyid);
        });
        $('button#'+surveyid+'.download').text('↓');
    }

    //确认下载
    function DownloadAll(surveyid){
        $('button#'+surveyid+'.yes').hide();
        setTimeout(()=>{
            $('button#'+surveyid+'.yes').show();
        },1000*$('ol#'+surveyid+'.filelist').find('a').length);
        $('ol#'+surveyid+'.filelist').find('a').each(function(){
            $(this).parent().parent().prev('iframe').attr('src',$(this).attr('href'));
        });
        $('button#'+surveyid+'.yes').text('〇');
    }
    /*问卷管理界面添加附件下载功能*/


    /*单店报告界面将n/a题选项标橙,扣分题选项标红*/
    if(扣分标记&&document.location.href.indexOf('alias=survey.view')>=0){
        $('span.surveyansweroption').each(function(){//标橙n/a项
            if($(this).prev('input').is(':checked')){
                if($(this).prev('input').val()==='__na__'){
                    $(this).css('color','orange');
                }
            }
        });

        let qidmark=[];
        $.get('/mystservices/v2new/getSurvey.asp?InstanceID='+$('input#instanceID').val(),(data,status)=>{//获取所有扣分的题目
            if (status==='success'){
                $(data).find('nobr').each(function(){
                    let score=$(this).text();
                    if(score!=''&&score.indexOf('%')===-1){
                        let pts=score.split('/');
                        if(pts[0]<pts[1]){
                            let QidANS=$(this).parent().parent().parent().parent().parent('td.surveyquestioncell').prev().find('div').attr('id');
                            qidmark.push(QidANS);
                        }
                    }
                });
                for(let i in qidmark){//标红扣分项
                    $('div#'+qidmark[i]).css('color','red');
                }
            }
        });
    }
    /*单店报告界面将n/a题选项标橙,扣分题选项标红*/


})();