minerva-online assistant

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

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

  1. // ==UserScript==
  2. // @name minerva-online assistant
  3. // @namespace https://space.bilibili.com/17846288
  4. // @version 1.8.1
  5. // @description 此脚本能更方便使用minerva-online平台,可在代码开头处手动设置功能开关,请仔细阅读后根据需要启用/关闭功能
  6. // @author inoki
  7. // @match https://www.minerva-online.com/*
  8. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js
  9. // @noframes
  10. // ==/UserScript==
  11.  
  12. /*jshint esversion: 6 */
  13.  
  14. /*功能开关:开启设为1;关闭设为0*/
  15. /*请根据需要手动修改开关值,保存(Ctrl+S)后生效*/
  16.  
  17. const 置顶置底=1;
  18. //置顶置底:在当前域名所有页面生效,右下角添加置顶置底按钮,滚动一次页面后显示,会根据页面滚动方向自动切换置顶和置底,按钮样式可修改
  19.  
  20. const 下载附件=1;
  21. //下载附件:在问卷管理页面生效,在每份报告前添加下载附件按钮,点↓加载附件列表,点√一键下载全部附件,点附件名下载单个附件,浏览器设置为无须确认直接下载效果更佳
  22.  
  23. const 扣分标记=1;
  24. //扣分标记:在单店报告页面生效,将题目选项中勾选n/a的标橙,扣分的标红,选项更改后需保存报告才会刷新标记项,方便快速检查扣分题评论
  25.  
  26.  
  27. (function() {
  28. 'use strict';
  29.  
  30. var $=$ || window.$;
  31.  
  32. /*全局添加置顶置底功能*/
  33. if(置顶置底&&document.location.href.indexOf('alias=knowledgebase')==-1){//knowledgebase页面自带置底按钮,不启用
  34. if($(document).height()<(window.innerHeight||document.documentElement.clientHeight)){//如有滚动条
  35. var goTopBottomButton=document.createElement('div');
  36. var toggleButton=document.createElement('img');
  37. $(toggleButton).appendTo(goTopBottomButton);
  38. $(goTopBottomButton).appendTo('body');
  39. $(goTopBottomButton).css({'position':'fixed','zIndex':10000});
  40. $(toggleButton).css({'display':'block','cursor':'pointer'}).attr('src','/knowledgebase/images/arrow_back_to_top.svg');//按钮显示图片(向下箭头)
  41.  
  42. //以下按钮参数可自定义修改
  43. goTopBottomButton.style.bottom='50px';//按钮距离网页底部50px
  44. goTopBottomButton.style.right='30px';//按钮距离网页右边30px
  45. toggleButton.style.width='25px';//按钮图片宽25px
  46. toggleButton.style.height='25px';//按钮图片高25px
  47. toggleButton.style.opacity=0.5;//按钮不透明度,0.0(完全透明)到1.0(完全不透明)
  48. toggleButton.style.backgroundColor='#808080';//按钮背景颜色,可在excel等软件的自定义颜色界面查看16进制代码
  49. var clickScrollTime=500;//点击按钮时,网页滚动到顶部或底部需要的时间,单位是毫秒
  50.  
  51. //按钮事件开始
  52. var scrollDirection='down';
  53. toggleButton.addEventListener('click',function(){//点击按钮时,网页滚动到顶部或底部
  54. if (scrollDirection=='up'){
  55. $('html,body').animate({scrollTop:'0px'},clickScrollTime);
  56. }
  57. else{
  58. var initialHeight=$(document).height();
  59. $('html,body').animate({scrollTop:initialHeight},clickScrollTime);
  60. }
  61. });
  62.  
  63.  
  64. //页面滚动监听
  65. var scrollAction=window.pageYOffset;
  66. document.onscroll=function(){
  67. var diffY=scrollAction-window.pageYOffset;
  68. scrollAction=window.pageYOffset;
  69. if(diffY<0){
  70. changeDirection('down');
  71. }
  72. else if(diffY>0){
  73. changeDirection('up');
  74. }
  75. if(getScrollTop()==0){
  76. changeDirection('down');
  77. }
  78. if(getScrollTop()+window.innerHeight+1>=$(document).height()){
  79. changeDirection('up');
  80. }
  81. };
  82. }
  83. }
  84.  
  85. //改变按钮方向
  86. function changeDirection(direction){
  87. scrollDirection=direction;
  88. if(direction=='down'){
  89. toggleButton.style.transform='rotate(0deg)';
  90. }
  91. if(direction=='up'){
  92. toggleButton.style.transform='rotate(180deg)';
  93. }
  94. }
  95.  
  96. //获取垂直方向滑动距离
  97. function getScrollTop(){
  98. var scrollTop=0;
  99. if(document.documentElement&&document.documentElement.scrollTop){
  100. scrollTop=document.documentElement.scrollTop;
  101. }
  102. else if(document.body){
  103. scrollTop=document.body.scrollTop;
  104. }
  105. return scrollTop;
  106. }
  107. /*全局添加置顶置底功能*/
  108.  
  109.  
  110. /*问卷管理界面添加附件下载功能*/
  111. if (下载附件&&document.location.href.indexOf('alias=smngr.surveyexplorer')>=0){
  112. $('tr.persist-header').each(function(){
  113. $(this).children().first().after( $(this).children().first().clone(true));
  114. });
  115. $('div.sticky-wrap').find(':checkbox').each(function(){//checkbox后添加下载按钮
  116. var surveyid=$(this).val();
  117. $(this).parent().after('<td><button type=button id='+surveyid+' class=download><b>↓</td>');
  118. $('#'+surveyid+'.download').one('click',function(){
  119. download_button(surveyid);
  120. });
  121. });
  122. }
  123.  
  124. //获取附件列表
  125. function download_button(surveyid){
  126. $('#'+surveyid+'.download').hide();
  127. $('#'+surveyid+'.download').after('<p id='+surveyid+' class=loading><b>......');
  128. $.get('/open/data.asp?post={"action":"exec","dataset":{"datasetname":"/Apps/SM/Survey/SurveyInstanceGetData"},"parameters":[{"name":"SurveyInstanceID","value":"'+surveyid+'"}]}',function(data,status){//调用API获取当前survey数据
  129. if (status=='success'){
  130. var attachmentdata=JSON.parse(data).dataset.data[3];
  131. var fileno=attachmentdata.length;
  132. $('p#'+surveyid+'.loading').after('<ol id='+surveyid+' class=filelist>\t#='+fileno+'');
  133. if (fileno>0){
  134. for(var i in attachmentdata){
  135. var filename=attachmentdata[i].FileName+'.'+attachmentdata[i].FileExtension;
  136. var fileurl='/mystservices/Attachments/getAttachment.asp?AttachmentID='+attachmentdata[i].AttachmentID+'&Password='+attachmentdata[i].Password+'';
  137. var filesize=Number(attachmentdata[i].FileSizeInBytes)/1024;
  138. filesize= (filesize>1024) ? (filesize/1024).toFixed(2)+'MB' : filesize.toFixed(2)+'KB';
  139. $('<li><a id='+surveyid+' class="file mailboxlink" href='+fileurl+'>'+filename+'</a>\t'+filesize+'</li>').appendTo('ol#'+surveyid+'.filelist');
  140. $('<iframe>').appendTo('ol#'+surveyid+'.filelist').hide();
  141. }
  142. $('ol#'+surveyid+'.filelist').prepend('<button type=button id='+surveyid+' class=yes><b>√');
  143. $('button#'+surveyid+'.yes').on('click',function(){
  144. download_yes(surveyid);
  145. });
  146. download_button0(surveyid);
  147. }
  148. else {
  149. download_button0(surveyid);
  150. }
  151. }
  152. else {
  153. download_button0(surveyid);
  154. }
  155. });
  156. }
  157.  
  158. //按钮变为关闭
  159. function download_button0(surveyid){
  160. $('p#'+surveyid+'.loading').remove();
  161. $('button#'+surveyid+'.download').one('click',function(){
  162. download_button1(surveyid);
  163. });
  164. $('button#'+surveyid+'.download').text('×');
  165. $('button#'+surveyid+'.download').show();
  166. }
  167.  
  168. //按钮重置为初始
  169. function download_button1(surveyid){
  170. $('ol').remove('#'+surveyid);
  171. $('button#'+surveyid+'.download').one('click',function(){
  172. download_button(surveyid);
  173. });
  174. $('button#'+surveyid+'.download').text('↓');
  175. }
  176.  
  177. //确认下载
  178. function download_yes(surveyid){
  179. $('button#'+surveyid+'.yes').hide();
  180. setTimeout(function(){
  181. $('button#'+surveyid+'.yes').show();
  182. },10000);
  183. $('a#'+surveyid+'.file').each(function(){
  184. $(this).parent().next().attr('src',$(this).attr('href'));
  185. });
  186. $('button#'+surveyid+'.yes').text('〇');
  187. }
  188. /*问卷管理界面添加附件下载功能*/
  189.  
  190.  
  191. /*单店报告界面将n/a题选项标橙,扣分题选项标红*/
  192. if(扣分标记&&document.location.href.indexOf('alias=survey.view')>=0){
  193. $('span.surveyansweroption').each(function(){//标橙n/a项
  194. if($(this).prev('input').is(':checked')){
  195. if($(this).prev('input').val()=='__na__'){
  196. $(this).css('color','orange');
  197. }
  198. }
  199. });
  200.  
  201. var qidmark=[];
  202. $.get('/mystservices/v2new/getSurvey.asp?InstanceID='+$('input#instanceID').val(),function(data,status){//获取所有扣分的题目
  203. if (status=='success'){
  204. $(data).find('nobr').each(function(){
  205. var score=$(this).text();
  206. if(score!=''&&score.indexOf('%')==-1){
  207. var pts=score.split('/');
  208. if(pts[0]<pts[1]){
  209. var QidANS=$(this).parent().parent().parent().parent().parent('td.surveyquestioncell').prev().find('div').attr('id');
  210. qidmark.push(QidANS);
  211. }
  212. }
  213. });
  214. for(var i=0;i<qidmark.length;i++){//标红扣分项
  215. $('div#'+qidmark[i]).css('color','red');
  216. }
  217. }
  218. });
  219. }
  220. /*单店报告界面将n/a题选项标橙,扣分题选项标红*/
  221.  
  222.  
  223. })();