GAOYI雨课堂网页版试卷试题导出到PDF

一款支持雨课堂网页版试卷导出成PDF的插件,简单易用。

  1. // ==UserScript==
  2. // @name GAOYI雨课堂网页版试卷试题导出到PDF
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.0
  5. // @description 一款支持雨课堂网页版试卷导出成PDF的插件,简单易用。
  6. // @author 羽肿
  7. // @match https://examination.xuetangx.com/*
  8.  
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // @license GPL
  12. // ==/UserScript==
  13.  
  14. function p(e){
  15. console.log(e)
  16. }
  17.  
  18. var pageContent
  19. function solve(){
  20. p("ok")
  21. pageContent = document.body.innerHTML;
  22. var dom=document.getElementsByClassName("subject-item")
  23. var problemDom=[];
  24. var list=["单选题","多选题","判断题"]
  25. for(var i=0;i<dom.length/2;i++)problemDom.push(dom[i+dom.length/2])
  26. p(problemDom)
  27. var str="";
  28. for(i=0;i<problemDom.length;i++){
  29. var more=1;
  30. var problemContent=problemDom[i].querySelectorAll(".clearfix p")[0]
  31. if(!problemContent){
  32. problemContent=problemDom[i].querySelectorAll(".clearfix")[0];
  33. more=2;
  34. }
  35. else{
  36. var idList=problemDom[i].querySelectorAll(".checkboxInput")
  37. var ansList=problemDom[i].querySelectorAll(".checkboxText")
  38. if(idList.length==0&&ansList.length==0){
  39. idList=problemDom[i].querySelectorAll(".radioInput")
  40. ansList=problemDom[i].querySelectorAll(".radioText")
  41. more=0;
  42. }
  43. }
  44. problemContent=problemContent.textContent.replace(/\n|\r/g, "")
  45.  
  46. str+=("第"+(i+1)+"题"+"("+list[more]+"):"+problemContent)+"<br>"
  47. if(more==2){
  48. continue;
  49. }
  50. p(idList)
  51. for(var j=0;j<idList.length;j++){
  52. var opt=idList[j].innerText.replace(/\n|\r/g, "")+":"+ansList[j].innerText.replace(/\n|\r/g, "")
  53. str+=opt+"<br>"
  54. }
  55. str+="<br>"
  56. }
  57. p(str)
  58. document.body.innerHTML=str;
  59. window.print()
  60. }
  61.  
  62.  
  63. class Question {
  64. constructor(Qtype, Qcontent, answerList, correctAnswer) {
  65. this.Qtype = Qtype;
  66. this.Qcontent = Qcontent;
  67. this.answerList = answerList;
  68. this.correctAnswer = correctAnswer;
  69. }
  70. }
  71.  
  72. function strReplace(str,key){
  73. if(str.includes(key)){
  74. return key;
  75. }
  76. return str;
  77. }
  78.  
  79. function test(){
  80. p("ok")
  81. pageContent = document.body.innerHTML;
  82. var pd=document.querySelector(".time")
  83. if(pd){
  84. alert("这张试卷还没有完成,完成后再进行导出")
  85. return
  86. }
  87. var elements = document.querySelectorAll('.result_item');//所有题目的集合
  88.  
  89. var QList=[]
  90. for(var i=0;i<elements.length;i++){
  91. var cur=elements[i]
  92. //=========
  93. var Qtype=cur.querySelector(".item-type").textContent;//获取类型
  94. Qtype=strReplace(Qtype,"单选题")
  95. Qtype=strReplace(Qtype,"多选题")
  96. Qtype=strReplace(Qtype,"判断题")
  97. //==========
  98. var Qcontent=cur.querySelector('.clearfix.exam-font p');//获取题目描述
  99. if(!Qcontent)Qcontent=cur.querySelector('.clearfix.exam-font')
  100. Qcontent=Qcontent.innerText
  101. //=========
  102. var answerList=[] //获取单个题目的答案集合
  103. if(Qtype=="判断题"){
  104. answerList=["对","错"]
  105. }else{
  106. var ansList=cur.querySelectorAll(".radioText p")
  107. for(var j=0;j<ansList.length;j++){
  108. var tmp=ansList[j].innerText;
  109. if(tmp&&tmp!="")answerList.push(tmp)
  110. }
  111. }
  112. p(answerList)
  113. //=========
  114. var correctAnswer;
  115. try{
  116. correctAnswer=cur.querySelector('.item-footer--header').innerText.match(/正确答案:\s*(\S+)/)[1]; //获取正确答案
  117. }catch(error){
  118. correctAnswer="主观题答案获取等待下次开发"
  119. }
  120. if(!correctAnswer)correctAnswer=""
  121. //========
  122. QList.push(new Question(Qtype,Qcontent,answerList,correctAnswer))
  123. }
  124. var str=""
  125. for(var k=0;k<QList.length;k++){
  126. var q=QList[k]
  127. str+="【"+q.Qtype+"】"
  128. str+=q.Qcontent
  129. str+="<strong>"+q.correctAnswer+"</strong>"
  130. str+="<br>"
  131. if(q.Qtype=="判断题")continue
  132. for(var x=0;x<q.answerList.length;x++){
  133. var id=String.fromCharCode(65 + x); //答案选项字母
  134. var choice=q.answerList[x]
  135. str+=id+"."+choice+"<br>"
  136. }
  137. }
  138. document.body.innerHTML=str
  139. window.print()
  140. }
  141.  
  142. (function() {
  143. window.onload = function() {
  144. setTimeout(function() {
  145. test()
  146. //document.body.innerHTML=pageContent
  147. }, 3000);
  148. };
  149.  
  150.  
  151. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址