// ==UserScript== // @name minerva-online assistant // @namespace https://space.bilibili.com/17846288 // @version 2.4.8 // @description 此脚本能更方便使用minerva-online平台,可在顶端菜单栏右下角的按钮处设置功能开关,并查看功能详情 // @author inoki // @match https://www.minerva-online.com/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @noframes // @downloadURL none // ==/UserScript== /*jshint esversion: 9*/ (()=>{ 'use strict'; const $=window.$; const SET=[ { 'id':0, 'name':'置顶置底', 'func':()=>{GOTOPBOTTOM();}, 'unfunc':()=>{unGOTOPBOTTOM();}, 'detail': `在平台域名所有可滚动页面生效,页面右下方添加置顶置底按钮
按钮会根据页面滚动方向自动切换置顶和置底,按钮样式可在代码中自定义中修改`, 'switch':1, }, { 'id':1, 'name':'菜单遮罩', 'func':()=>{COVERMENU();}, 'unfunc':()=>{unCOVERMENU();}, 'detail': `在有顶端菜单栏的页面生效
让菜单栏需要点击一次后才可展开,防止鼠标经过时误触 (默认关闭)`, 'switch':0, }, { 'id':2, 'name':'附件下载', 'func':()=>{DOWNLOADFILE();}, 'unfunc':()=>{unDOWNLOADFILE();}, 'detail': `在问卷管理页面生效,每份报告前添加↓按钮
点击↓加载附件列表,点击√下载全部附件,点击附件名下载单个附件,鼠标悬停可预览图片`, 'switch':1, }, { 'id':3, 'name':'扣分标记', 'func':()=>{MARKQUESTION();}, 'unfunc':()=>{unMARKQUESTION();}, 'detail': `在单店报告页面生效
将题目中勾选扣分和n/a项标色,选项更改后需保存报告才会刷新标记,方便快速检查相关题评论
可在简介上方设置扣分(默认为红)和N/A(默认为绿)的标记颜色,点击√保存更改,保存后关开此功能可在报告页面即时刷新颜色`, 'switch':1, }, { 'id':4, 'name':'评论编辑', 'func':()=>{COMMENTEDIT();}, 'unfunc':()=>{unCOMMENTEDIT();}, 'detail': `在单店报告页面生效,右下方按钮展开操作界面
使用前请注意阅读操作界面最上方的【点击获取提示】
输入匹配内容(支持正则)会即时显示匹配的评论框数量并标灰,点击一键替换可批量修改所有评论框内容
点击首字母大写可智能将所有句首字母变为大写,并标灰发生过修改的评论框,只对英文生效
点击评论翻译会调用百度翻译(由于需要跨域请求,弹出提示后选“总是允许”),在每个评论框下方输出目标语言翻译,点击↑可将下方内容添加至评论框`, 'switch':1, }, { 'id':5, 'name':'验证输出', 'func':()=>{VERIFYEXPORT();}, 'unfunc':()=>{unVERIFYEXPORT();}, 'detail': `在问卷管理页面生效,表头上方添加按钮
点击按钮弹出确认提示,确认后会验证输出当前页面勾选的所有报告,成功后会在每份报告下方小窗口显示绿色保存成功提示
(电脑配置较低时一次输出太多份可能导致页面卡死,请根据浏览器最多同时能开几个报告页面量力而行)`, 'switch':1, }, ]; /*在顶端菜单栏添加MOassist设置按钮*/ const menu=$('div#menu'); if(menu.length){ menu.find('ul.tools').append(`
  • `); menu.find('li.MOassist').on('click',function(){ MOListSwitch(this); }).find('ul#MOoption').on('click',e=>{ e.stopPropagation();//让之后添加的功能列表不继承click事件 }); //导入所有功能列表并显示开关状态 for(let i in SET){ menu.find('ul#MOoption').append(`
  • `); //运行开启状态的功能并打勾 if(GM_getValue(SET[i].name,SET[i].switch)){ SET[i].func(); menu.find('input#'+SET[i].id).attr('checked',true); } } //根据是否选中即时启用或卸载功能并记录开关状态 menu.find('li#MOoptions').on('click',function(){ const checkbox=$(this).find('input'); const id=$(checkbox).attr('id'); if($(checkbox).attr('checked')){ SET[id].unfunc(); $(checkbox).attr('checked',false); GM_setValue(SET[id].name,0); } else{ SET[id].func(); $(checkbox).attr("checked",true); GM_setValue(SET[id].name,1); } }).children('ul.textArea').on('click',e=>{ e.stopPropagation(); }); //鼠标聚焦时显示详情 【https://www.minerva-online.com/portal/menu/js/v2/menuRender.js?version=21-08 createToolOption : 】 menu.find('li.MOassist').hover(function(){ $(this).find('ul:first').stop().show(200); },function(){ $(this).find('ul:first').stop().hide(200); }); setMarkQuestionColor(menu); } else{ for(let i in SET) if(GM_getValue(SET[i].name,SET[i].switch)) SET[i].func();//没有menu也执行开启的功能 } //功能列表开关 function MOListSwitch(self){ const on=$(self).find('ul#MOoption').css('display'); if(on==='none'){ $(self).find('ul#MOoption').stop().slideDown(200); } else{ $(self).find('ul#MOoption').stop().slideUp(200); } } //添加扣分标记颜色设置界面 function setMarkQuestionColor(menu){ $(menu).find('input#3.menuIconSmall').next('ul').prepend(`
    扣分颜色:
    绿 自定义
    N/A颜色:
    绿 自定义
    `); //颜色选项初始化 $('form#de,form#na').each(function(){ const curColor= $(this).attr('id')==='de'? GM_getValue($(this).prev().text(),'red') : GM_getValue($(this).prev().text(),'green'); $(this).prev().css('color',curColor); $(this).children('.selectedColor').attr('id',curColor); if(curColor.indexOf('#')<0){ $(this).children('input[value='+curColor+']').attr('checked',true); $(this).children('.selectedColor').hide(); } else{ $(this).children('input[value=custom]').attr('checked',true); $(this).children('.selectedColor').val(curColor); } }); //点击选项颜色改变 $('form#de,form#na').children(':radio').on('click',function(){ if($(this).val()==='custom'){ $(this).next().show(); $(this).next().attr('id',$(this).next().val()); } else{ $(this).nextAll('.selectedColor').hide(); $(this).nextAll('.selectedColor').attr('id',$(this).val()); } $(this).parent().prev().css('color',$(this).nextAll('.selectedColor').attr('id')); }); //自定义颜色改变 $('form#de,form#na').children('.selectedColor').on('input',function(){ $(this).attr('id',$(this).val()); $(this).parent().prev().css('color',$(this).val()); }); //确认更改 $('form#de,form#na').children(':button').on('click',function(){ GM_setValue($(this).parent().prev().text(),$(this).prev().attr('id')); if(!$(this).next().is('b')){ $(this).after('保存成功'); setTimeout(()=>{ $(this).next().remove(); },3000); } }); } /*在顶端菜单栏添加MOassist设置按钮*/ /*置顶置底*/ function GOTOPBOTTOM(){ const scrollBar=$(document).height()>(window.innerHeight+1||document.documentElement.clientHeight);//如有滚动条 if(scrollBar&&document.location.href.indexOf('alias=knowledgebase')===-1){//knowledgebase页面自带置顶按钮,不启用 const goTopBottomButton=document.createElement('div'); const toggleButton=document.createElement('img'); $(toggleButton).appendTo(goTopBottomButton); $(goTopBottomButton).appendTo($('body')[0]); $(goTopBottomButton).css({'position':'fixed','zIndex':10000}).attr('id','goTopBottom'); $(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进制代码 const clickScrollTime=500;//点击按钮时,网页滚动到顶部或底部需要的时间,单位是毫秒 //点击按钮时网页滚动到顶部或底部 let scrollDirection='down'; toggleButton.addEventListener('click',()=>{ if(scrollDirection==='up'){ $('html,body').animate({scrollTop:'0px'},clickScrollTime); } else{ $('html,body').animate({scrollTop:$(document).height()},clickScrollTime); } }); //页面滚动监听 let scrollAction=window.pageYOffset; $(window).scroll(()=>{ const diffY=scrollAction-window.pageYOffset; scrollAction=window.pageYOffset; scrollDirection= diffY<0? 'down' : 'up'; toggleButton.style.transform= diffY<0? 'rotate(0deg)' : 'rotate(180deg)'; if(getScrollTop()===0){ scrollDirection='down'; toggleButton.style.transform='rotate(0deg)'; } if(getScrollTop()+window.innerHeight+20>=$(document).height()){ scrollDirection='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; } /*置顶置底*/ /*卸载置顶置底*/ function unGOTOPBOTTOM(){ if($('div#goTopBottom').length) $('div#goTopBottom').remove(); } /*卸载置顶置底*/ /*菜单遮罩*/ function COVERMENU(){ const menu=$('div#menu'); if(menu.length){ //若存在menu则添加cover层 const cover = document.createElement('div'); cover.className = 'layout'; cover.style = 'top:'+menu[0].style.top+';opacity:0.3;z-index:10000;right:10%'; $(cover).appendTo($('body')[0]).attr('id','cover'); //点击时将cover层下置 cover.addEventListener('click',()=>{ cover.style.zIndex = -1; }); //离开menu时cover层还原 menu[0].addEventListener('mouseleave',()=>{ cover.style.zIndex = 10000; }); //cover层位置跟随menu 【https://www.minerva-online.com/portal/menu/js/v2/menuRender.js?version=21-08 onScrollEventHandler : 】 $(window).scroll(()=>{ const SM=unsafeWindow.SM; const ind = SM.ui.headerHeight - SM.ui.getScrollTop(); cover.style.top= ind>0? ind+'px' : '0px'; }); } } /*菜单遮罩*/ /*卸载菜单遮罩*/ function unCOVERMENU(){ if($('div#cover').length) $('div#cover').remove(); } /*卸载菜单遮罩*/ /*附件下载*/ function DOWNLOADFILE(){ if (document.location.href.indexOf('alias=smngr.surveyexplorer')>=0&&$('tr.persist-header').length){ $('tr.persist-header').each(function(){ $(this).children().first().after($(this).children().first().clone(true)); }); $('div.sticky-wrap').find(':checkbox').each(function(){//checkbox后添加下载按钮 const surveyid=$(this).val(); $(this).parent().after('