wsxy_autoExamineTest

网上学院函数库:自动答题

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/395966/773575/wsxy_autoExamineTest.js

  1. // ==UserScript==
  2. // @name wsxy_autoExamineTest
  3. // @namespace Vionlentmonkey
  4. // @version 0.8.1
  5. // @description 网上学院函数库:自动答题
  6. // ==/UserScript==
  7.  
  8. /**
  9. * 获取各题答案。一次性数据,无存储必要
  10. * @param {String | Number} subjectPk
  11. */
  12. const getSubjectData = async subjectPk => {
  13. const subjectURL = `${location.origin}/sfxzwsxy//jypxks/modules/train/course/subject_view.jsp?subjectPk=${subjectPk}`;
  14. const response = await fetch(subjectURL, {
  15. method: 'POST',
  16. body: 'blob'
  17. });
  18. const blob = await response.blob();
  19. const subjectHtml = await binary2Text(blob);
  20. const elements = htmlToElements(subjectHtml);
  21. // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map
  22. let subjectDataMap = new Map();
  23. // 题目类型:判断题/单选题/多选题
  24. const questionType = elements
  25. .querySelectorAll('table')[0]
  26. .querySelectorAll('tr')[0]
  27. .querySelectorAll('td')[1]
  28. .textContent.trim();
  29. subjectDataMap.set('questionType', questionType);
  30. // 题目内容:string
  31. const questionContent = elements
  32. .querySelectorAll('table')[0]
  33. .querySelectorAll('tr')[1]
  34. .querySelectorAll('td')[1]
  35. .textContent.trim();
  36. // 判断题答案,选择题此处为空值
  37. const judgementAnswer = elements
  38. .querySelectorAll('table')[0]
  39. .querySelectorAll('tr')[2]
  40. .querySelectorAll('td')[1]
  41. .textContent.trim();
  42. subjectDataMap.set('questionContent', questionContent);
  43.  
  44. if (questionType === '判断题') {
  45. subjectDataMap.set('judgementAnswer', judgementAnswer);
  46. } else {
  47. // 选择题答案表格第一行为标题:序号 选项内容 类型 是否为标准答案
  48. // 此表格中答案选项与试题选项顺序打乱,序号没有意义,类型已获取也没有意义
  49. const options = elements.querySelectorAll('table')[1].querySelectorAll('tr');
  50. for (const option of options) {
  51. const optionContent = option.querySelectorAll('td')[1].textContent.trim();
  52. const optionAnswer = option.querySelectorAll('td')[3].textContent.trim();
  53. if (optionContent === '选项内容' || optionAnswer === '是否为标准答案') continue;
  54. subjectDataMap.set(optionContent, optionAnswer);
  55. }
  56. }
  57. return subjectDataMap;
  58. };
  59.  
  60. /**
  61. * 打开考卷后自动答题交卷
  62. */
  63. const autoExamineTest = async () => {
  64. // 本考试所有试题
  65. const topics = document.getElementsByClassName('topic-tms');
  66. for await (const topic of topics) {
  67. // 题号
  68. const pkid = topic.querySelector('a[pkid]').getAttribute('pkid');
  69. // 本题答案
  70. const subjectDataMap = await getSubjectData(pkid);
  71. // 本题选项
  72. const options = topic.querySelectorAll('.tms-Right-wrong > p > a');
  73. for (const option of options) {
  74. const optionText = option.textContent.trim();
  75. if (subjectDataMap.get('questionType') === '判断题') {
  76. if (option.textContent.trim() !== subjectDataMap.get('judgementAnswer')) continue;
  77. option.click();
  78. } else {
  79. // 选择题选项内容带着序号与空格,如“A ”,故获取第三个字符开始的子串
  80. if (subjectDataMap.get(optionText.substring(2)) !== '是') continue;
  81. option.click();
  82. }
  83. }
  84. }
  85. // 交卷
  86. if (document.getElementsByClassName('subline _submit').length === 1) {
  87. document.getElementsByClassName('subline _submit')[0].click();
  88. }
  89. // 确认
  90. if (document.getElementsByClassName('layui-layer-btn0').length === 1) {
  91. document.getElementsByClassName('layui-layer-btn0')[0].click();
  92. }
  93. };

QingJ © 2025

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