Greasy Fork

Greasy Fork is available in English.

minerva-online assistant

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

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

// ==UserScript==
// @name         minerva-online assistant
// @namespace    https://space.bilibili.com/17846288
// @version      1.6
// @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 */

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

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

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

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


(function() {
    'use strict';

    var $ = $ || window.$;

    /*全局添加置顶置底功能*/
    if(置顶置底){//参考 http://greasyfork.icu/scripts/370556
        var clickScrollTime = 500; //点击按钮时,网页滚动到顶部或底部需要的时间,单位是毫秒,可修改
        var initialHeight = 0; //网页向底部滚动时,需要滚动的距离
        var scrollAction = 'undefined';
        var scrollDirection = 'down'; //网页滚动方向,down 为向下,up 为向上
        var goTopBottomButton = document.createElement('div');
        goTopBottomButton.className = 'goTopBottomButton';
        goTopBottomButton.innerHTML = "<img class='toggleButton' style='width:25px;height:25px;display:block;cursor:pointer;'></img>"; //图片宽高均为 25px,可修改
        goTopBottomButton.style.position = 'fixed';
        goTopBottomButton.style.zIndex = 10000;
        goTopBottomButton.style.bottom = '50px'; //距离网页底部 50px,可修改
        goTopBottomButton.style.right = '30px'; //距离网页右边 30px,可修改
        var toggleButton = goTopBottomButton.lastChild;
        toggleButton.style.opacity = 0.5; //按钮初始不透明度
        toggleButton.src = '/knowledgebase/images/arrow_back_to_top.svg'; //按钮初始显示向下的图片
        toggleButton.style.transform = 'rotate(0deg)';//按钮初始旋转角度向下
        toggleButton.style.backgroundColor = '#4C5157';//背景颜色
        document.getElementsByTagName('body')[0].appendChild(goTopBottomButton);
        $(goTopBottomButton).hide();//初始隐藏按钮

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

    //页面滚动监听
    document.onscroll = function() {
        $('div.goTopBottomButton').show();
        if (scrollAction == 'undefined') {
            scrollAction = window.pageYOffset;
        }
        var 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).height() + 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() {
        var 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后添加下载按钮
            var surveyid=$(this).val();
            $(this).parent().after('<td><button type=button id='+surveyid+' class=download><b>↓</td>');
            $('#'+surveyid+'.download').one('click',function(){
                download_button(surveyid);
            });
        });
    }

    //获取附件列表
    function download_button(surveyid){
        $('#'+surveyid+'.download').hide();
        $('#'+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').length;
                $('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]+'</a>').appendTo('ol#'+surveyid+'.filelist');
                        $('<iframe>').appendTo('ol#'+surveyid+'.filelist').hide();
                    });
                    $('ol#'+surveyid+'.filelist').prepend('<button type=button id='+surveyid+' class=yes><b>√');
                    $('button#'+surveyid+'.yes').on('click',function(){
                        download_yes(surveyid);
                    });
                    download_button0(surveyid);
                }
                else {
                    download_button0(surveyid);
                }
            }
            else {
                download_button0(surveyid);
            }
        });
    }

    //判断附件类型并获取名称和地址
    function file_attr(file){
        var filename,fileurl;
        if ($(file).children().first().is('img')){
            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');
        }
        filename=$(file).next().find('div.propValueContent.propValueFileName').text();
        if (fileurl.indexOf('getImage')>=0){
            fileurl=fileurl.replace('Image.asp?','Attachment.asp?Attachment').replace('&ImageType=modified','');
        }
        return [filename,fileurl];
    }

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

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

    //确认下载
    function download_yes(surveyid){
        $('a#'+surveyid+'.file').each(function(){
            $(this).parent().next().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');
                }
            }
        });

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


})();